DirectoryContents.st
author Claus Gittinger <cg@exept.de>
Sat, 02 May 2020 21:40:13 +0200
changeset 5476 7355a4b11cb6
parent 5471 0bee7a5e40e8
permissions -rw-r--r--
#FEATURE by cg class: Socket class added: #newTCPclientToHost:port:domain:domainOrder:withTimeout: changed: #newTCPclientToHost:port:domain:withTimeout:
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
     1
"
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
     2
 COPYRIGHT (c) 1997 by eXept Software AG
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
     3
              All Rights Reserved
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
     4
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
     5
 This software is furnished under a license and may be used
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
     6
 only in accordance with the terms of that license and with the
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
     7
 inclusion of the above copyright notice.   This software may not
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
     8
 be provided or otherwise made available to, or used by, any
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
     9
 other person.  No title to or ownership of the software is
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    10
 hereby transferred.
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    11
"
904
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 880
diff changeset
    12
"{ Package: 'stx:libbasic2' }"
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 880
diff changeset
    13
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
    14
"{ NameSpace: Smalltalk }"
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
    15
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    16
Object subclass:#DirectoryContents
2079
ca
parents: 2078
diff changeset
    17
	instanceVariableNames:'directory timeStamp contents isReadable isRootDirectory accessKey'
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
    18
	classVariableNames:'CachedDirectories LockSema ReadersList'
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    19
	poolDictionaries:''
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    20
	category:'System-Support'
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    21
!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    22
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
    23
Object subclass:#DirectoryContentsItem
1099
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
    24
	instanceVariableNames:'info fileName'
1431
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
    25
	classVariableNames:'CachedRemoteMountPoints CachedRemoteMountPointsTimeStamp'
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
    26
	poolDictionaries:''
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
    27
	privateIn:DirectoryContents
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
    28
!
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
    29
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    30
!DirectoryContents class methodsFor:'documentation'!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    31
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    32
copyright
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    33
"
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    34
 COPYRIGHT (c) 1997 by eXept Software AG
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    35
              All Rights Reserved
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    36
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    37
 This software is furnished under a license and may be used
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    38
 only in accordance with the terms of that license and with the
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    39
 inclusion of the above copyright notice.   This software may not
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    40
 be provided or otherwise made available to, or used by, any
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    41
 other person.  No title to or ownership of the software is
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    42
 hereby transferred.
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    43
"
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    44
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    45
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    46
!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    47
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    48
documentation
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    49
"
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    50
    DirectoryContents provides a cached view onto a fileDirectory.
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    51
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    52
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    53
    Notice:
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    54
        This class is not available in other ST-systems;
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    55
        Applications using it may not be portable.
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    56
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    57
    [author:]
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    58
        Claus Atzkern
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    59
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    60
    [see also:]
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    61
        Filename
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    62
        FileStream DirectoryStream OperatingSystem
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    63
"
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    64
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    65
! !
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    66
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
    67
!DirectoryContents class methodsFor:'initialization'!
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
    68
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
    69
initialize
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
    70
    LockSema    := RecursionLock new.
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
    71
    ReadersList := Dictionary new.
4306
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
    72
    CachedDirectories := OrderedCollection new.
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
    73
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
    74
    "Modified (comment): / 08-02-2017 / 15:47:06 / stefan"
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
    75
! !
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
    76
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
    77
!DirectoryContents class methodsFor:'instance creation'!
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
    78
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
    79
new
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
    80
    ^ self basicNew initialize
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
    81
! !
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
    82
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    83
!DirectoryContents class methodsFor:'accessing'!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    84
2080
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
    85
cachedDirectoryNamed:aFileOrString
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
    86
    "answer the valid cached directory or nil"
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
    87
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
    88
    ^ self directoryAt:aFileOrString
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
    89
!
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
    90
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
    91
directoryNamed:aDirectory
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    92
    "returns the DirectoryContents for a directory named 
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
    93
     aDirectoryName, aString, nil or Filename
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    94
    "
2081
746a24c36e8d *** empty log message ***
ca
parents: 2080
diff changeset
    95
    |directory contents lockRead pathName addToList|
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
    96
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
    97
    aDirectory isNil ifTrue:[^ nil].
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
    98
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
    99
    directory := aDirectory asFilename.
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   100
    directory exists ifFalse:[ ^ nil ].
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   101
1105
556e633a86c7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1102
diff changeset
   102
    directory := directory asAbsoluteFilename.
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   103
    contents := nil.
620
2a40beccf337 - useing Filename to read contents of a directory
ca
parents: 616
diff changeset
   104
4306
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   105
    LockSema critical:[        
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   106
        CachedDirectories notEmpty ifTrue:[
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   107
            "/ First: remove all obsolete directories - without doing a system call
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   108
            CachedDirectories := CachedDirectories select:[:aDir| aDir timeStamp notNil ].
2081
746a24c36e8d *** empty log message ***
ca
parents: 2080
diff changeset
   109
4306
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   110
            "take care, #directoryAt: modifies CacheDirectory!!"
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   111
            contents := self directoryAt:directory.
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   112
            contents isNil ifTrue:[
4306
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   113
                |numberOfCacheEntriesToRemove max|
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   114
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   115
                max := self maxCachedDirectories.
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   116
4306
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   117
                CachedDirectories size > max ifTrue:[
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   118
                    "/ make room for a new entry.
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   119
                    "/ Second: remove directories which contain less than 64 entries
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   120
                    "/ or are obsolete (outdated) (isObsolete makes a system call)
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   121
                    CachedDirectories := CachedDirectories
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   122
                        select:[:eachDir| eachDir size > 64 and:[eachDir isObsolete not]].
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   123
4306
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   124
                    numberOfCacheEntriesToRemove := CachedDirectories size + 2 - max.
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   125
                    numberOfCacheEntriesToRemove > 0 ifTrue:[
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   126
                        "/ remove oldest directories (they are at the end)
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   127
                        CachedDirectories removeLast:numberOfCacheEntriesToRemove.
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   128
                    ].
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   129
                ].
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   130
            ].
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   131
        ].
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   132
        contents isNil ifTrue:[
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   133
            pathName := directory pathName.
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   134
            lockRead := ReadersList at:pathName ifAbsentPut:[Semaphore forMutualExclusion].
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   135
        ]
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   136
    ].
