author | ca |
Wed, 17 Dec 2008 13:45:08 +0100 | |
changeset 2074 | 8a4ffdd9fddc |
parent 2071 | f58e3dcf48b0 |
child 2078 | a196d0ebe6fc |
permissions | -rw-r--r-- |
583 | 1 |
" |
2 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
3 |
All Rights Reserved |
|
4 |
||
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
904 | 12 |
"{ Package: 'stx:libbasic2' }" |
13 |
||
583 | 14 |
Object subclass:#DirectoryContents |
1105 | 15 |
instanceVariableNames:'directory timeStamp contents' |
957 | 16 |
classVariableNames:'CachedDirectories LockSema ReadersList' |
583 | 17 |
poolDictionaries:'' |
18 |
category:'System-Support' |
|
19 |
! |
|
20 |
||
1093 | 21 |
Object subclass:#DirectoryContentsItem |
1099 | 22 |
instanceVariableNames:'info fileName' |
1431
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
23 |
classVariableNames:'CachedRemoteMountPoints CachedRemoteMountPointsTimeStamp' |
1093 | 24 |
poolDictionaries:'' |
25 |
privateIn:DirectoryContents |
|
26 |
! |
|
27 |
||
583 | 28 |
!DirectoryContents class methodsFor:'documentation'! |
29 |
||
30 |
copyright |
|
31 |
" |
|
32 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
33 |
All Rights Reserved |
|
34 |
||
35 |
This software is furnished under a license and may be used |
|
36 |
only in accordance with the terms of that license and with the |
|
37 |
inclusion of the above copyright notice. This software may not |
|
38 |
be provided or otherwise made available to, or used by, any |
|
39 |
other person. No title to or ownership of the software is |
|
40 |
hereby transferred. |
|
41 |
" |
|
42 |
||
43 |
||
44 |
! |
|
45 |
||
46 |
documentation |
|
47 |
" |
|
48 |
DirectoryContents provides a cached view onto a fileDirectory. |
|
49 |
||
50 |
||
51 |
Notice: |
|
52 |
This class is not available in other ST-systems; |
|
53 |
Applications using it may not be portable. |
|
54 |
||
55 |
[author:] |
|
56 |
Claus Atzkern |
|
57 |
||
58 |
[see also:] |
|
59 |
Filename |
|
60 |
FileStream DirectoryStream OperatingSystem |
|
61 |
" |
|
62 |
||
63 |
! ! |
|
64 |
||
957 | 65 |
!DirectoryContents class methodsFor:'initialization'! |
66 |
||
67 |
initialize |
|
68 |
"setup lock-mechanism |
|
69 |
" |
|
70 |
LockSema := RecursionLock new. |
|
71 |
ReadersList := Dictionary new. |
|
72 |
! ! |
|
73 |
||
1093 | 74 |
!DirectoryContents class methodsFor:'instance creation'! |
75 |
||
76 |
new |
|
77 |
^ self basicNew initialize |
|
78 |
! ! |
|
79 |
||
583 | 80 |
!DirectoryContents class methodsFor:'accessing'! |
81 |
||
957 | 82 |
directoryNamed:aDirectory |
583 | 83 |
"returns the DirectoryContents for a directory named |
957 | 84 |
aDirectoryName, aString, nil or Filename |
583 | 85 |
" |
957 | 86 |
|directory contents max lockRead pathName addToList| |
583 | 87 |
|
957 | 88 |
(aDirectory notNil and:[(directory := aDirectory asFilename) exists]) ifFalse:[ |
620 | 89 |
^ nil |
90 |
]. |
|
1105 | 91 |
directory := directory asAbsoluteFilename. |
957 | 92 |
contents := nil. |
620 | 93 |
|
957 | 94 |
LockSema critical:[ |
95 |
CachedDirectories notNil ifTrue:[ |
|
96 |
contents := self directoryAt:directory. |
|
97 |
||
98 |
contents isNil ifTrue:[ |
|
99 |
max := self maxCachedDirectories. |
|
583 | 100 |
|
957 | 101 |
CachedDirectories size > max ifTrue:[ |
102 |
CachedDirectories := CachedDirectories select:[:aDir| |
|
103 |
(aDir size > 32 and:[aDir isObsolete not]) |
|
104 |
] |
|
105 |
]. |
|
106 |
||
107 |
CachedDirectories size > max ifTrue:[ |
|
108 |
CachedDirectories removeFirst |
|
109 |
] |
|
110 |
]. |
|
583 | 111 |
]. |
957 | 112 |
contents isNil ifTrue:[ |
113 |
ReadersList isNil ifTrue:[ReadersList := Dictionary new]. |
|
114 |
pathName := directory pathName. |
|
115 |
lockRead := ReadersList at:pathName ifAbsentPut:[Semaphore forMutualExclusion]. |
|
116 |
] |
|
117 |
]. |
|
118 |
contents notNil ifTrue:[^ contents]. |
|
119 |
addToList := false. |
|
583 | 120 |
|
957 | 121 |
lockRead critical:[ |
1431
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
122 |
[ "/ test whether another task got the semaphore and |
957 | 123 |
"/ has read the directory contents |
124 |
(contents := self directoryAt:directory) isNil ifTrue:[ |
|
125 |
"/ read the directory contents |
|
126 |
contents := self new directory:directory. |
|
127 |
"/ only cache if the mod'Time is valid. |
|
128 |
addToList := contents timeStamp notNil. |
|
129 |
] |
|
1022
6a288db5312a
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
974
diff
changeset
|
130 |
] ensure:[ |
957 | 131 |
LockSema critical:[ |
132 |
addToList ifTrue:[ |
|
133 |
CachedDirectories isNil ifTrue:[ |
|
134 |
CachedDirectories := OrderedCollection new |
|
135 |
]. |
|
136 |
CachedDirectories add:contents |
|
137 |
]. |
|
138 |
(lockRead isEmpty and:[ReadersList notNil]) ifTrue:[ |
|
139 |
ReadersList removeKey:pathName ifAbsent:nil |
|
140 |
] |
|
583 | 141 |
] |
142 |
] |
|
957 | 143 |
]. |
620 | 144 |
|
957 | 145 |
^ contents |
583 | 146 |
! ! |
147 |
||
616
cb0377b446bd
flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
148 |
!DirectoryContents class methodsFor:'cache flushing'! |
cb0377b446bd
flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
149 |
|
880 | 150 |
flushCache |
151 |
"flush list of rememebred directory contents" |
|
152 |
||
957 | 153 |
LockSema critical:[ CachedDirectories := nil ]. |
880 | 154 |
|
155 |
" |
|
156 |
self flushCache |
|
157 |
" |
|
158 |
||
159 |
"Created: / 11.2.2000 / 00:13:59 / cg" |
|
160 |
! |
|
161 |
||
1105 | 162 |
flushCachedDirectoryFor:aDirectoryOrString |
958 | 163 |
"remove directory from cache |
164 |
" |
|
1105 | 165 |
|index directory| |
958 | 166 |
|
1105 | 167 |
(CachedDirectories notNil and:[aDirectoryOrString notNil]) ifTrue:[ |
168 |
directory := aDirectoryOrString asFilename. |
|
958 | 169 |
|
1352 | 170 |
(directory isSymbolicLink not |
171 |
and:[ directory isDirectory]) ifTrue:[ |
|
958 | 172 |
LockSema critical:[ |
173 |
CachedDirectories notNil ifTrue:[ |
|
1105 | 174 |
directory := directory asAbsoluteFilename. |
1349 | 175 |
index := CachedDirectories findFirst:[:d | d directory = directory ]. |
958 | 176 |
|
177 |
index ~~ 0 ifTrue:[ |
|
178 |
CachedDirectories removeAtIndex:index. |
|
179 |
] |
|
180 |
] |
|
181 |
] |
|
182 |
] |
|
183 |
]. |
|
184 |
! |
|
185 |
||
695
368ddb719976
only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents:
679
diff
changeset
|
186 |
lowSpaceCleanup |
1575 | 187 |
"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
|
188 |
|
1134 | 189 |
self flushCache |
695
368ddb719976
only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents:
679
diff
changeset
|
190 |
|
368ddb719976
only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents:
679
diff
changeset
|
191 |
" |
368ddb719976
only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents:
679
diff
changeset
|
192 |
self lowSpaceCleanup |
368ddb719976
only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents:
679
diff
changeset
|
193 |
" |
368ddb719976
only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents:
679
diff
changeset
|
194 |
|
368ddb719976
only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents:
679
diff
changeset
|
195 |
"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
|
196 |
"Modified: / 24.9.1998 / 17:51:15 / cg" |
368ddb719976
only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents:
679
diff
changeset
|
197 |
! |
368ddb719976
only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents:
679
diff
changeset
|
198 |
|
616
cb0377b446bd
flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
199 |
preSnapshot |
1919 | 200 |
"flush list of cached directory contents before saving a snapshot" |
616
cb0377b446bd
flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
201 |
|
1349 | 202 |
self flushCache. |
616
cb0377b446bd
flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
203 |
! ! |
cb0377b446bd
flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
204 |
|
583 | 205 |
!DirectoryContents class methodsFor:'constants'! |
206 |
||
207 |
maxCachedDirectories |
|
208 |
"returns number of maximum cached directories |
|
209 |
" |
|
616
cb0377b446bd
flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
210 |
^ 20 |
cb0377b446bd
flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
211 |
|
cb0377b446bd
flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
212 |
"Modified: / 25.2.1998 / 19:56:24 / cg" |
583 | 213 |
! ! |
214 |
||
215 |
!DirectoryContents class methodsFor:'private'! |
|
216 |
||
217 |
directoryAt:aFilename |
|
218 |
"checks whether directory already exists and is valid. |
|
219 |
If true the directory is returned otherwise nil |
|
220 |
" |
|
1105 | 221 |
|index directory absoluteFilename| |
583 | 222 |
|
957 | 223 |
directory := nil. |
224 |
||
225 |
LockSema critical:[ |
|
226 |
CachedDirectories notNil ifTrue:[ |
|
1105 | 227 |
absoluteFilename := aFilename asFilename asAbsoluteFilename. |
228 |
index := CachedDirectories findFirst:[:d| d directory = absoluteFilename ]. |
|
583 | 229 |
|
957 | 230 |
index ~~ 0 ifTrue:[ |
231 |
directory := CachedDirectories at:index. |
|
583 | 232 |
|
957 | 233 |
directory isObsolete ifTrue:[ |
234 |
CachedDirectories removeAtIndex:index. |
|
235 |
directory := nil. |
|
236 |
] |
|
237 |
] |
|
583 | 238 |
] |
239 |
]. |
|
957 | 240 |
^ directory |
583 | 241 |
! ! |
242 |
||
243 |
!DirectoryContents class methodsFor:'queries'! |
|
244 |
||
245 |
directoryNamed:aDirectoryName detect:aTwoArgBlock |
|
246 |
"evaluate the block, [:filename :isDirectory] on the directory |
|
247 |
contents of a directory named aDirectoryName, until the block |
|
248 |
returns true. If nothing detected false is returned |
|
249 |
" |
|
1155
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
250 |
|directory dir| |
583 | 251 |
|
252 |
directory := aDirectoryName asFilename. |
|
253 |
||
620 | 254 |
directory exists ifFalse:[ |
255 |
^ false |
|
256 |
]. |
|
257 |
||
583 | 258 |
(dir := self directoryAt:directory) notNil ifTrue:[ |
259 |
dir contentsDo:[:aFile :isDir| |
|
260 |
(aTwoArgBlock value:aFile value:isDir) ifTrue:[^ true] |
|
261 |
]. |
|
262 |
^ false |
|
1155
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
263 |
]. |
583 | 264 |
|
1155
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
265 |
[ |
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
266 |
directory directoryContentsDo:[:fn | |
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
267 |
|file| |
583 | 268 |
|
1155
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
269 |
file := directory construct:fn. |
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
270 |
(aTwoArgBlock value:file value:(file isDirectory)) ifTrue:[ |
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
271 |
^ true |
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
272 |
] |
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
273 |
]. |
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
274 |
] on:FileStream openErrorSignal do:[:ex| |
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
275 |
"cannot open directory" |
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
276 |
^ false |
583 | 277 |
]. |
696
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
278 |
|
1155
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
279 |
|
696
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
280 |
"/ dir := DirectoryStream directoryNamed:(directory pathName). |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
281 |
"/ |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
282 |
"/ dir isNil ifFalse:[ |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
283 |
"/ [ |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
284 |
"/ [dir atEnd] whileFalse:[ |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
285 |
"/ (name := dir nextLine) notNil ifTrue:[ |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
286 |
"/ name := directory construct:name. |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
287 |
"/ |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
288 |
"/ (aTwoArgBlock value:name value:(name isDirectory)) ifTrue:[ |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
289 |
"/ ^ true |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
290 |
"/ ] |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
291 |
"/ ] |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
292 |
"/ ]. |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
293 |
"/ ] valueNowOrOnUnwindDo:[ |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
294 |
"/ dir close. |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
295 |
"/ ] |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
296 |
"/ ]. |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
297 |
|
583 | 298 |
^ false |
696
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
299 |
|
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
300 |
"Modified: / 24.9.1998 / 21:14:58 / cg" |
583 | 301 |
! ! |
302 |
||
1102 | 303 |
!DirectoryContents class methodsFor:'utilities'! |
304 |
||
305 |
contentsItemForFileName:aFilenameOrString |
|
306 |
| aFilename directory directoryContents| |
|
307 |
||
308 |
aFilename := aFilenameOrString asFilename. |
|
309 |
directory := aFilename directory. |
|
310 |
directoryContents := self directoryNamed:directory. |
|
1393
bb7048aaf86a
care for directory without parent (network-dirs on WIN32)
Claus Gittinger <cg@exept.de>
parents:
1352
diff
changeset
|
311 |
directoryContents isNil ifTrue:[ |
bb7048aaf86a
care for directory without parent (network-dirs on WIN32)
Claus Gittinger <cg@exept.de>
parents:
1352
diff
changeset
|
312 |
aFilename exists ifTrue:[ |
bb7048aaf86a
care for directory without parent (network-dirs on WIN32)
Claus Gittinger <cg@exept.de>
parents:
1352
diff
changeset
|
313 |
^ (DirectoryContentsItem new fileName:aFilename) info:aFilename info. |
bb7048aaf86a
care for directory without parent (network-dirs on WIN32)
Claus Gittinger <cg@exept.de>
parents:
1352
diff
changeset
|
314 |
]. |
bb7048aaf86a
care for directory without parent (network-dirs on WIN32)
Claus Gittinger <cg@exept.de>
parents:
1352
diff
changeset
|
315 |
^ nil |
bb7048aaf86a
care for directory without parent (network-dirs on WIN32)
Claus Gittinger <cg@exept.de>
parents:
1352
diff
changeset
|
316 |
]. |
1252
933afe6d5bd6
care for directory being removed
Claus Gittinger <cg@exept.de>
parents:
1198
diff
changeset
|
317 |
|
1253 | 318 |
directoryContents itemsDo:[:fileItemThere | |
1102 | 319 |
fileItemThere fileName = aFilename ifTrue:[ |
1350 | 320 |
fileItemThere updateInfo. |
1102 | 321 |
^ fileItemThere. |
322 |
] |
|
323 |
]. |
|
1105 | 324 |
^ (DirectoryContentsItem new fileName:aFilename) info:aFilename info. |
1102 | 325 |
|
326 |
" |
|
327 |
DirectoryContents contentsItemForFileName:'/etc/passwd' |
|
1105 | 328 |
DirectoryContents contentsItemForFileName:'/' |
1102 | 329 |
" |
330 |
! ! |
|
331 |
||
583 | 332 |
!DirectoryContents methodsFor:'accessing'! |
333 |
||
334 |
directory |
|
335 |
"returns the directoy name as Filename |
|
336 |
" |
|
337 |
^ directory |
|
338 |
! |
|
339 |
||
340 |
modificationTime |
|
341 |
"get the last modification time of the directory |
|
342 |
" |
|
2071 | 343 |
timeStamp isNil ifTrue:[^ nil ]. |
344 |
||
345 |
self isRootDirectory ifTrue:[ |
|
346 |
directory exists ifFalse:[ |
|
347 |
"/ set to obsolete |
|
348 |
timeStamp := nil. |
|
349 |
]. |
|
350 |
^ timeStamp |
|
351 |
]. |
|
951 | 352 |
^ directory modificationTime |
353 |
! |
|
354 |
||
355 |
timeStamp |
|
356 |
"get the last timeStamp (when the directory info was read) of the directory |
|
357 |
" |
|
583 | 358 |
^ timeStamp |
359 |
! ! |
|
360 |
||
361 |
!DirectoryContents methodsFor:'enumerating'! |
|
362 |
||
363 |
contentsAndBaseNamesDo:aThreeArgBlock |
|
364 |
"evaluate the block on each file; the argument to the block is the |
|
365 |
filename, the baseName and true in case of a directory |
|
366 |
block arguments: [:fileName :aBaseName :isDirectory| |
|
367 |
" |
|
1350 | 368 |
|
1093 | 369 |
self itemsDo:[:eachItem | |
370 |
aThreeArgBlock |
|
371 |
value:(eachItem fileName) |
|
372 |
value:(eachItem baseName ) |
|
373 |
value:(eachItem isDirectory) |
|
583 | 374 |
]. |
375 |
! |
|
376 |
||
377 |
contentsDo:aTwoArgBlock |
|
378 |
"evaluate the block on each file; the argument to the block is the |
|
379 |
filename and true in case of a directory |
|
380 |
block arguments: [:fileName :isDirectory| |
|
381 |
" |
|
1350 | 382 |
|
1093 | 383 |
self itemsDo:[:eachItem | |
384 |
aTwoArgBlock |
|
385 |
value:(eachItem fileName) |
|
386 |
value:(eachItem isDirectory) |
|
583 | 387 |
]. |
388 |
! |
|
389 |
||
390 |
directoriesAndBasenamesDo:aTwoArgBlock |
|
391 |
"evaluate block on each directory; a Filename and Basename. |
|
392 |
The directories are sorted |
|
393 |
" |
|
1350 | 394 |
|
1093 | 395 |
self itemsDo:[:eachItem | |
396 |
eachItem isDirectory ifTrue:[ |
|
397 |
aTwoArgBlock value:(eachItem fileName) value:(eachItem baseName) |
|
583 | 398 |
] |
399 |
] |
|
400 |
! |
|
401 |
||
402 |
directoriesDo:aOneArgBlock |
|
403 |
"evaluate block on each directory; a Filename. The directories are sorted |
|
404 |
" |
|
1350 | 405 |
|
1093 | 406 |
self itemsDo:[:eachItem | |
407 |
eachItem isDirectory ifTrue:[ |
|
1350 | 408 |
aOneArgBlock value:(eachItem fileName) |
583 | 409 |
] |
1093 | 410 |
]. |
583 | 411 |
! |
412 |
||
413 |
filesAndBasenamesDo:aTwoArgBlock |
|
414 |
"evaluate block on each file; a Filename and a Basename. |
|
415 |
The files are sorted. |
|
416 |
" |
|
1350 | 417 |
|
1093 | 418 |
self itemsDo:[:eachItem | |
1324 | 419 |
eachItem isDirectory ifFalse:[ |
1093 | 420 |
aTwoArgBlock value:(eachItem fileName) value:(eachItem baseName) |
583 | 421 |
] |
422 |
] |
|
423 |
! |
|
424 |
||
425 |
filesDo:aOneArgBlock |
|
426 |
"evaluate block on each file; a Filename. The files are sorted. |
|
427 |
" |
|
1350 | 428 |
|
1093 | 429 |
self itemsDo:[:eachItem | |
1324 | 430 |
eachItem isDirectory ifFalse:[ |
1093 | 431 |
aOneArgBlock value:(eachItem fileName) |
583 | 432 |
] |
433 |
] |
|
1093 | 434 |
! |
435 |
||
436 |
itemsDo:aBlock |
|
437 |
"evaluate the block on each contentsItem, which contains the fileName and type info" |
|
438 |
||
1350 | 439 |
contents do:[:eachItem | |
440 |
aBlock value:eachItem. |
|
441 |
]. |
|
583 | 442 |
! ! |
443 |
||
444 |
!DirectoryContents methodsFor:'instance creation'! |
|
445 |
||
446 |
directory:aFilename |
|
1155
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
447 |
"instance creation; setup attributes" |
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
448 |
|
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
449 |
|t dircontents| |
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
450 |
|
583 | 451 |
directory := aFilename asFilename. |
1435
5895158e7491
Use Timestamp/#asTimestamp instead of AbsoluteTime/#asAbsoluteTime
Stefan Vogel <sv@exept.de>
parents:
1431
diff
changeset
|
452 |
t := Timestamp now. "/ directory modificationTime. |
1155
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
453 |
[ |
1431
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
454 |
dircontents := directory directoryContents. |
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
455 |
dircontents sort. |
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
456 |
contents := dircontents collect:[:eachBasename | DirectoryContentsItem new fileName:(directory construct:eachBasename)]. |
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
457 |
|
2071 | 458 |
|
459 |
||
1431
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
460 |
"/ dircontents := directory directoryContentsAsFilenames. |
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
461 |
"/ dircontents sort:[:a :b | a baseName < b baseName]. |
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
462 |
"/ contents := dircontents |
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
463 |
"/ collect:[:eachFilename | DirectoryContentsItem new fileName:eachFilename]. |
1155
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
464 |
] on:FileStream openErrorSignal do:[:ex| |
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
465 |
contents := #(). |
1093 | 466 |
]. |
1101 | 467 |
timeStamp := t. |
1093 | 468 |
! ! |
469 |
||
470 |
!DirectoryContents methodsFor:'printing'! |
|
471 |
||
472 |
printOn:aStream |
|
473 |
aStream nextPutAll:'DirectoryContents of: '. |
|
474 |
directory printOn:aStream. |
|
583 | 475 |
! ! |
476 |
||
477 |
!DirectoryContents methodsFor:'private'! |
|
478 |
||
1093 | 479 |
updateContents |
1350 | 480 |
"ensure that the file-info os present for every item" |
1093 | 481 |
|
482 |
contents do:[:eachItem | |
|
1350 | 483 |
eachItem updateInfo. |
583 | 484 |
]. |
485 |
! ! |
|
486 |
||
487 |
!DirectoryContents methodsFor:'queries'! |
|
488 |
||
489 |
isObsolete |
|
1350 | 490 |
"returns true if the directory contents represented by the receiver is obsolete |
491 |
(i.e. if the fileSystems directory has been changed in the meanwhile) |
|
583 | 492 |
" |
974
c4be514ddd96
fix for windows bug (directory has no modification time)
Claus Gittinger <cg@exept.de>
parents:
958
diff
changeset
|
493 |
|mt| |
679 | 494 |
|
974
c4be514ddd96
fix for windows bug (directory has no modification time)
Claus Gittinger <cg@exept.de>
parents:
958
diff
changeset
|
495 |
timeStamp isNil ifTrue:[^ true]. |
2071 | 496 |
|
497 |
mt := self modificationTime. |
|
498 |
mt isNil ifTrue:[^ true ]. |
|
499 |
||
500 |
timeStamp < mt ifTrue:[ |
|
501 |
timeStamp getSeconds < mt getSeconds ifTrue:[ |
|
502 |
timeStamp := nil. "/ mark as obsolete |
|
503 |
^ true. |
|
504 |
]. |
|
505 |
]. |
|
974
c4be514ddd96
fix for windows bug (directory has no modification time)
Claus Gittinger <cg@exept.de>
parents:
958
diff
changeset
|
506 |
^ false |
2071 | 507 |
! |
974
c4be514ddd96
fix for windows bug (directory has no modification time)
Claus Gittinger <cg@exept.de>
parents:
958
diff
changeset
|
508 |
|
2071 | 509 |
isRootDirectory |
510 |
^ directory isRootDirectory |
|
906 | 511 |
! |
512 |
||
513 |
size |
|
514 |
"get number of files including directories in the directory |
|
515 |
" |
|
1093 | 516 |
^ contents size |
904 | 517 |
! ! |
518 |
||
519 |
!DirectoryContents methodsFor:'testing'! |
|
520 |
||
521 |
isEmpty |
|
522 |
"retuirns true if directory is empty |
|
523 |
" |
|
1093 | 524 |
^ contents size == 0 |
583 | 525 |
! |
526 |
||
527 |
notEmpty |
|
528 |
"returns true if directory is not empty |
|
529 |
" |
|
1093 | 530 |
^ contents size ~~ 0 |
531 |
! ! |
|
532 |
||
533 |
!DirectoryContents::DirectoryContentsItem methodsFor:'accessing'! |
|
534 |
||
535 |
baseName |
|
536 |
^ fileName baseName |
|
537 |
! |
|
538 |
||
539 |
fileName |
|
540 |
^ fileName |
|
541 |
! |
|
542 |
||
543 |
fileName:something |
|
544 |
"set the value of the instance variable 'fileName' (automatically generated)" |
|
545 |
||
546 |
fileName := something. |
|
547 |
! |
|
548 |
||
1100 | 549 |
info |
1350 | 550 |
info isNil ifTrue:[ |
551 |
self updateInfo. |
|
552 |
]. |
|
1100 | 553 |
info isSymbol ifTrue:[^ nil]. "/ a remote directory |
554 |
^ info |
|
555 |
! |
|
556 |
||
1099 | 557 |
info:something |
558 |
"set the value of the instance variable 'type' (automatically generated)" |
|
559 |
||
560 |
info := something. |
|
561 |
! |
|
562 |
||
1093 | 563 |
type |
1350 | 564 |
info isNil ifTrue:[ |
565 |
self updateInfo. |
|
566 |
]. |
|
1099 | 567 |
info isSymbol ifTrue:[^ info]. |
568 |
^ info type |
|
1093 | 569 |
! ! |
570 |
||
1350 | 571 |
!DirectoryContents::DirectoryContentsItem methodsFor:'misc'! |
572 |
||
1431
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
573 |
cachedRemoteMountPoints |
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
574 |
|mountPoints now| |
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
575 |
|
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
576 |
mountPoints := CachedRemoteMountPoints. |
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
577 |
|
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
578 |
(mountPoints isNil |
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
579 |
or:[ CachedRemoteMountPointsTimeStamp isNil |
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
580 |
or:[ now := Timestamp now. |
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
581 |
(now - CachedRemoteMountPointsTimeStamp) > 30 |
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
582 |
]]) ifTrue:[ |
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
583 |
CachedRemoteMountPointsTimeStamp := now. |
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
584 |
mountPoints := OperatingSystem mountPoints. |
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
585 |
mountPoints := mountPoints select:[:mp | mp isRemote]. |
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
586 |
CachedRemoteMountPoints := mountPoints. |
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
587 |
]. |
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
588 |
|
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
589 |
^ mountPoints. |
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
590 |
! |
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
591 |
|
1350 | 592 |
updateInfo |
2047 | 593 |
"ensure that the file-info is present |
594 |
DirectoryContents flushCache |
|
595 |
" |
|
1468
476e360d4aeb
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
1435
diff
changeset
|
596 |
|
2047 | 597 |
|mountPoints mountPoint nameString linkName| |
1350 | 598 |
|
599 |
info isNil ifTrue:[ |
|
600 |
nameString := fileName name. |
|
1468
476e360d4aeb
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
1435
diff
changeset
|
601 |
self assert:[fileName isAbsolute]. |
1431
049b89c5bf60
cache mountPoints; faster directoryRead & sort
Claus Gittinger <cg@exept.de>
parents:
1393
diff
changeset
|
602 |
mountPoints := self cachedRemoteMountPoints. |
1468
476e360d4aeb
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
1435
diff
changeset
|
603 |
info := fileName linkInfo. |
2047 | 604 |
|
1468
476e360d4aeb
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
1435
diff
changeset
|
605 |
(info notNil and:[info isSymbolicLink]) ifTrue:[ |
2047 | 606 |
OperatingSystem isMSWINDOWSlike ifFalse:[ |
607 |
linkName := info path. |
|
2046 | 608 |
|
2047 | 609 |
linkName notNil ifTrue:[ |
610 |
"have to check for both link and link target" |
|
611 |
mountPoint := mountPoints |
|
612 |
detect:[:mInfo | |p| |
|
613 |
p := mInfo mountPointPath. |
|
614 |
((linkName startsWith:p) and:[ linkName startsWith:(p , '/') ]) |
|
615 |
] |
|
616 |
ifNone:nil. |
|
617 |
||
618 |
info := fileName info. "get the info of the link target" |
|
619 |
]. |
|
620 |
]. |
|
1351
9741c3cbc395
avoid blocking on mounted directories;
Claus Gittinger <cg@exept.de>
parents:
1350
diff
changeset
|
621 |
] ifFalse:[ |
1468
476e360d4aeb
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
1435
diff
changeset
|
622 |
"have to check for mountPoint only" |
1351
9741c3cbc395
avoid blocking on mounted directories;
Claus Gittinger <cg@exept.de>
parents:
1350
diff
changeset
|
623 |
mountPoint := mountPoints |
1468
476e360d4aeb
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
1435
diff
changeset
|
624 |
detect:[:mInfo | mInfo mountPointPath = nameString ] |
476e360d4aeb
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
1435
diff
changeset
|
625 |
ifNone:nil. |
1351
9741c3cbc395
avoid blocking on mounted directories;
Claus Gittinger <cg@exept.de>
parents:
1350
diff
changeset
|
626 |
]. |
2047 | 627 |
mountPoint notNil ifTrue:[ |
1350 | 628 |
info := #remoteDirectory. |
629 |
] ifFalse:[ |
|
630 |
info isNil ifTrue:[ |
|
631 |
"/ broken symbolic link |
|
632 |
info := #symbolicLink. |
|
633 |
] |
|
634 |
]. |
|
635 |
]. |
|
636 |
! ! |
|
637 |
||
1093 | 638 |
!DirectoryContents::DirectoryContentsItem methodsFor:'printing'! |
639 |
||
640 |
printOn:aStream |
|
641 |
aStream nextPutAll:'DirectoryContentsItem for: '. |
|
642 |
fileName printOn:aStream. |
|
643 |
! ! |
|
644 |
||
645 |
!DirectoryContents::DirectoryContentsItem methodsFor:'queries'! |
|
646 |
||
647 |
isDirectory |
|
1099 | 648 |
|t| |
649 |
||
650 |
t := self type. |
|
651 |
^ (t == #directory or:[t == #remoteDirectory]) |
|
1093 | 652 |
! |
653 |
||
654 |
isRemoteDirectory |
|
2074 | 655 |
^ self type == #remoteDirectory |
656 |
! |
|
657 |
||
658 |
isSymbolicLink |
|
659 |
^ self type == #isymbolicLink |
|
583 | 660 |
! ! |
661 |
||
662 |
!DirectoryContents class methodsFor:'documentation'! |
|
663 |
||
664 |
version |
|
2074 | 665 |
^ '$Header: /cvs/stx/stx/libbasic2/DirectoryContents.st,v 1.46 2008-12-17 12:45:08 ca Exp $' |
583 | 666 |
! ! |
1093 | 667 |
|
957 | 668 |
DirectoryContents initialize! |