author | Claus Gittinger <cg@exept.de> |
Wed, 18 Jun 2003 21:04:56 +0200 | |
changeset 1253 | 598408cdecc7 |
parent 1252 | 933afe6d5bd6 |
child 1296 | 44feec34ff6c |
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' |
1093 | 26 |
classVariableNames:'' |
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:[ |
125 |
[ "/ test whether another task gots the semaphore and |
|
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 |
|
1105 | 173 |
directory isDirectory ifTrue:[ |
958 | 174 |
LockSema critical:[ |
175 |
CachedDirectories notNil ifTrue:[ |
|
1105 | 176 |
directory := directory asAbsoluteFilename. |
177 |
index := CachedDirectories findFirst:[:d| d directory = directory ]. |
|
958 | 178 |
|
179 |
index ~~ 0 ifTrue:[ |
|
180 |
CachedDirectories removeAtIndex:index. |
|
181 |
] |
|
182 |
] |
|
183 |
] |
|
184 |
] |
|
185 |
]. |
|
186 |
! |
|
187 |
||
695
368ddb719976
only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents:
679
diff
changeset
|
188 |
lowSpaceCleanup |
368ddb719976
only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents:
679
diff
changeset
|
189 |
"flush list of rememebred directory contents when low on memory" |
368ddb719976
only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents:
679
diff
changeset
|
190 |
|
1134 | 191 |
self flushCache |
695
368ddb719976
only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents:
679
diff
changeset
|
192 |
|
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 |
self lowSpaceCleanup |
368ddb719976
only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents:
679
diff
changeset
|
195 |
" |
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 |
"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
|
198 |
"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
|
199 |
! |
368ddb719976
only cache dir if its mod'time is known (for win32)
Claus Gittinger <cg@exept.de>
parents:
679
diff
changeset
|
200 |
|
616
cb0377b446bd
flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
201 |
preSnapshot |
cb0377b446bd
flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
202 |
"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
|
203 |
|
957 | 204 |
CachedDirectories := nil. |
616
cb0377b446bd
flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
205 |
|
cb0377b446bd
flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
206 |
"Created: / 18.2.1998 / 18:17:05 / cg" |
cb0377b446bd
flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
207 |
! ! |
cb0377b446bd
flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
208 |
|
583 | 209 |
!DirectoryContents class methodsFor:'constants'! |
210 |
||
211 |
maxCachedDirectories |
|
212 |
"returns number of maximum cached directories |
|
213 |
" |
|
616
cb0377b446bd
flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
214 |
^ 20 |
cb0377b446bd
flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
215 |
|
cb0377b446bd
flush cachedDirectory list when saving a snapshot
Claus Gittinger <cg@exept.de>
parents:
583
diff
changeset
|
216 |
"Modified: / 25.2.1998 / 19:56:24 / cg" |
583 | 217 |
! ! |
218 |
||
219 |
!DirectoryContents class methodsFor:'private'! |
|
220 |
||
221 |
directoryAt:aFilename |
|
222 |
"checks whether directory already exists and is valid. |
|
223 |
If true the directory is returned otherwise nil |
|
224 |
" |
|
1105 | 225 |
|index directory absoluteFilename| |
583 | 226 |
|
957 | 227 |
directory := nil. |
228 |
||
229 |
LockSema critical:[ |
|
230 |
CachedDirectories notNil ifTrue:[ |
|
1105 | 231 |
absoluteFilename := aFilename asFilename asAbsoluteFilename. |
232 |
index := CachedDirectories findFirst:[:d| d directory = absoluteFilename ]. |
|
583 | 233 |
|
957 | 234 |
index ~~ 0 ifTrue:[ |
235 |
directory := CachedDirectories at:index. |
|
583 | 236 |
|
957 | 237 |
directory isObsolete ifTrue:[ |
238 |
CachedDirectories removeAtIndex:index. |
|
239 |
directory := nil. |
|
240 |
] |
|
241 |
] |
|
583 | 242 |
] |
243 |
]. |
|
957 | 244 |
^ directory |
583 | 245 |
! ! |
246 |
||
247 |
!DirectoryContents class methodsFor:'queries'! |
|
248 |
||
249 |
directoryNamed:aDirectoryName detect:aTwoArgBlock |
|
250 |
"evaluate the block, [:filename :isDirectory] on the directory |
|
251 |
contents of a directory named aDirectoryName, until the block |
|
252 |
returns true. If nothing detected false is returned |
|
253 |
" |
|
1155
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
254 |
|directory dir| |
583 | 255 |
|
256 |
directory := aDirectoryName asFilename. |
|
257 |
||
620 | 258 |
directory exists ifFalse:[ |
259 |
^ false |
|
260 |
]. |
|
261 |
||
583 | 262 |
(dir := self directoryAt:directory) notNil ifTrue:[ |
263 |
dir contentsDo:[:aFile :isDir| |
|
264 |
(aTwoArgBlock value:aFile value:isDir) ifTrue:[^ true] |
|
265 |
]. |
|
266 |
^ false |
|
1155
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
267 |
]. |
583 | 268 |
|
1155
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
269 |
[ |
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
270 |
directory directoryContentsDo:[:fn | |
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
271 |
|file| |
583 | 272 |
|
1155
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
273 |
file := directory construct:fn. |
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
274 |
(aTwoArgBlock value:file value:(file isDirectory)) ifTrue:[ |
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
275 |
^ true |
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 |
]. |
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
278 |
] on:FileStream openErrorSignal do:[:ex| |
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
279 |
"cannot open directory" |
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
280 |
^ false |
583 | 281 |
]. |
696
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
282 |
|
1155
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
283 |
|
696
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
284 |
"/ dir := DirectoryStream directoryNamed:(directory pathName). |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
285 |
"/ |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
286 |
"/ dir isNil ifFalse:[ |
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 |
"/ [dir atEnd] whileFalse:[ |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
289 |
"/ (name := dir nextLine) notNil ifTrue:[ |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
290 |
"/ name := directory construct:name. |
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 |
"/ (aTwoArgBlock value:name value:(name isDirectory)) ifTrue:[ |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
293 |
"/ ^ true |
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 |
"/ ]. |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
297 |
"/ ] valueNowOrOnUnwindDo:[ |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
298 |
"/ dir close. |
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 |
"/ ]. |
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
301 |
|
583 | 302 |
^ false |
696
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
303 |
|
9d1571f69f8e
use fileName>>directoryContents instead of a DirectoryStream.
Claus Gittinger <cg@exept.de>
parents:
695
diff
changeset
|
304 |
"Modified: / 24.9.1998 / 21:14:58 / cg" |
583 | 305 |
! ! |
306 |
||
1102 | 307 |
!DirectoryContents class methodsFor:'utilities'! |
308 |
||
309 |
contentsItemForFileName:aFilenameOrString |
|
310 |
| aFilename directory directoryContents| |
|
311 |
||
312 |
aFilename := aFilenameOrString asFilename. |
|
313 |
directory := aFilename directory. |
|
314 |
directoryContents := self directoryNamed:directory. |
|
1252
933afe6d5bd6
care for directory being removed
Claus Gittinger <cg@exept.de>
parents:
1198
diff
changeset
|
315 |
directoryContents isNil ifTrue:[^ nil]. |
933afe6d5bd6
care for directory being removed
Claus Gittinger <cg@exept.de>
parents:
1198
diff
changeset
|
316 |
|
1253 | 317 |
directoryContents itemsDo:[:fileItemThere | |
1102 | 318 |
fileItemThere fileName = aFilename ifTrue:[ |
319 |
^ fileItemThere. |
|
320 |
] |
|
321 |
]. |
|
1105 | 322 |
^ (DirectoryContentsItem new fileName:aFilename) info:aFilename info. |
1102 | 323 |
|
324 |
" |
|
325 |
DirectoryContents contentsItemForFileName:'/etc/passwd' |
|
1105 | 326 |
DirectoryContents contentsItemForFileName:'/' |
1102 | 327 |
" |
328 |
! ! |
|
329 |
||
583 | 330 |
!DirectoryContents methodsFor:'accessing'! |
331 |
||
332 |
directory |
|
333 |
"returns the directoy name as Filename |
|
334 |
" |
|
335 |
^ directory |
|
336 |
! |
|
337 |
||
338 |
modificationTime |
|
339 |
"get the last modification time of the directory |
|
340 |
" |
|
951 | 341 |
^ directory modificationTime |
342 |
! |
|
343 |
||
344 |
timeStamp |
|
345 |
"get the last timeStamp (when the directory info was read) of the directory |
|
346 |
" |
|
583 | 347 |
^ timeStamp |
348 |
! ! |
|
349 |
||
350 |
!DirectoryContents methodsFor:'enumerating'! |
|
351 |
||
352 |
contentsAndBaseNamesDo:aThreeArgBlock |
|
353 |
"evaluate the block on each file; the argument to the block is the |
|
354 |
filename, the baseName and true in case of a directory |
|
355 |
block arguments: [:fileName :aBaseName :isDirectory| |
|
356 |
" |
|
1093 | 357 |
self itemsDo:[:eachItem | |
358 |
aThreeArgBlock |
|
359 |
value:(eachItem fileName) |
|
360 |
value:(eachItem baseName ) |
|
361 |
value:(eachItem isDirectory) |
|
583 | 362 |
]. |
363 |
! |
|
364 |
||
365 |
contentsDo:aTwoArgBlock |
|
366 |
"evaluate the block on each file; the argument to the block is the |
|
367 |
filename and true in case of a directory |
|
368 |
block arguments: [:fileName :isDirectory| |
|
369 |
" |
|
1093 | 370 |
self itemsDo:[:eachItem | |
371 |
aTwoArgBlock |
|
372 |
value:(eachItem fileName) |
|
373 |
value:(eachItem isDirectory) |
|
583 | 374 |
]. |
375 |
! |
|
376 |
||
377 |
directoriesAndBasenamesDo:aTwoArgBlock |
|
378 |
"evaluate block on each directory; a Filename and Basename. |
|
379 |
The directories are sorted |
|
380 |
" |
|
1093 | 381 |
self itemsDo:[:eachItem | |
382 |
eachItem isDirectory ifTrue:[ |
|
383 |
aTwoArgBlock value:(eachItem fileName) value:(eachItem baseName) |
|
583 | 384 |
] |
385 |
] |
|
386 |
! |
|
387 |
||
388 |
directoriesDo:aOneArgBlock |
|
389 |
"evaluate block on each directory; a Filename. The directories are sorted |
|
390 |
" |
|
1093 | 391 |
self itemsDo:[:eachItem | |
392 |
eachItem isDirectory ifTrue:[ |
|
393 |
aOneArgBlock |
|
394 |
value:(eachItem fileName) |
|
583 | 395 |
] |
1093 | 396 |
]. |
583 | 397 |
! |
398 |
||
399 |
filesAndBasenamesDo:aTwoArgBlock |
|
400 |
"evaluate block on each file; a Filename and a Basename. |
|
401 |
The files are sorted. |
|
402 |
" |
|
1093 | 403 |
self itemsDo:[:eachItem | |
404 |
eachItem isDirectory not ifTrue:[ |
|
405 |
aTwoArgBlock value:(eachItem fileName) value:(eachItem baseName) |
|
583 | 406 |
] |
407 |
] |
|
408 |
! |
|
409 |
||
410 |
filesDo:aOneArgBlock |
|
411 |
"evaluate block on each file; a Filename. The files are sorted. |
|
412 |
" |
|
1093 | 413 |
self itemsDo:[:eachItem | |
414 |
eachItem isDirectory not ifTrue:[ |
|
415 |
aOneArgBlock value:(eachItem fileName) |
|
583 | 416 |
] |
417 |
] |
|
1093 | 418 |
! |
419 |
||
420 |
itemsDo:aBlock |
|
421 |
"evaluate the block on each contentsItem, which contains the fileName and type info" |
|
422 |
||
423 |
self updateContents. |
|
424 |
contents do:aBlock. |
|
583 | 425 |
! ! |
426 |
||
427 |
!DirectoryContents methodsFor:'instance creation'! |
|
428 |
||
429 |
directory:aFilename |
|
1155
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
430 |
"instance creation; setup attributes" |
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
431 |
|
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
432 |
|t dircontents| |
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
433 |
|
583 | 434 |
directory := aFilename asFilename. |
1101 | 435 |
t := AbsoluteTime now. "/ directory modificationTime. |
1155
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
436 |
[ |
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
437 |
dircontents := directory directoryContentsAsFilenames. |
1147 | 438 |
dircontents sort:[:a :b | a baseName < b baseName]. |
1101 | 439 |
contents := dircontents |
1105 | 440 |
collect:[:eachFilename | DirectoryContentsItem new fileName:eachFilename]. |
1155
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
441 |
] on:FileStream openErrorSignal do:[:ex| |
edcf3cfe1e93
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
1147
diff
changeset
|
442 |
contents := #(). |
1093 | 443 |
]. |
1101 | 444 |
timeStamp := t. |
1093 | 445 |
! ! |
446 |
||
447 |
!DirectoryContents methodsFor:'printing'! |
|
448 |
||
449 |
printOn:aStream |
|
450 |
aStream nextPutAll:'DirectoryContents of: '. |
|
451 |
directory printOn:aStream. |
|
583 | 452 |
! ! |
453 |
||
454 |
!DirectoryContents methodsFor:'private'! |
|
455 |
||
1093 | 456 |
updateContents |
457 |
"check whether files and types are set" |
|
583 | 458 |
|
1093 | 459 |
|mountPoints| |
460 |
||
461 |
contents do:[:eachItem | |
|
462 |
|file type mountInfo| |
|
583 | 463 |
|
1093 | 464 |
type := eachItem type. |
465 |
type isNil ifTrue:[ |
|
466 |
file := eachItem fileName. |
|
467 |
mountPoints isNil ifTrue:[ |
|
468 |
mountPoints := OperatingSystem mountPoints. |
|
469 |
]. |
|
583 | 470 |
|
1093 | 471 |
mountInfo := mountPoints detect:[:mInfo | mInfo mountPointPath = file name] ifNone:nil. |
472 |
(mountInfo notNil and:[mountInfo isRemote]) ifTrue:[ |
|
1099 | 473 |
eachItem info:#remoteDirectory. |
1093 | 474 |
] ifFalse:[ |
1099 | 475 |
eachItem info:file info. |
1093 | 476 |
]. |
727 | 477 |
]. |
583 | 478 |
]. |
479 |
! ! |
|
480 |
||
481 |
!DirectoryContents methodsFor:'queries'! |
|
482 |
||
483 |
isObsolete |
|
484 |
"returns true if directory contents is obsolete |
|
485 |
" |
|
951 | 486 |
|
974
c4be514ddd96
fix for windows bug (directory has no modification time)
Claus Gittinger <cg@exept.de>
parents:
958
diff
changeset
|
487 |
|mt| |
679 | 488 |
|
974
c4be514ddd96
fix for windows bug (directory has no modification time)
Claus Gittinger <cg@exept.de>
parents:
958
diff
changeset
|
489 |
directory exists ifFalse:[^ true]. |
c4be514ddd96
fix for windows bug (directory has no modification time)
Claus Gittinger <cg@exept.de>
parents:
958
diff
changeset
|
490 |
timeStamp isNil ifTrue:[^ true]. |
c4be514ddd96
fix for windows bug (directory has no modification time)
Claus Gittinger <cg@exept.de>
parents:
958
diff
changeset
|
491 |
(mt := directory modificationTime) isNil ifTrue:[^ true]. |
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 |
536 |
info isSymbol ifTrue:[^ nil]. "/ a remote directory |
|
537 |
^ info |
|
538 |
! |
|
539 |
||
1099 | 540 |
info:something |
541 |
"set the value of the instance variable 'type' (automatically generated)" |
|
542 |
||
543 |
info := something. |
|
544 |
! |
|
545 |
||
1093 | 546 |
type |
1198 | 547 |
info isNil ifTrue:[^ info]. |
1099 | 548 |
info isSymbol ifTrue:[^ info]. |
549 |
^ info type |
|
1093 | 550 |
! ! |
551 |
||
552 |
!DirectoryContents::DirectoryContentsItem methodsFor:'printing'! |
|
553 |
||
554 |
printOn:aStream |
|
555 |
aStream nextPutAll:'DirectoryContentsItem for: '. |
|
556 |
fileName printOn:aStream. |
|
557 |
! ! |
|
558 |
||
559 |
!DirectoryContents::DirectoryContentsItem methodsFor:'queries'! |
|
560 |
||
561 |
isDirectory |
|
1099 | 562 |
|t| |
563 |
||
564 |
t := self type. |
|
565 |
^ (t == #directory or:[t == #remoteDirectory]) |
|
1093 | 566 |
! |
567 |
||
568 |
isRemoteDirectory |
|
1099 | 569 |
^ info == #remoteDirectory |
583 | 570 |
! ! |
571 |
||
572 |
!DirectoryContents class methodsFor:'documentation'! |
|
573 |
||
574 |
version |
|
1253 | 575 |
^ '$Header: /cvs/stx/stx/libbasic2/DirectoryContents.st,v 1.29 2003-06-18 19:04:56 cg Exp $' |
583 | 576 |
! ! |
1093 | 577 |
|
957 | 578 |
DirectoryContents initialize! |