4306
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   137
    contents notNil ifTrue:[
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   138
        ^ contents
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   139
    ].
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   140
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   141
    addToList := false.
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   142
    lockRead critical:[
1431
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   143
        [  "/ test whether another task got the semaphore and
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   144
           "/ has read the directory contents
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   145
           (contents := self directoryAt:directory) isNil ifTrue:[
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   146
                "/ read the directory contents
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   147
                contents  := self new directory:directory.
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   148
                "/ only cache if the mod'Time is valid.
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   149
                addToList := contents timeStamp notNil.
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   150
            ]
1022
6a288db5312a #valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents: 974
diff changeset
   151
        ] ensure:[
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   152
            LockSema critical:[
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   153
                addToList ifTrue:[
4306
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   154
                    CachedDirectories addFirst:contents
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   155
                ].
4306
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   156
                lockRead isEmpty ifTrue:[
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   157
                    ReadersList removeKey:pathName ifAbsent:nil
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   158
                ]
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   159
            ]
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   160
        ]
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   161
    ].    
620
2a40beccf337 - useing Filename to read contents of a directory
ca
parents: 616
diff changeset
   162
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   163
    ^ contents
4306
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   164
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   165
    "
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   166
        self directoryNamed:'/tmp'.
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   167
        self directoryNamed:'/home'.
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   168
        self directoryNamed:'/etc'.
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   169
    "
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   170
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   171
    "Modified (comment): / 08-02-2017 / 16:15:47 / stefan"
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   172
! !
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   173
616
cb0377b446bd flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   174
!DirectoryContents class methodsFor:'cache flushing'!
cb0377b446bd flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   175
880
8067101a5d8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 727
diff changeset
   176
flushCache
2421
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   177
    "flush list of remembered directory contents"
880
8067101a5d8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 727
diff changeset
   178
4306
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   179
    LockSema critical:[
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   180
        CachedDirectories removeAll.
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   181
    ].
880
8067101a5d8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 727
diff changeset
   182
8067101a5d8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 727
diff changeset
   183
    "
8067101a5d8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 727
diff changeset
   184
     self flushCache
8067101a5d8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 727
diff changeset
   185
    "
8067101a5d8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 727
diff changeset
   186
4306
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   187
    "Created: / 11-02-2000 / 00:13:59 / cg"
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   188
    "Modified: / 08-02-2017 / 15:57:13 / stefan"
880
8067101a5d8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 727
diff changeset
   189
!
8067101a5d8b *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 727
diff changeset
   190
1105
556e633a86c7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1102
diff changeset
   191
flushCachedDirectoryFor:aDirectoryOrString
958
989ff0f0d173 add new method: remove a specified directory from cash
ca
parents: 957
diff changeset
   192
    "remove directory from cache
989ff0f0d173 add new method: remove a specified directory from cash
ca
parents: 957
diff changeset
   193
    "
2130
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   194
    |directory|
958
989ff0f0d173 add new method: remove a specified directory from cash
ca
parents: 957
diff changeset
   195
2130
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   196
    aDirectoryOrString isNil ifTrue:[^ self ].                   
958
989ff0f0d173 add new method: remove a specified directory from cash
ca
parents: 957
diff changeset
   197
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   198
    directory := aDirectoryOrString asFilename.
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   199
    directory isSymbolicLink ifTrue:[^ self].
958
989ff0f0d173 add new method: remove a specified directory from cash
ca
parents: 957
diff changeset
   200
2130
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   201
    self
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   202
        directoryAt:directory
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   203
        checkForValidContentsDo:[:aDirectory| false ].  "/ should be removed from cache
4892
924087c8862b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4616
diff changeset
   204
! !
924087c8862b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4616
diff changeset
   205
924087c8862b #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 4616
diff changeset
   206
!DirectoryContents class methodsFor:'cleanup'!
958
989ff0f0d173 add new method: remove a specified directory from cash
ca
parents: 957
diff changeset
   207
695
368ddb719976 only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   208
lowSpaceCleanup
1575
Stefan Vogel <sv@exept.de>
parents: 1468
diff changeset
   209
    "flush list of remembered directory contents when low on memory"
695
368ddb719976 only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   210
1134
66f96c472a47 checkin from browser
Claus Gittinger <cg@exept.de>
parents: 1105
diff changeset
   211
    self flushCache
695
368ddb719976 only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   212
368ddb719976 only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   213
    "
368ddb719976 only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   214
     self lowSpaceCleanup
368ddb719976 only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   215
    "
368ddb719976 only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   216
368ddb719976 only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   217
    "Created: / 18.2.1998 / 18:17:05 / cg"
368ddb719976 only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents: 679
diff changeset
   218
    "Modified: / 24.9.1998 / 17:51:15 / cg"
616
cb0377b446bd flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   219
! !
cb0377b446bd flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   220
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   221
!DirectoryContents class methodsFor:'constants'!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   222
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   223
maxCachedDirectories
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   224
    "returns number of maximum cached directories
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   225
    "
616
cb0377b446bd flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   226
    ^ 20
cb0377b446bd flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   227
cb0377b446bd flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents: 583
diff changeset
   228
    "Modified: / 25.2.1998 / 19:56:24 / cg"
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   229
! !
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   230
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   231
!DirectoryContents class methodsFor:'private'!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   232
2079
ca
parents: 2078
diff changeset
   233
