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