accessKeyForDirectory:aDirectoryOrString
ca
parents: 2078
diff changeset
   234
    "computes a fast access key to retrieve the directory in the cache
ca
parents: 2078
diff changeset
   235
    "
ca
parents: 2078
diff changeset
   236
    |key last|
ca
parents: 2078
diff changeset
   237
    
ca
parents: 2078
diff changeset
   238
    aDirectoryOrString isNil ifTrue:[^ nil ].
ca
parents: 2078
diff changeset
   239
ca
parents: 2078
diff changeset
   240
    aDirectoryOrString isFilename ifTrue:[ key := aDirectoryOrString nameString ]
ca
parents: 2078
diff changeset
   241
                                 ifFalse:[ key := aDirectoryOrString ].
ca
parents: 2078
diff changeset
   242
ca
parents: 2078
diff changeset
   243
    key size > 1 ifTrue:[
ca
parents: 2078
diff changeset
   244
        last := key last.
ca
parents: 2078
diff changeset
   245
        (last == $/ or:[last == $\]) ifTrue:[
2989
4b2ec07a1de6 Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 2749
diff changeset
   246
            ^ key copyButLast:1.
2079
ca
parents: 2078
diff changeset
   247
        ].
ca
parents: 2078
diff changeset
   248
    ].
ca
parents: 2078
diff changeset
   249
    ^ key
ca
parents: 2078
diff changeset
   250
!
ca
parents: 2078
diff changeset
   251
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   252
directoryAt:aFileOrString
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   253
    "checks whether directory already exists and is valid.
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   254
     If true the directory is returned otherwise nil
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   255
    "
2130
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   256
    ^ self
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   257
        directoryAt:aFileOrString
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   258
        checkForValidContentsDo:[:aContents| aContents isObsolete not ].
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   259
!
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   260
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   261
directoryAt:aFileOrString checkForValidContentsDo:checkIsValidBlock
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   262
    "answer the directoryContents stored under aFileOrString in the cache.
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   263
     If the evaluation of the checkIsValidBlock returns false, the contents
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   264
     will be removed from the cache and nil is returned."
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   265
2079
ca
parents: 2078
diff changeset
   266
    |index directory file fastKey|
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   267
2079
ca
parents: 2078
diff changeset
   268
    fastKey := self accessKeyForDirectory:aFileOrString.
ca
parents: 2078
diff changeset
   269
    fastKey isNil ifTrue:[^ nil ].  "/ the name is nil
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   270
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   271
    directory := nil.
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   272
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   273
    LockSema critical:[
4299
54a7d553b06e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4086
diff changeset
   274
        |cachedDirectories|
54a7d553b06e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4086
diff changeset
   275
4306
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   276
        (cachedDirectories := CachedDirectories) notEmpty ifTrue:[
4299
54a7d553b06e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4086
diff changeset
   277
            index := cachedDirectories findFirst:[:d| d accessKey = fastKey ].
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   278
            index == 0 ifTrue:[
2079
ca
parents: 2078
diff changeset
   279
                file  := aFileOrString asFilename asAbsoluteFilename.
4299
54a7d553b06e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4086
diff changeset
   280
                index := cachedDirectories findFirst:[:d| d directory = file ].
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   281
            ].
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   282
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   283
            index ~~ 0 ifTrue:[
4299
54a7d553b06e #REFACTORING by cg
Claus Gittinger <cg@exept.de>
parents: 4086
diff changeset
   284
                directory := cachedDirectories removeAtIndex:index.
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   285
2130
dcbfec8558f9 added: #directoryAt:checkForValidContentsDo:
fm
parents: 2083
diff changeset
   286
                (checkIsValidBlock value:directory) ifTrue:[
4306
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   287
                    "/ keep the last accessed directory at the front
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   288
                    cachedDirectories addFirst:directory.
2133
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   289
                ] ifFalse:[
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   290
                    "/ validation block answers false - return nil and removed from cache
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   291
                    directory := nil.
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   292
                ].
4306
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   293
                CachedDirectories := cachedDirectories.
2133
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   294
            ].
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   295
        ].
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   296
    ].
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   297
    ^ directory
4306
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   298
dabdce68fdd2 #BUGFIX by stefan
Stefan Vogel <sv@exept.de>
parents: 4299
diff changeset
   299
    "Modified (format): / 08-02-2017 / 15:59:59 / stefan"
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   300
! !
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   301
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   302
!DirectoryContents class methodsFor:'queries'!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   303
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   304
directoryNamed:aDirectoryName detect:aTwoArgBlock
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   305
    "evaluate the block, [:filename :isDirectory] on the directory
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   306
     contents of a directory named aDirectoryName, until the block
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   307
     returns true. If nothing detected false is returned
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   308
    "
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   309
    ^ self directoryNamed:aDirectoryName detect:aTwoArgBlock onOpenErrorDo:nil
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   310
!
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   311
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   312
directoryNamed:aDirectoryName detect:aTwoArgBlock onOpenErrorDo:exceptionBlock
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   313
    "evaluate the block, [:filename :isDirectory] on the directory
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   314
     contents of a directory named aDirectoryName, until the block
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   315
     returns true. If nothing detected false is returned.
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   316
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   317
     if the directory cannot be open, the exceptionBlock is processed
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   318
     with the filename.
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   319
    "
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   320
    |directory contents isReadable file|
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   321
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   322
    directory := aDirectoryName asFilename.
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   323
    contents  := self directoryAt:directory.
620
2a40beccf337 - useing Filename to read contents of a directory
ca
parents: 616
diff changeset
   324
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   325
    contents notNil ifTrue:[
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   326
        (isReadable := contents isReadable) ifTrue:[
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   327
            contents contentsDo:[:aFile :isDir|
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   328
                (aTwoArgBlock value:aFile value:isDir) ifTrue:[^ true]
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   329
            ].
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   330
            ^ false.
1155
edcf3cfe1e93 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 1147
diff changeset
   331
        ].
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   332
    ] ifFalse:[
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   333
        (isReadable := directory exists) ifTrue:[
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   334
            [
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   335
                directory directoryContentsDo:[:fn |
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   336
                    file := directory construct:fn.
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   337
                    (aTwoArgBlock value:file value:(file isDirectory)) ifTrue:[
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   338
                        ^ true
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   339
                    ]
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   340
                ].
5420
ed59dfaab1a8 #REFACTORING by exept
Claus Gittinger <cg@exept.de>
parents: 4892
diff changeset
   341
            ] on:(OpenError, StreamIOError) do:[:ex|
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   342
                isReadable := false.
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   343
            ].
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   344
        ].
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   345
    ].
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   346
    (isReadable not and:[exceptionBlock notNil]) ifTrue:[
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   347
        exceptionBlock value:directory.
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   348
    ].
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   349
    ^ false
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   350
! !
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   351
3831
8fc6245e8c39 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3465
diff changeset
   352
!DirectoryContents class methodsFor:'startup & release'!
8fc6245e8c39 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3465
diff changeset
   353
8fc6245e8c39 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3465
diff changeset
   354
preSnapshot
8fc6245e8c39 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3465
diff changeset
   355
    "flush list of cached directory contents before saving a snapshot
8fc6245e8c39 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3465
diff changeset
   356
     (do not save them in the image)"
8fc6245e8c39 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3465
diff changeset
   357
8fc6245e8c39 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3465
diff changeset
   358
    self flushCache.
8fc6245e8c39 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3465
diff changeset
   359
! !
8fc6245e8c39 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3465
diff changeset
   360
1102
2ec96742a420 utility to get an item
Claus Gittinger <cg@exept.de>
parents: 1101
diff changeset
   361
!DirectoryContents class methodsFor:'utilities'!
2ec96742a420 utility to get an item
Claus Gittinger <cg@exept.de>
parents: 1101
diff changeset
   362
2ec96742a420 utility to get an item
Claus Gittinger <cg@exept.de>
parents: 1101
diff changeset
   363
contentsItemForFileName:aFilenameOrString 
2ec96742a420 utility to get an item
Claus Gittinger <cg@exept.de>
parents: 1101
diff changeset
   364
    | aFilename directory directoryContents|
2ec96742a420 utility to get an item
Claus Gittinger <cg@exept.de>
parents: 1101
diff changeset
   365
2ec96742a420 utility to get an item
Claus Gittinger <cg@exept.de>
parents: 1101
diff changeset
   366
    aFilename := aFilenameOrString asFilename.
2ec96742a420 utility to get an item
Claus Gittinger <cg@exept.de>
parents: 1101
diff changeset
   367
    directory := aFilename directory.
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   368
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   369
    directoryContents := self directoryAt:directory.
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   370
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   371
    directoryContents notNil ifTrue:[
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   372
        directoryContents itemsDo:[:fileItemThere |
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   373
            fileItemThere fileName = aFilename ifTrue:[
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   374
                ^ fileItemThere.
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   375
            ].
1393
bb7048aaf86a care for directory without parent (network-dirs on WIN32)
Claus Gittinger <cg@exept.de>
parents: 1352
diff changeset
   376
        ].
bb7048aaf86a care for directory without parent (network-dirs on WIN32)
Claus Gittinger <cg@exept.de>
parents: 1352
diff changeset
   377
    ].
1252
933afe6d5bd6 care for directory being removed
Claus Gittinger <cg@exept.de>
parents: 1198
diff changeset
   378
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   379
    aFilename exists ifFalse:[
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   380
        directoryContents notNil ifTrue:[ directoryContents beObsolete ].
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   381
        ^ nil
1102
2ec96742a420 utility to get an item
Claus Gittinger <cg@exept.de>
parents: 1101
diff changeset
   382
    ].
1105
556e633a86c7 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1102
diff changeset
   383
    ^ (DirectoryContentsItem new fileName:aFilename) info:aFilename info.
1102
2ec96742a420 utility to get an item
Claus Gittinger <cg@exept.de>
parents: 1101
diff changeset
   384
! !
2ec96742a420 utility to get an item
Claus Gittinger <cg@exept.de>
parents: 1101
diff changeset
   385
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   386
!DirectoryContents methodsFor:'accessing'!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   387
2079
ca
parents: 2078
diff changeset
   388
accessKey
ca
parents: 2078
diff changeset
   389
    ^ accessKey
ca
parents: 2078
diff changeset
   390
!
ca
parents: 2078
diff changeset
   391
2421
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   392
beObsolete
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   393
    "mark self as obsolete
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   394
     clear contents and reset time"
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   395
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   396
    |saveCont|
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   397
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   398
    timeStamp := nil.
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   399
    saveCont  := contents.
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   400
    contents  := #().
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   401
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   402
    saveCont notEmptyOrNil ifTrue:[
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   403
        "/ clear the info - if someone has a reference to the item
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   404
        saveCont do:[:eachItem | eachItem resetInfo ].
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   405
    ].
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   406
!
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   407
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   408
directory
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   409
    "returns the directoy name as Filename
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   410
    "
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   411
    ^ directory
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   412
!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   413
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   414
modificationTime
2499
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   415
    "get the last modification time of the directory.
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   416
     Note that sometimes a root directory does not return
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   417
     a valid modification time - so do not cache it."
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   418
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   419
    |modifyTime|
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   420
2499
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   421
    timeStamp isNil ifTrue:[^ nil].
2071
f58e3dcf48b0 handling isRootDirectory & modificationTime
ca
parents: 2047
diff changeset
   422
2499
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   423
    modifyTime := directory modificationTime.
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   424
    modifyTime notNil ifTrue:[
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   425
        ^ modifyTime 
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   426
   ].
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   427
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   428
    isRootDirectory ifFalse:[
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   429
        "if it is not a root directory, assume that we have no access"
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   430
        isReadable := false.
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   431
        self beObsolete.
2071
f58e3dcf48b0 handling isRootDirectory & modificationTime
ca
parents: 2047
diff changeset
   432
    ].
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   433
    ^ nil
951
37870a37b930 consider contents as obsolete, if modification
martin
parents: 906
diff changeset
   434
!
37870a37b930 consider contents as obsolete, if modification
martin
parents: 906
diff changeset
   435
37870a37b930 consider contents as obsolete, if modification
martin
parents: 906
diff changeset
   436
timeStamp
37870a37b930 consider contents as obsolete, if modification
martin
parents: 906
diff changeset
   437
    "get the last timeStamp (when the directory info was read) of the directory
37870a37b930 consider contents as obsolete, if modification
martin
parents: 906
diff changeset
   438
    "
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   439
    ^ timeStamp
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   440
! !
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   441
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   442
!DirectoryContents methodsFor:'enumerating'!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   443
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   444
contentsAndBaseNamesDo:aThreeArgBlock
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   445
    "evaluate the block on each file; the argument to the block is the
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   446
     filename, the baseName and true in case of a directory
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   447
     block arguments: [:fileName :aBaseName :isDirectory|
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   448
    "
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   449
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   450
    self itemsDo:[:eachItem |
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   451
        aThreeArgBlock 
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   452
            value:(eachItem fileName) 
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   453
            value:(eachItem baseName ) 
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   454
            value:(eachItem isDirectory)
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   455
    ].
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   456
!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   457
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   458
contentsDo:aTwoArgBlock
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   459
    "evaluate the block on each file; the argument to the block is the
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   460
     filename and true in case of a directory
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   461
     block arguments: [:fileName :isDirectory|
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   462
    "
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   463
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   464
    self itemsDo:[:eachItem |
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   465
        aTwoArgBlock
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   466
            value:(eachItem fileName) 
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   467
            value:(eachItem isDirectory)
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   468
    ].
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   469
!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   470
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   471
directoriesAndBasenamesDo:aTwoArgBlock
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   472
    "evaluate block on each directory; a Filename and Basename.
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   473
     The directories are sorted
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   474
    "
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   475
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   476
    self itemsDo:[:eachItem |
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   477
        eachItem isDirectory ifTrue:[
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   478
            aTwoArgBlock value:(eachItem fileName) value:(eachItem baseName)
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   479
        ]
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   480
    ]
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   481
!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   482
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   483
directoriesDo:aOneArgBlock
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   484
    "evaluate block on each directory; a Filename. The directories are sorted
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   485
    "
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   486
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   487
    self itemsDo:[:eachItem |
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   488
        eachItem isDirectory ifTrue:[
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   489
            aOneArgBlock value:(eachItem fileName) 
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   490
        ]
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   491
    ].
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   492
!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   493
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   494
filesAndBasenamesDo:aTwoArgBlock
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   495
    "evaluate block on each file; a Filename and a Basename.
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   496
     The files are sorted.
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   497
    "
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   498
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   499
    self itemsDo:[:eachItem |
1324
e51285e95b3f not ifTrue -> ifFalse
Claus Gittinger <cg@exept.de>
parents: 1296
diff changeset
   500
        eachItem isDirectory ifFalse:[
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   501
            aTwoArgBlock value:(eachItem fileName) value:(eachItem baseName)
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   502
        ]
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   503
    ]
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   504
!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   505
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   506
filesDo:aOneArgBlock
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   507
    "evaluate block on each file; a Filename. The files are sorted.
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   508
    "
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   509
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   510
    self itemsDo:[:eachItem |
1324
e51285e95b3f not ifTrue -> ifFalse
Claus Gittinger <cg@exept.de>
parents: 1296
diff changeset
   511
        eachItem isDirectory ifFalse:[
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   512
            aOneArgBlock value:(eachItem fileName)
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   513
        ]
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   514
    ]
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   515
!
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   516
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   517
itemsDo:aBlock
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   518
    "evaluate the block on each contentsItem, which contains the fileName and type info"
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   519
2421
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   520
    contents do:aBlock.
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   521
! !
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   522
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   523
!DirectoryContents methodsFor:'instance creation'!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   524
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   525
directory:aFilename 
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   526
    |time stream linkInfo sourcePath|
1155
edcf3cfe1e93 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 1147
diff changeset
   527
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   528
    directory := aFilename asFilename.
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   529
    isRootDirectory := directory isRootDirectory.
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   530
    accessKey := self class accessKeyForDirectory:directory.
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   531
    contents := OrderedCollection new.
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   532
    isReadable := false.
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   533
    time := Timestamp now.
1155
edcf3cfe1e93 Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents: 1147
diff changeset
   534
    [
2082
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   535
        [
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   536
            stream := DirectoryStream 
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   537
                    directoryNamed:(directory osNameForDirectoryContents).
2082
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   538
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   539
            stream notNil ifTrue:[
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   540
                [
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   541
                    (stream atEnd or:[ (linkInfo := stream nextLinkInfo) isNil ])
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   542
                ] whileFalse:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   543
                    sourcePath := linkInfo sourcePath.
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   544
                    (sourcePath = '.' or:[ sourcePath = '..' ]) ifFalse:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   545
                        |fitem|
1431
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   546
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   547
                        fitem := DirectoryContentsItem new 
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   548
                                fileName:(directory construct:sourcePath)
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   549
                                linkInfo:linkInfo.
2082
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   550
                        contents add:fitem.
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   551
                    ].
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   552
                ].
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   553
                isReadable := true.
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   554
            ].
5471
0bee7a5e40e8 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5420
diff changeset
   555
        ] on:StreamError do:[:ex | isReadable := false. ].
2082
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   556
    ] ensure:[
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   557
        stream notNil ifTrue:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   558
            stream close
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   559
        ].
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   560
        isReadable ifFalse:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   561
            contents := #()
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   562
        ].
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   563
    ].
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   564
    contents sort:[:a :b | a nameString < b nameString ].
2421
7d70e8269bec comment/format in: #isObsolete
Claus Gittinger <cg@exept.de>
parents: 2412
diff changeset
   565
    contents := contents asArray.
2082
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   566
    timeStamp := time.
5471
0bee7a5e40e8 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5420
diff changeset
   567
0bee7a5e40e8 #TUNING by stefan
Stefan Vogel <sv@exept.de>
parents: 5420
diff changeset
   568
    "Modified: / 03-04-2020 / 18:50:11 / Stefan Vogel"
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   569
! !
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   570
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   571
!DirectoryContents methodsFor:'obsolete'!
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   572
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   573
updateContents
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   574
    <resource:#obsolete>
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   575
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   576
    "ensure that the file-info os present for every item
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   577
     ** obsolete - access info if required"
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   578
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   579
    "/    contents do:[:eachItem | eachItem updateInfo ].
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   580
! !
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   581
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   582
!DirectoryContents methodsFor:'printing'!
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   583
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   584
printOn:aStream
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   585
    aStream nextPutAll:'DirectoryContents of: '.
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   586
    aStream nextPutAll:(directory pathName).
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   587
! !
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   588
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   589
!DirectoryContents methodsFor:'queries'!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   590
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   591
isObsolete
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   592
    "returns true if the directory contents represented by the receiver is obsolete
3303
b7f33985ea38 class: DirectoryContents
Claus Gittinger <cg@exept.de>
parents: 3229
diff changeset
   593
     (i.e. if the fileSystem's directory has been changed in the meanwhile)
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   594
    "
974
c4be514ddd96 fix for windows bug (directory has no modification time)
Claus Gittinger <cg@exept.de>
parents: 958
diff changeset
   595
    |mt|
679
ce7aed726aff checkin from browser
Claus Gittinger <cg@exept.de>
parents: 620
diff changeset
   596
974
c4be514ddd96 fix for windows bug (directory has no modification time)
Claus Gittinger <cg@exept.de>
parents: 958
diff changeset
   597
    timeStamp isNil ifTrue:[^ true].
2071
f58e3dcf48b0 handling isRootDirectory & modificationTime
ca
parents: 2047
diff changeset
   598
f58e3dcf48b0 handling isRootDirectory & modificationTime
ca
parents: 2047
diff changeset
   599
    mt := self modificationTime.
f58e3dcf48b0 handling isRootDirectory & modificationTime
ca
parents: 2047
diff changeset
   600
    mt isNil ifTrue:[^ true ].
f58e3dcf48b0 handling isRootDirectory & modificationTime
ca
parents: 2047
diff changeset
   601
2499
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   602
    "we compare only seconds, since the modification time is not as (millisecond) accurate as the timestamp"
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   603
    timeStamp getSeconds < mt getSeconds ifTrue:[
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   604
        self beObsolete.
9a5dcca2130a changed:
Stefan Vogel <sv@exept.de>
parents: 2421
diff changeset
   605
        ^ true.
2071
f58e3dcf48b0 handling isRootDirectory & modificationTime
ca
parents: 2047
diff changeset
   606
    ].
974
c4be514ddd96 fix for windows bug (directory has no modification time)
Claus Gittinger <cg@exept.de>
parents: 958
diff changeset
   607
    ^ false
2071
f58e3dcf48b0 handling isRootDirectory & modificationTime
ca
parents: 2047
diff changeset
   608
!
974
c4be514ddd96 fix for windows bug (directory has no modification time)
Claus Gittinger <cg@exept.de>
parents: 958
diff changeset
   609
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   610
isReadable
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   611
    "answer true if the directory is readable
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   612
     no open error raised during reading the directory"
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   613
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   614
    ^ isReadable
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   615
!
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   616
2071
f58e3dcf48b0 handling isRootDirectory & modificationTime
ca
parents: 2047
diff changeset
   617
isRootDirectory
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   618
    ^ isRootDirectory
906
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
   619
!
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
   620
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
   621
size
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
   622
    "get number of files including directories in the directory
30c1ab2aee8d category change
Claus Gittinger <cg@exept.de>
parents: 904
diff changeset
   623
    "
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   624
    ^ contents size
904
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 880
diff changeset
   625
! !
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 880
diff changeset
   626
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 880
diff changeset
   627
!DirectoryContents methodsFor:'testing'!
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 880
diff changeset
   628
2080
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
   629
includesIdentical:anItem
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
   630
    ^ contents includesIdentical:anItem
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
   631
!
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
   632
904
f4791de2295b category change
Claus Gittinger <cg@exept.de>
parents: 880
diff changeset
   633
isEmpty
4616
22f8c0303a8b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4306
diff changeset
   634
    "returns true if directory is empty"
22f8c0303a8b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4306
diff changeset
   635
22f8c0303a8b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4306
diff changeset
   636
    ^ contents isEmpty
22f8c0303a8b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4306
diff changeset
   637
22f8c0303a8b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4306
diff changeset
   638
    "Modified: / 08-03-2018 / 13:42:51 / stefan"
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   639
!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   640
2133
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   641
isEmptyOrNil
2627
6d4adf17cfd6 comment
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   642
    "return true if I am nil or an empty collection" 
6d4adf17cfd6 comment
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   643
4616
22f8c0303a8b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4306
diff changeset
   644
    ^ contents isEmptyOrNil
2627
6d4adf17cfd6 comment
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   645
6d4adf17cfd6 comment
Claus Gittinger <cg@exept.de>
parents: 2499
diff changeset
   646
    "Modified (comment): / 17-08-2011 / 09:30:15 / cg"
4616
22f8c0303a8b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4306
diff changeset
   647
    "Modified: / 06-03-2018 / 21:27:12 / stefan"
2133
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   648
!
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   649
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   650
notEmpty
4616
22f8c0303a8b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4306
diff changeset
   651
    "returns true if directory is not empty"
22f8c0303a8b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4306
diff changeset
   652
22f8c0303a8b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4306
diff changeset
   653
    ^ contents notEmpty
22f8c0303a8b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4306
diff changeset
   654
22f8c0303a8b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4306
diff changeset
   655
    "Modified: / 08-03-2018 / 13:42:18 / stefan"
2133
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   656
!
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   657
a739d816088e bugfix and queries
ca
parents: 2130
diff changeset
   658
notEmptyOrNil
4616
22f8c0303a8b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4306
diff changeset
   659
    "returns true if directory is not empty"
22f8c0303a8b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4306
diff changeset
   660
22f8c0303a8b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4306
diff changeset
   661
    ^ contents notEmptyOrNil
22f8c0303a8b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4306
diff changeset
   662
22f8c0303a8b #REFACTORING by stefan
Stefan Vogel <sv@exept.de>
parents: 4306
diff changeset
   663
    "Modified: / 08-03-2018 / 13:42:32 / stefan"
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   664
! !
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   665
2082
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   666
!DirectoryContents::DirectoryContentsItem class methodsFor:'instance creation'!
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   667
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   668
fileName:aFilename
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   669
    ^ self new fileName:aFilename.
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   670
! !
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   671
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   672
!DirectoryContents::DirectoryContentsItem methodsFor:'accessing'!
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   673
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   674
baseName
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   675
    ^ fileName baseName
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   676
!
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   677
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   678
fileName
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   679
    ^ fileName
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   680
!
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   681
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   682
fileName:something
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   683
    "set the value of the instance variable 'fileName' (automatically generated)"
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   684
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   685
    fileName := something.
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   686
!
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   687
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   688
fileName:aFilename linkInfo:aLinkInfo
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   689
    fileName := aFilename.
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   690
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   691
    (aLinkInfo notNil and:[aLinkInfo isValid])
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   692
        ifTrue:[self updateInfoFrom:aLinkInfo].
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   693
!
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   694
1100
a8c44ef83781 checkin from browser
ca
parents: 1099
diff changeset
   695
info
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   696
    info isNil ifTrue:[
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   697
        self updateInfo.
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   698
    ].
1100
a8c44ef83781 checkin from browser
ca
parents: 1099
diff changeset
   699
    info isSymbol ifTrue:[^ nil]. "/ a remote directory
a8c44ef83781 checkin from browser
ca
parents: 1099
diff changeset
   700
    ^ info
a8c44ef83781 checkin from browser
ca
parents: 1099
diff changeset
   701
!
a8c44ef83781 checkin from browser
ca
parents: 1099
diff changeset
   702
1099
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   703
info:something
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   704
    "set the value of the instance variable 'type' (automatically generated)"
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   705
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   706
    info := something.
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   707
!
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   708
2082
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   709
nameString
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   710
    "raw access to nameString"
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   711
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   712
    ^ fileName nameString
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   713
!
396cb3c74f93 instance creation - read directory contents
ca
parents: 2081
diff changeset
   714
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   715
type
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   716
    info isNil ifTrue:[
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   717
        self updateInfo.
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   718
    ].
1099
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   719
    info isSymbol ifTrue:[^ info].
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   720
    ^ info type
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   721
! !
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   722
2745
7fb1a2c5483d Added #asFilename
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2627
diff changeset
   723
!DirectoryContents::DirectoryContentsItem methodsFor:'converting'!
7fb1a2c5483d Added #asFilename
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2627
diff changeset
   724
7fb1a2c5483d Added #asFilename
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2627
diff changeset
   725
asFilename
7fb1a2c5483d Added #asFilename
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2627
diff changeset
   726
7fb1a2c5483d Added #asFilename
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2627
diff changeset
   727
    ^fileName
7fb1a2c5483d Added #asFilename
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2627
diff changeset
   728
7fb1a2c5483d Added #asFilename
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2627
diff changeset
   729
    "Created: / 08-05-2012 / 15:15:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
7fb1a2c5483d Added #asFilename
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2627
diff changeset
   730
! !
7fb1a2c5483d Added #asFilename
Jan Vrany <jan.vrany@fit.cvut.cz>
parents: 2627
diff changeset
   731
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   732
!DirectoryContents::DirectoryContentsItem methodsFor:'misc'!
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   733
1431
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   734
cachedRemoteMountPoints
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   735
    |mountPoints now|
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   736
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   737
    mountPoints := CachedRemoteMountPoints.
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   738
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   739
    (mountPoints isNil
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   740
    or:[ CachedRemoteMountPointsTimeStamp isNil
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   741
    or:[ now := Timestamp now.
3229
c858bc4167dd class: DirectoryContents
Claus Gittinger <cg@exept.de>
parents: 2989
diff changeset
   742
         (now secondDeltaFrom: CachedRemoteMountPointsTimeStamp) > 30 
1431
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   743
    ]]) ifTrue:[
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   744
        CachedRemoteMountPointsTimeStamp := now.
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   745
        mountPoints := OperatingSystem mountPoints.
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   746
        mountPoints := mountPoints select:[:mp | mp isRemote].
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   747
        CachedRemoteMountPoints := mountPoints.
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   748
    ].
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   749
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   750
    ^ mountPoints.
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   751
!
049b89c5bf60 cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents: 1393
diff changeset
   752
2078
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   753
resetAttributes
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   754
    "reset the attributes... done if I'am a normal file"
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   755
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   756
    (info isNil or:[info isSymbol]) ifTrue:[^ self ].
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   757
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   758
    self isDirectory ifFalse:[
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   759
        info := nil.
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   760
    ].
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   761
!
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   762
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   763
resetInfo
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   764
    info := nil.
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   765
!
a196d0ebe6fc rework - optimization and bugfixes concerning cache
ca
parents: 2074
diff changeset
   766
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   767
updateInfo
2047
16c159894d3f *** empty log message ***
ca
parents: 2046
diff changeset
   768
    "ensure that the file-info is present
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   769
        DirectoryContents flushCache
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   770
    "
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   771
    info isNil ifTrue:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   772
        self updateInfoFrom:(fileName linkInfo).
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   773
    ].
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   774
!
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   775
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   776
updateInfoFrom:aLinkInfo
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   777
    "might be reused by updateLinkInfo"
2083
fb059bbd81e6 *** empty log message ***
ca
parents: 2082
diff changeset
   778
    |mountPoint nameString linkName|
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   779
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   780
    info := aLinkInfo.
2047
16c159894d3f *** empty log message ***
ca
parents: 2046
diff changeset
   781
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   782
    (info notNil and:[info isSymbolicLink]) ifTrue:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   783
        OperatingSystem isMSWINDOWSlike ifFalse:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   784
            linkName := info path.
2046
0ca98ed5fb80 handling of symbolic links
ca
parents: 1919
diff changeset
   785
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   786
            linkName notNil ifTrue:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   787
                "have to check for both link and link target"
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   788
                mountPoint := self cachedRemoteMountPoints 
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   789
                            detect:[:mInfo | |p|
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   790
                                p := mInfo mountPointPath.
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   791
                                ((linkName startsWith:p) and:[ linkName startsWith:(p , '/') ])
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   792
                            ]
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   793
                            ifNone:nil.
2047
16c159894d3f *** empty log message ***
ca
parents: 2046
diff changeset
   794
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   795
                info := fileName info.  "get the info of the link target"   
2047
16c159894d3f *** empty log message ***
ca
parents: 2046
diff changeset
   796
            ].
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   797
        ].
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   798
    ] ifFalse:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   799
        "have to check for mountPoint only"
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   800
        nameString := fileName name.
2083
fb059bbd81e6 *** empty log message ***
ca
parents: 2082
diff changeset
   801
3465
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   802
        mountPoint := self cachedRemoteMountPoints 
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   803
                    detect:[:mInfo | mInfo mountPointPath = nameString ]
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   804
                    ifNone:nil.
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   805
    ].
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   806
    mountPoint notNil ifTrue:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   807
        info := #remoteDirectory.
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   808
    ] ifFalse:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   809
        info isNil ifTrue:[
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   810
            "/ broken symbolic link
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   811
            info := #symbolicLink.
c15c6d70877f class: DirectoryContents
ca
parents: 3303
diff changeset
   812
        ]
1350
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   813
    ].
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   814
! !
61e51decadea lazy generation of info
Claus Gittinger <cg@exept.de>
parents: 1349
diff changeset
   815
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   816
!DirectoryContents::DirectoryContentsItem methodsFor:'printing'!
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   817
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   818
printOn:aStream
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   819
    aStream nextPutAll:'DirectoryContentsItem for: '.
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   820
    fileName printOn:aStream.
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   821
! !
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   822
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   823
!DirectoryContents::DirectoryContentsItem methodsFor:'queries'!
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   824
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   825
isDirectory
1099
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   826
    |t|
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   827
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   828
    t := self type.
81e2d4217524 keep info instead of type alone
ca
parents: 1097
diff changeset
   829
    ^ (t == #directory or:[t == #remoteDirectory])
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   830
!
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   831
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   832
isRemoteDirectory
2074
8a4ffdd9fddc isSymbolicLink
ca
parents: 2071
diff changeset
   833
    ^ self type == #remoteDirectory
8a4ffdd9fddc isSymbolicLink
ca
parents: 2071
diff changeset
   834
!
8a4ffdd9fddc isSymbolicLink
ca
parents: 2071
diff changeset
   835
2080
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
   836
isSpecialFile
2412
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   837
    |type|
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   838
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   839
    type := self type.
2080
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
   840
2412
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   841
    ^ (type ~~ #directory
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   842
        and:[type ~~ #remoteDirectory
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   843
        and:[type ~~ #regular
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   844
        and:[type ~~ #symbolicLink
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   845
    ]]])
2080
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
   846
!
20651a2e1c4f flushCachedDirectoryFor: force flush of directory
ca
parents: 2079
diff changeset
   847
2074
8a4ffdd9fddc isSymbolicLink
ca
parents: 2071
diff changeset
   848
isSymbolicLink
2412
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   849
    ^ self type == #symbolicLink
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   850
! !
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   851
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   852
!DirectoryContents class methodsFor:'documentation'!
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   853
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   854
version
3831
8fc6245e8c39 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3465
diff changeset
   855
    ^ '$Header$'
2412
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   856
!
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   857
6814ebed2138 bugfix: isSymbolicLink
ca
parents: 2133
diff changeset
   858
version_CVS
3831
8fc6245e8c39 #DOCUMENTATION by cg
Claus Gittinger <cg@exept.de>
parents: 3465
diff changeset
   859
    ^ '$Header$'
583
3298b0ca7927 intitial checkin
ca
parents:
diff changeset
   860
! !
1093
052299fc7594 mark remoteDirectories specially
penk
parents: 1022
diff changeset
   861
2989
4b2ec07a1de6 Changed usage of deprecated #copyWithoutLast: to #copyButLast:
Stefan Vogel <sv@exept.de>
parents: 2749
diff changeset
   862
957
88d941cdbe8f suspend processes reading same directory
ca
parents: 951
diff changeset
   863
DirectoryContents initialize!