author | Claus Gittinger <cg@exept.de> |
Wed, 26 Jun 2019 22:06:12 +0200 | |
changeset 24369 | e796791ea838 |
parent 24235 | 210f242ffbd9 |
child 24379 | 852be153b0ec |
permissions | -rw-r--r-- |
18272 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1 | 3 |
" |
5 | 4 |
COPYRIGHT (c) 1992 by Claus Gittinger |
24017 | 5 |
All Rights Reserved |
1 | 6 |
|
7 |
This software is furnished under a license and may be used |
|
8 |
only in accordance with the terms of that license and with the |
|
9 |
inclusion of the above copyright notice. This software may not |
|
10 |
be provided or otherwise made available to, or used by, any |
|
11 |
other person. No title to or ownership of the software is |
|
12 |
hereby transferred. |
|
13 |
" |
|
5507
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
14 |
"{ Package: 'stx:libbasic' }" |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
15 |
|
17310 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
1 | 18 |
Object subclass:#Filename |
24101 | 19 |
instanceVariableNames:'nameString' |
20 |
classVariableNames:'ConcreteClass DefaultTempDirectory TempDirectory' |
|
21 |
poolDictionaries:'' |
|
22 |
category:'System-Support' |
|
615 | 23 |
! |
1 | 24 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
25 |
!Filename class methodsFor:'documentation'! |
88 | 26 |
|
27 |
copyright |
|
28 |
" |
|
29 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
24017 | 30 |
All Rights Reserved |
1 | 31 |
|
88 | 32 |
This software is furnished under a license and may be used |
33 |
only in accordance with the terms of that license and with the |
|
34 |
inclusion of the above copyright notice. This software may not |
|
35 |
be provided or otherwise made available to, or used by, any |
|
36 |
other person. No title to or ownership of the software is |
|
37 |
hereby transferred. |
|
38 |
" |
|
39 |
! |
|
40 |
||
41 |
documentation |
|
42 |
" |
|
43 |
Filenames; originally added for ST-80 compatibility, is |
|
44 |
taking over functionality from other classes (FileDirectory). |
|
92 | 45 |
|
21778 | 46 |
Instances of Filename do not necessarily represent valid or existing |
92 | 47 |
files - i.e. it is possible (and useful) to have instances for non-existing |
48 |
files around. In other words: the name-string is not checked automatically |
|
49 |
for being correct or existing. |
|
50 |
Thus, it is possible to do queries such as: |
|
51 |
||
20293 | 52 |
'/fee/foo/foe' asFilename exists |
53 |
'/not_existing' asFilename isDirectory |
|
54 |
'/foo/bar' asFilename isReadable |
|
92 | 55 |
|
195 | 56 |
(all of the above examples will probably return false on your machine ;-). |
276 | 57 |
|
58 |
examples: |
|
59 |
||
20293 | 60 |
'Makefile' asFilename readStream |
61 |
||
62 |
'newFile' asFilename writeStream |
|
63 |
||
64 |
Filename newTemporary writeStream |
|
276 | 65 |
|
21779 | 66 |
Beside lots of protocol to query for a file's attributes, the class |
20293 | 67 |
protocol offers methods for filename completion, to construct paths |
1318 | 68 |
(in an OS-independent way) and to create temporary files. |
21779 | 69 |
Especially the path construction methods (i.e. #construct:) are highly |
1318 | 70 |
recommended in order to avoid having OS details (like directory separators |
21779 | 71 |
being slash or backslash) spread in your application. |
1318 | 72 |
|
8738 | 73 |
Since Filenames have different semantics under different operating systems, |
74 |
class methods are delegated to concrete implementations in various subclasses like |
|
75 |
UnixFilename, PCFilename, ... |
|
76 |
The delegation is implemented in a way, so that some methods of |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
77 |
specific OS Filenames might be used, even if ST/X is currently running |
8738 | 78 |
on a different OS (as long as the method does not depend on the OperatingSystem class). |
79 |
||
1286 | 80 |
[author:] |
20293 | 81 |
Claus Gittinger |
276 | 82 |
|
1286 | 83 |
[see also:] |
20293 | 84 |
String |
85 |
FileStream DirectoryStream PipeStream Socket |
|
86 |
OperatingSystem |
|
87 |
Date Time |
|
88 | 88 |
" |
360 | 89 |
! |
90 |
||
91 |
examples |
|
92 |
" |
|
93 |
does a file/directory exist ?: |
|
24017 | 94 |
[exBegin] |
95 |
|f| |
|
96 |
||
97 |
f := 'foobar' asFilename. |
|
98 |
^ f exists |
|
99 |
[exEnd] |
|
360 | 100 |
|
101 |
||
102 |
is it a directory ?: |
|
24017 | 103 |
[exBegin] |
104 |
|f| |
|
105 |
||
106 |
f := '/tmp' asFilename. |
|
107 |
^ f isDirectory. |
|
108 |
[exEnd] |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
109 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
110 |
|
360 | 111 |
get the working directory: |
24017 | 112 |
[exBegin] |
113 |
^ Filename defaultDirectory |
|
114 |
[exEnd] |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
115 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
116 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
117 |
get a files full pathname |
360 | 118 |
(caring for relative names or symbolic links): |
24017 | 119 |
[exBegin] |
120 |
|f| |
|
121 |
||
122 |
f := '..' asFilename. |
|
123 |
^ f pathName |
|
124 |
[exEnd] |
|
360 | 125 |
|
126 |
||
127 |
get a directories directory: |
|
24017 | 128 |
[exBegin] |
129 |
|f| |
|
130 |
||
131 |
f := Filename defaultDirectory. |
|
132 |
^ f directory |
|
133 |
[exEnd] |
|
360 | 134 |
|
135 |
||
136 |
get a files directory: |
|
24017 | 137 |
[exBegin] |
138 |
|f| |
|
139 |
||
140 |
f := './smalltalk' asFilename. |
|
141 |
^ f directory |
|
142 |
[exEnd] |
|
360 | 143 |
|
144 |
||
145 |
getting access & modification times: |
|
24017 | 146 |
[exBegin] |
147 |
|f| |
|
148 |
||
149 |
f := '/tmp' asFilename. |
|
150 |
^ f dates |
|
151 |
[exEnd] |
|
360 | 152 |
|
153 |
access time only: |
|
24017 | 154 |
[exBegin] |
155 |
|f| |
|
156 |
||
157 |
f := '/tmp' asFilename. |
|
158 |
^ f dates at:#accessed |
|
159 |
[exEnd] |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
160 |
|
360 | 161 |
|
162 |
getting all information on a file/directory: |
|
24017 | 163 |
[exBegin] |
164 |
|f| |
|
165 |
||
166 |
f := '/tmp' asFilename. |
|
167 |
^ f info |
|
168 |
[exEnd] |
|
360 | 169 |
|
170 |
||
171 |
getting a temporary file (unique name): |
|
24017 | 172 |
[exBegin] |
173 |
|f| |
|
174 |
||
175 |
f := Filename newTemporary. |
|
176 |
^ f |
|
177 |
[exEnd] |
|
360 | 178 |
|
179 |
creating, writing, reading and removing a temporary file: |
|
24017 | 180 |
[exBegin] |
181 |
|f writeStream readStream| |
|
182 |
||
183 |
f := Filename newTemporary. |
|
184 |
writeStream := f writeStream. |
|
185 |
writeStream nextPutAll:'hello world'. |
|
186 |
writeStream cr. |
|
187 |
writeStream close. |
|
188 |
||
189 |
'contents (as seen by unix''s cat command:' printNL. |
|
190 |
OperatingSystem executeCommand:('cat ' , f pathName). |
|
191 |
||
192 |
readStream := f readStream. |
|
193 |
Transcript showCR:'contents as seen by smalltalk:'. |
|
194 |
Transcript showCR:(readStream upToEnd). |
|
195 |
readStream close. |
|
196 |
||
197 |
f delete. |
|
198 |
[exEnd] |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
199 |
|
360 | 200 |
|
201 |
getting a directories contents: |
|
24017 | 202 |
[exBegin] |
203 |
|f files| |
|
204 |
||
205 |
f := Filename currentDirectory. |
|
206 |
files := f directoryContents. |
|
207 |
Transcript showCR:'the files are:'. |
|
208 |
Transcript showCR:(files printString). |
|
209 |
[exEnd] |
|
360 | 210 |
|
211 |
||
212 |
editing a file: |
|
24017 | 213 |
[exBegin] |
214 |
|f| |
|
215 |
||
216 |
f := Filename newTemporary. |
|
217 |
(f writeStream) nextPutAll:'hello world'; close. |
|
218 |
||
219 |
f edit |
|
220 |
[exEnd] |
|
360 | 221 |
" |
88 | 222 |
! ! |
1 | 223 |
|
2906 | 224 |
!Filename class methodsFor:'initialization'! |
225 |
||
226 |
initialize |
|
227 |
"initialize for the OS we are running on" |
|
228 |
||
8754 | 229 |
ConcreteClass isNil ifTrue:[ |
24017 | 230 |
self initializeConcreteClass |
7702 | 231 |
]. |
2906 | 232 |
|
233 |
" |
|
234 |
self initialize |
|
235 |
" |
|
236 |
||
237 |
"Created: 7.9.1997 / 23:32:55 / cg" |
|
238 |
! |
|
239 |
||
240 |
initializeConcreteClass |
|
241 |
"initialize for the OS we are running on" |
|
242 |
||
8754 | 243 |
OperatingSystem isUNIXlike ifTrue:[ |
24017 | 244 |
ConcreteClass := UnixFilename |
8754 | 245 |
] ifFalse:[OperatingSystem isMSDOSlike ifTrue:[ |
24017 | 246 |
ConcreteClass := PCFilename |
8754 | 247 |
] ifFalse:[OperatingSystem isVMSlike ifTrue:[ |
24017 | 248 |
ConcreteClass := OpenVMSFilename |
2906 | 249 |
] ifFalse:[ |
24017 | 250 |
self error:'Filename: unknown OperatingSystem when initializing concrete Filename class'. |
8754 | 251 |
]]]. |
252 |
||
253 |
ConcreteClass isNil ifTrue:[ |
|
24017 | 254 |
self error:'Filename: Missing concrete Filename class'. |
8754 | 255 |
]. |
256 |
||
257 |
" |
|
258 |
self initializeConcreteClass |
|
2906 | 259 |
" |
260 |
||
261 |
"Modified: 7.9.1997 / 23:32:37 / cg" |
|
262 |
! |
|
263 |
||
264 |
reinitialize |
|
8738 | 265 |
"initialize for the OS we are running on (after a restart)" |
2906 | 266 |
|
9806 | 267 |
TempDirectory := nil. |
268 |
self initializeConcreteClass. |
|
2906 | 269 |
|
270 |
" |
|
8754 | 271 |
self reinitialize |
2906 | 272 |
" |
273 |
||
9806 | 274 |
"Created: / 07-09-1997 / 23:33:02 / cg" |
275 |
"Modified: / 29-08-2006 / 12:40:28 / cg" |
|
2906 | 276 |
! ! |
277 |
||
3959 | 278 |
!Filename class methodsFor:'instance creation'! |
279 |
||
17227 | 280 |
applicationDataDirectory |
281 |
"return the directory, where user-and-application-specific private files are to be |
|
282 |
located (ini-files, preferences etc.). |
|
283 |
Under windows, something like 'C:\Users\Administrator\AppData\Roaming\<appName>' |
|
284 |
is returned, under unix, we use ~/.<appName> (but see details in UnixOS). |
|
285 |
For smalltalk itself (the IDE), 'smalltalk' is used as appName. |
|
286 |
If the directory does not exist, it is created" |
|
287 |
||
288 |
|exeName| |
|
289 |
||
290 |
Smalltalk isStandAloneApp ifTrue:[ |
|
24017 | 291 |
exeName := OperatingSystem nameOfSTXExecutable. |
17227 | 292 |
] ifFalse:[ |
24017 | 293 |
exeName := 'smalltalk' |
17227 | 294 |
]. |
295 |
^ self applicationDataDirectoryFor:exeName |
|
296 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
297 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
298 |
Filename applicationDataDirectory |
17227 | 299 |
" |
300 |
! |
|
301 |
||
12972 | 302 |
applicationDataDirectoryFor:appName |
303 |
"return the directory, where user-and-application-specific private files are to be |
|
304 |
located (ini-files, preferences etc.). |
|
305 |
Under windows, something like 'C:\Users\Administrator\AppData\Roaming\<appName>' |
|
12973 | 306 |
is returned, under unix, we use ~/.<appName> (but see details in UnixOS). |
12974 | 307 |
If the directory does not exist, it is created" |
308 |
||
23606 | 309 |
|s dir firstTime| |
12972 | 310 |
|
311 |
s := OperatingSystem getApplicationDataDirectoryFor:appName. |
|
312 |
s isNil ifTrue:[ |
|
23605 | 313 |
^ self homeDirectory |
12972 | 314 |
]. |
12974 | 315 |
dir := self named:s. |
23605 | 316 |
dir isWritableDirectory ifFalse:[ |
23606 | 317 |
firstTime := true. |
23605 | 318 |
[ |
319 |
dir makeDirectory. |
|
320 |
] on:OsError do:[:ex| |
|
23606 | 321 |
firstTime ifTrue:[ |
322 |
firstTime := false. |
|
23605 | 323 |
dir := self tempDirectory / appName. |
23606 | 324 |
dir isWritableDirectory ifFalse:[ |
325 |
ex restart. |
|
326 |
]. |
|
327 |
] ifFalse:[ |
|
328 |
ex reject. |
|
23605 | 329 |
]. |
330 |
]. |
|
12974 | 331 |
]. |
332 |
^ dir |
|
12972 | 333 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
334 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
335 |
Filename applicationDataDirectoryFor:'smalltalk' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
336 |
Filename applicationDataDirectoryFor:'expecco' |
12972 | 337 |
" |
338 |
||
339 |
"Created: / 29-07-2010 / 12:05:35 / sr" |
|
23606 | 340 |
"Modified: / 16-01-2019 / 14:29:59 / Stefan Vogel" |
12972 | 341 |
! |
342 |
||
3959 | 343 |
currentDirectory |
344 |
"return a filename for the current directory" |
|
345 |
||
13109 | 346 |
^ self named:(OperatingSystem getCurrentDirectory). |
3959 | 347 |
|
348 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
349 |
Filename currentDirectory |
3959 | 350 |
" |
351 |
! |
|
352 |
||
353 |
defaultDirectory |
|
354 |
"ST80 compatibility: same as currentDirectory" |
|
355 |
||
356 |
^ self currentDirectory |
|
357 |
||
358 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
359 |
Filename defaultDirectory |
3959 | 360 |
" |
361 |
! |
|
362 |
||
12336
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
363 |
defaultTempDirectory |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
364 |
"return the default temp directory as a filename. |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
365 |
That is the same as TempDirectory, except that TempDirectory can be changed |
17048 | 366 |
from the outside (via tempDirectory:) whereas this is the OS's original default. |
12336
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
367 |
Use this for files which MUST remain the same (stx_sourceCache)" |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
368 |
|
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
369 |
DefaultTempDirectory isNil ifTrue:[ |
24017 | 370 |
self tempDirectory. "/ actually sets DefaultTempDirectory as side effect |
371 |
DefaultTempDirectory isNil ifTrue:[ |
|
372 |
DefaultTempDirectory := TempDirectory |
|
373 |
]. |
|
12336
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
374 |
]. |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
375 |
|
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
376 |
DefaultTempDirectory exists ifFalse:[ |
24017 | 377 |
DefaultTempDirectory |
378 |
makeDirectory; |
|
379 |
addAccessRights:#(readUser readGroup readOthers |
|
380 |
writeUser writeGroup writeOthers |
|
381 |
executeUser executeGroup executeOthers |
|
382 |
removeOnlyByOwner). |
|
12336
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
383 |
]. |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
384 |
^ DefaultTempDirectory |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
385 |
|
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
386 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
387 |
Filename tempDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
388 |
Filename defaultTempDirectory |
12336
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
389 |
" |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
390 |
|
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
391 |
"Created: / 07-03-1996 / 14:51:18 / cg" |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
392 |
"Modified: / 29-08-2006 / 12:57:16 / cg" |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
393 |
! |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
394 |
|
10546 | 395 |
desktopDirectory |
396 |
"return your desktop directory. |
|
20413 | 397 |
Under windows, that's the real desktop directory; |
10546 | 398 |
under other OperatingSystems, the home directory is returned." |
399 |
||
400 |
|s| |
|
401 |
||
402 |
s := OperatingSystem getDesktopDirectory. |
|
403 |
s isNil ifTrue:[ |
|
20413 | 404 |
^ self homeDirectory |
10546 | 405 |
]. |
406 |
^ self named:s |
|
407 |
||
408 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
409 |
Filename desktopDirectory |
10546 | 410 |
" |
411 |
||
412 |
"Created: / 16-05-2007 / 13:18:34 / cg" |
|
413 |
! |
|
414 |
||
11763 | 415 |
documentsDirectory |
416 |
"return your documents directory. |
|
20413 | 417 |
Under windows, that's the real 'Documents' or 'My Documents'; |
11763 | 418 |
under other OperatingSystems, the home directory is returned." |
419 |
||
420 |
|s| |
|
421 |
||
422 |
s := OperatingSystem getDocumentsDirectory. |
|
423 |
s isNil ifTrue:[ |
|
20413 | 424 |
^ self homeDirectory |
11763 | 425 |
]. |
426 |
^ self named:s |
|
427 |
||
428 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
429 |
Filename documentsDirectory |
11763 | 430 |
" |
431 |
||
432 |
"Created: / 16-05-2007 / 13:18:34 / cg" |
|
433 |
! |
|
434 |
||
22676 | 435 |
downloadsDirectory |
436 |
"return the downloads directory. |
|
437 |
Some OperatingSystems do not support this - on those, |
|
438 |
the documentsDirectory is returned. |
|
439 |
Notice: services under windows do not have a user/home and therefore |
|
440 |
no downloads directory." |
|
441 |
||
442 |
|home dir| |
|
443 |
||
444 |
home := self homeDirectory. |
|
445 |
home isNil ifTrue:[^ nil]. |
|
446 |
#( |
|
447 |
'Downloads' |
|
448 |
'downloads' |
|
449 |
'Download' |
|
450 |
'download' |
|
451 |
) do:[:eachTry | |
|
452 |
(dir := home / eachTry) exists ifTrue:[ |
|
453 |
^ dir |
|
454 |
]. |
|
455 |
]. |
|
456 |
^ nil |
|
457 |
||
458 |
" |
|
459 |
Filename downloadsDirectory |
|
460 |
" |
|
461 |
! |
|
462 |
||
3959 | 463 |
findDefaultDirectory |
464 |
"same as #defaultDirectory for ST80 compatibility" |
|
465 |
||
466 |
^ self defaultDirectory |
|
467 |
||
468 |
"Created: 20.6.1997 / 17:00:29 / cg" |
|
469 |
! |
|
470 |
||
471 |
fromComponents:aCollectionOfDirectoryNames |
|
472 |
"create & return a new filename from components given in |
|
473 |
aCollectionOfDirectoryNames. If the first component is the name of the |
|
474 |
root directory (i.e. '/') an absolute path-filename is returned." |
|
475 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
476 |
self isAbstract ifTrue:[ |
24017 | 477 |
^ ConcreteClass fromComponents:aCollectionOfDirectoryNames |
3959 | 478 |
]. |
479 |
||
6802 | 480 |
^ self named:(self nameFromComponents:aCollectionOfDirectoryNames) |
3959 | 481 |
|
482 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
483 |
Filename fromComponents:#('/' 'foo' 'bar' 'baz') |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
484 |
PCFilename fromComponents:#('/' 'foo' 'bar' 'baz') |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
485 |
UnixFilename fromComponents:#('/' 'foo' 'bar' 'baz') |
8754 | 486 |
OpenVMSFilename fromComponents:#('foo' 'bar' 'baz') |
487 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
488 |
Filename fromComponents:#('foo' 'bar' 'baz') |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
489 |
Filename fromComponents:#('/') |
3959 | 490 |
|
491 |
Filename fromComponents: |
|
24017 | 492 |
(Filename components:('.' asFilename pathName)) |
3959 | 493 |
|
494 |
Filename fromComponents: |
|
24017 | 495 |
(Filename components:('.' asFilename name)) |
3959 | 496 |
" |
497 |
||
498 |
"Modified: 8.9.1997 / 00:23:16 / cg" |
|
499 |
! |
|
500 |
||
501 |
fromUser |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
502 |
"show a box to enter a filename. |
3959 | 503 |
Return a filename instance or nil (if cancel was pressed)." |
504 |
||
505 |
|name| |
|
506 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
507 |
name := Dialog |
24017 | 508 |
requestFileName:'filename:' |
509 |
default:nil |
|
510 |
fromDirectory:(FileSelectionBox lastFileSelectionDirectory). |
|
8738 | 511 |
|
512 |
name notEmptyOrNil ifTrue:[ |
|
24017 | 513 |
^ self named:name |
3978
b2babde0857b
use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents:
3959
diff
changeset
|
514 |
]. |
3959 | 515 |
^ nil |
516 |
||
517 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
518 |
Filename fromUser |
3959 | 519 |
" |
520 |
||
521 |
"Modified: 19.4.1996 / 13:57:44 / cg" |
|
522 |
! |
|
523 |
||
524 |
homeDirectory |
|
525 |
"return your homeDirectory. |
|
526 |
Some OperatingSystems do not support this - on those, the defaultDirectory |
|
17113 | 527 |
(which is the currentDirectory) is returned. |
528 |
Notice: services under windows also do not have a home directory." |
|
3959 | 529 |
|
530 |
|s| |
|
531 |
||
532 |
s := OperatingSystem getHomeDirectory. |
|
533 |
s isNil ifTrue:[ |
|
24017 | 534 |
^ self defaultDirectory |
3959 | 535 |
]. |
536 |
^ self named:s |
|
537 |
||
538 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
539 |
Filename homeDirectory |
3959 | 540 |
" |
541 |
||
542 |
"Modified: 8.9.1997 / 00:25:23 / cg" |
|
543 |
! |
|
544 |
||
545 |
named:aString |
|
546 |
"return a filename for a directory named aString. |
|
547 |
This is the same as 'aString asFilename'." |
|
548 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
549 |
self isAbstract ifTrue:[ |
24017 | 550 |
^ ConcreteClass named:aString |
3959 | 551 |
]. |
8738 | 552 |
^ self basicNew setName:aString |
3959 | 553 |
|
554 |
" |
|
555 |
Filename named:'/tmp/fooBar' |
|
556 |
" |
|
557 |
||
558 |
"Modified: 7.9.1997 / 23:30:06 / cg" |
|
559 |
! |
|
560 |
||
561 |
newTemporary |
|
562 |
"return a new unique filename - use this for temporary files. |
|
563 |
The filenames returned are '/tmp/stxtmp_xx_nn' where xx is our |
|
564 |
unix process id, and nn is a unique number, incremented with every |
|
565 |
call to this method. |
|
23043 | 566 |
If any of the environment variables STX_TMPDIR, ST_TMPDIR, TMPDIR is set, |
4757 | 567 |
its value defines the temp directory. |
568 |
Notice, that no file is created by this - only a unique name |
|
15459 | 569 |
is generated. |
570 |
||
16787 | 571 |
DO NOT USE THIS FOR PLAIN FILES - IT IS UNSECURE use FileStream>>#newTemporary |
572 |
(the insecurity is due to a small chance for some other program to open/create |
|
573 |
the file, as only a name is generated here. However, chances are small as the name |
|
574 |
is reasonably random - but for security relevant applications, this may be relevant) |
|
575 |
" |
|
3959 | 576 |
|
9912 | 577 |
^ self newTemporaryIn:(self tempDirectory) |
3959 | 578 |
|
579 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
580 |
Filename newTemporary |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
581 |
Filename newTemporary |
3959 | 582 |
" |
583 |
||
23043 | 584 |
"Modified: / 07-09-1995 / 10:48:31 / claus" |
585 |
"Modified: / 07-03-1996 / 14:51:33 / cg" |
|
586 |
"Modified (comment): / 31-05-2018 / 09:57:58 / Claus Gittinger" |
|
3959 | 587 |
! |
588 |
||
9912 | 589 |
newTemporaryDirectory |
590 |
"return a new unique temporary directory - use this for temporary files. |
|
591 |
The directories returned are '/tmp/stxtmp_xx_nn' where xx is our |
|
592 |
unix process id, and nn is a unique number, incremented with every |
|
593 |
call to this method. |
|
23043 | 594 |
If any of the environment variables STX_TMPDIR, ST_TMPDIR, TMPDIR is set, |
9912 | 595 |
its value defines the temp directory." |
596 |
||
597 |
^ self newTemporaryDirectoryIn:(self tempDirectory) |
|
23043 | 598 |
|
599 |
"Modified (comment): / 31-05-2018 / 09:57:54 / Claus Gittinger" |
|
9912 | 600 |
! |
601 |
||
602 |
newTemporaryDirectoryIn:aDirectoryOrNil |
|
603 |
"return a new unique temporary directory in another directory, or the current dir. |
|
604 |
Use this for temporary files. |
|
605 |
The directories returned are '/tmp/stxtmp_xx_nn' where xx is our |
|
606 |
unix process id, and nn is a unique number, incremented with every |
|
607 |
call to this method. |
|
23043 | 608 |
If any of the environment variables STX_TMPDIR, ST_TMPDIR, TMPDIR... is set, |
9912 | 609 |
its value defines the temp directory." |
610 |
||
611 |
|tempdir| |
|
612 |
||
15811 | 613 |
tempdir := self newTemporaryIn:aDirectoryOrNil. |
9912 | 614 |
tempdir exists ifTrue:[ |
23043 | 615 |
tempdir recursiveRemove. |
9912 | 616 |
]. |
617 |
tempdir makeDirectory. |
|
618 |
^ tempdir |
|
23043 | 619 |
|
620 |
"Modified (comment): / 31-05-2018 / 09:57:49 / Claus Gittinger" |
|
9912 | 621 |
! |
622 |
||
623 |
newTemporaryIn:aDirectoryOrNil |
|
3959 | 624 |
"return a new unique filename - use this for temporary files. |
625 |
The filenames returned are in aDirectoryPrefix and named 'stxtmp_xx_nn', |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
626 |
where xx is our unix process id, and nn is a unique number, incremented |
3959 | 627 |
with every call to this method. |
628 |
Notice: only a unique filename object is created and returned - no physical |
|
629 |
file is created by this method (i.e. you have to send #writeStream or |
|
630 |
whatever to it in order to really create something). |
|
15459 | 631 |
See also: #newTemporary which looks for a good temp directory. |
632 |
||
633 |
DO NOT USE THIS FOR PLAIN FILES - IT IS UNSECURE use FileStream>>#newTemporaryIn:" |
|
3959 | 634 |
|
12617 | 635 |
^ self newTemporaryIn:aDirectoryOrNil nameTemplate:(self tempFileNameTemplate) |
3959 | 636 |
|
637 |
"temp files in '/tmp': |
|
638 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
639 |
Filename newTemporary |
19665 | 640 |
Filename newTemporaryIn:(Filename tempDirectory) |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
641 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
642 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
643 |
"temp files somewhere |
3959 | 644 |
(not recommended - use above since it can be controlled via shell variables): |
645 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
646 |
UnixFilename newTemporaryIn:'/tmp' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
647 |
UnixFilename newTemporaryIn:'/tmp' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
648 |
UnixFilename newTemporaryIn:'/usr/tmp' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
649 |
UnixFilename newTemporaryIn:'/' |
3959 | 650 |
" |
651 |
||
652 |
"a local temp file: |
|
653 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
654 |
Filename newTemporaryIn:'' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
655 |
Filename newTemporaryIn:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
656 |
Filename newTemporaryIn:'.' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
657 |
Filename newTemporaryIn:('source' asFilename) |
3959 | 658 |
" |
659 |
||
660 |
"Modified: / 7.9.1995 / 10:48:31 / claus" |
|
661 |
"Modified: / 11.8.1998 / 22:51:43 / cg" |
|
662 |
! |
|
663 |
||
9912 | 664 |
newTemporaryIn:aDirectoryOrNil nameTemplate:template |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
665 |
"return a new unique filename - use this for temporary files. |
9912 | 666 |
The filenames returned are in aDirectoryOrNil and named after the given template, |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
667 |
in which %1 and %2 are expanded to the unix process id, and a unique number, incremented |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
668 |
with every call to this method respectively. |
19665 | 669 |
If the template does not contain %-meta characters, and the file already exists, |
670 |
a sequence of _1, _2,... is appended to the name. This is dangerous, as it does not prevent race |
|
671 |
conditions (if two such files are created at the same time). |
|
672 |
||
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
673 |
Notice: only a unique filename object is created and returned - no physical |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
674 |
file is created by this method (i.e. you have to send #writeStream or |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
675 |
whatever to it in order to really create something). |
15459 | 676 |
See also: #newTemporary which looks for a good temp directory. |
677 |
||
678 |
DO NOT USE THIS FOR PLAIN FILES - IT IS UNSECURE use FileStream>>#newTemporaryIn:nameTemplate:" |
|
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
679 |
|
19665 | 680 |
|newTempFilename oldNameString nextSeqNr| |
8738 | 681 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
682 |
self isAbstract ifTrue:[ |
19665 | 683 |
^ ConcreteClass newTemporaryIn:aDirectoryOrNil nameTemplate:template |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
684 |
]. |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
685 |
|
8738 | 686 |
"although the above allows things to be redefined in concrete classes, |
687 |
the following should work on all systems ..." |
|
688 |
||
689 |
[ |
|
19665 | 690 |
|nameString fn| |
691 |
||
692 |
"Use random numbers in order to improve the security |
|
693 |
by making the generated names less predictable" |
|
694 |
nameString := template bindWith:(OperatingSystem getProcessId) with:(RandomGenerator nextLettersOrDigits:4). |
|
695 |
(oldNameString = nameString) ifTrue:[ |
|
696 |
"/ ouch - the given template seems to not generate unique file names. |
|
697 |
"/ append a sequence number |
|
698 |
nextSeqNr := (nextSeqNr ? 0) + 1. |
|
699 |
fn := nameString asFilename. |
|
700 |
nameString := fn withoutSuffix name,'_',nextSeqNr asString,'.' , fn suffix. |
|
701 |
]. |
|
702 |
||
703 |
aDirectoryOrNil isNil ifTrue:[ |
|
704 |
newTempFilename := self named:nameString |
|
705 |
] ifFalse:[ |
|
23664 | 706 |
"do not use #construct - I might be an AutoDeletedFilename!!" |
707 |
newTempFilename := aDirectoryOrNil asFilename constructString:nameString. |
|
708 |
newTempFilename := self named:newTempFilename. |
|
19665 | 709 |
]. |
710 |
oldNameString := nameString. |
|
8738 | 711 |
] doWhile:[ |
19665 | 712 |
"care for existing leftOver tempFiles |
713 |
from a previous boot of the OS |
|
714 |
i.e. my pid could be the same as when executed |
|
715 |
the last time before system reboot ...)" |
|
716 |
||
717 |
newTempFilename exists |
|
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
718 |
]. |
8738 | 719 |
^ newTempFilename |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
720 |
|
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
721 |
"temp files in '/tmp': |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
722 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
723 |
Filename newTemporary |
19665 | 724 |
Filename newTemporaryIn:nil nameTemplate:'out_%1_%2.txt' |
725 |
Filename newTemporaryIn:(Filename tempDirectory) nameTemplate:'out_%1_%2.txt' |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
726 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
727 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
728 |
"temp files somewhere |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
729 |
(not recommended - use above since it can be controlled via shell variables): |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
730 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
731 |
UnixFilename newTemporaryIn:'/tmp' nameTemplate:'foo%1_%2' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
732 |
UnixFilename newTemporaryIn:'/tmp' nameTemplate:'foo%1_%2' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
733 |
UnixFilename newTemporaryIn:'/usr/tmp' nameTemplate:'foo%1_%2' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
734 |
UnixFilename newTemporaryIn:'/' nameTemplate:'foo%1_%2' |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
735 |
" |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
736 |
|
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
737 |
"a local temp file: |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
738 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
739 |
Filename newTemporaryIn:'' nameTemplate:'foo%1_%2' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
740 |
Filename newTemporaryIn:nil nameTemplate:'foo%1_%2' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
741 |
Filename newTemporaryIn:'.' nameTemplate:'foo%1_%2' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
742 |
Filename newTemporaryIn:('source' asFilename) nameTemplate:'foo%1_%2' |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
743 |
" |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
744 |
|
12918
a9de9243a951
changed: #newTemporaryIn:nameTemplate:
Claus Gittinger <cg@exept.de>
parents:
12910
diff
changeset
|
745 |
"Modified: / 07-09-1995 / 10:48:31 / claus" |
a9de9243a951
changed: #newTemporaryIn:nameTemplate:
Claus Gittinger <cg@exept.de>
parents:
12910
diff
changeset
|
746 |
"Modified: / 07-05-2010 / 11:46:05 / cg" |
23664 | 747 |
"Modified: / 06-02-2019 / 10:44:21 / Stefan Vogel" |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
748 |
! |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
749 |
|
4199 | 750 |
nullDevice |
751 |
"return the filename of the nullDevice (if available). |
|
752 |
returns nil, if the OperatingSystem does not support this." |
|
753 |
||
754 |
|s| |
|
755 |
||
8754 | 756 |
s := self nullFilename. |
4199 | 757 |
s isNil ifTrue:[ |
24017 | 758 |
^ nil |
4199 | 759 |
]. |
760 |
^ self named:s |
|
761 |
||
762 |
" |
|
8754 | 763 |
Filename nullDevice |
764 |
UnixFilename nullDevice |
|
765 |
PCFilename nullDevice |
|
4199 | 766 |
" |
767 |
||
768 |
"Created: / 19.5.1999 / 12:24:26 / cg" |
|
769 |
! |
|
770 |
||
6256 | 771 |
remoteHost:remoteHostString rootComponents:aCollectionOfDirectoryNames |
772 |
"create & return a new filename from components given in |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
773 |
aCollectionOfDirectoryNames on a host named remoteHostString. |
6256 | 774 |
An absolute network-filename is returned." |
775 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
776 |
self isAbstract ifTrue:[ |
24017 | 777 |
^ ConcreteClass remoteHost:remoteHostString |
778 |
rootComponents:aCollectionOfDirectoryNames |
|
6256 | 779 |
]. |
780 |
||
10390 | 781 |
remoteHostString notEmptyOrNil ifTrue:[ |
24017 | 782 |
self error:'remote hosts are not supported by OS' |
10390 | 783 |
]. |
784 |
||
785 |
^ self rootComponents:aCollectionOfDirectoryNames |
|
786 |
||
787 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
788 |
'file:///tmp/test' asURI asFilename |
10390 | 789 |
" |
6256 | 790 |
! |
791 |
||
792 |
rootComponents:aCollectionOfDirectoryNames |
|
793 |
"create & return a new filename from components given in |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
794 |
aCollectionOfDirectoryNames. |
6256 | 795 |
An absolute path-filename is returned." |
796 |
||
797 |
|sep s| |
|
798 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
799 |
self isAbstract ifTrue:[ |
24017 | 800 |
^ ConcreteClass rootComponents:aCollectionOfDirectoryNames |
6256 | 801 |
]. |
802 |
||
803 |
"/ fallBack - works on Unix & MSDOS |
|
804 |
||
8243 | 805 |
sep := self separatorString. |
18272 | 806 |
s := CharacterWriteStream new. |
6256 | 807 |
aCollectionOfDirectoryNames do:[:component | |
24017 | 808 |
component ~= sep ifTrue:[ |
809 |
s nextPutAll:sep; nextPutAll:component |
|
810 |
] |
|
6256 | 811 |
]. |
812 |
s := s contents. |
|
813 |
s size == 0 ifTrue:[s := sep]. |
|
814 |
^ self named:s |
|
815 |
||
816 |
" |
|
8754 | 817 |
Filename rootComponents:#('/' 'foo' 'bar' 'baz') |
818 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
819 |
Filename rootComponents:#('foo' 'bar' 'baz') |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
820 |
PCFilename rootComponents:#('foo' 'bar' 'baz') |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
821 |
UnixFilename rootComponents:#('foo' 'bar' 'baz') |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
822 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
823 |
Filename rootComponents:#('/') |
6256 | 824 |
|
825 |
Filename rootComponents: |
|
24017 | 826 |
(Filename components:('.' asFilename pathName)) |
6256 | 827 |
|
828 |
Filename rootComponents: |
|
24017 | 829 |
(Filename components:('.' asFilename name)) |
6256 | 830 |
" |
831 |
||
832 |
"Modified: 8.9.1997 / 00:23:16 / cg" |
|
833 |
! |
|
834 |
||
3959 | 835 |
rootDirectory |
836 |
"return a filename for the root directory" |
|
837 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
838 |
self isAbstract ifTrue:[ |
24017 | 839 |
^ ConcreteClass rootDirectory |
3959 | 840 |
]. |
841 |
||
842 |
"/ fallBack - works on Unix & MSDOS (but not on VMS) |
|
843 |
||
8243 | 844 |
^ self named:(self separatorString) |
3959 | 845 |
|
846 |
" |
|
847 |
Filename rootDirectory |
|
848 |
" |
|
849 |
||
850 |
"Modified: 8.9.1997 / 00:24:15 / cg" |
|
851 |
! |
|
852 |
||
853 |
rootDirectoryOnVolume:aVolumeName |
|
854 |
"return a filename for the root directory on some volume" |
|
855 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
856 |
self isAbstract ifTrue:[ |
24017 | 857 |
^ ConcreteClass rootDirectoryOnVolume:aVolumeName |
3959 | 858 |
]. |
859 |
||
860 |
"/ fallBack - works on Unix (not on MSDOS or VMS) |
|
861 |
||
862 |
^ self rootDirectory |
|
863 |
||
864 |
" |
|
865 |
Filename rootDirectoryOnVolume:'/phys/idefix' |
|
866 |
Filename rootDirectoryOnVolume:'d:' |
|
867 |
" |
|
868 |
||
869 |
"Modified: / 5.10.1998 / 12:45:39 / cg" |
|
870 |
! |
|
871 |
||
872 |
tempDirectory |
|
873 |
"return the temp directory as a filename. |
|
23043 | 874 |
If any of the environment variables STX_TMPDIR, ST_TMPDIR, TMPDIR,... |
875 |
is set, its value defines the name, |
|
3959 | 876 |
otherwise, '/tmp' is used. (at least on unix ...). |
877 |
||
878 |
Notice: do not hardcode '/tmp' into your programs - things may be |
|
23043 | 879 |
different on other operating systems. Also, the user may want to set the |
880 |
TMPDIR environment variable to have her temp files somewhere else." |
|
3959 | 881 |
|
882 |
|tempDir| |
|
883 |
||
9806 | 884 |
TempDirectory isNil ifTrue:[ |
23043 | 885 |
tempDir := self named:(self defaultTempDirectoryName pathName). |
886 |
tempDir exists ifFalse:[ |
|
887 |
tempDir |
|
888 |
makeDirectory; |
|
889 |
addAccessRights:#(readUser readGroup readOthers |
|
890 |
writeUser writeGroup writeOthers |
|
891 |
executeUser executeGroup executeOthers |
|
892 |
removeOnlyByOwner). |
|
893 |
]. |
|
894 |
TempDirectory := DefaultTempDirectory := tempDir construct:'stx_tmp'. |
|
3959 | 895 |
]. |
10551
4924bf1ce2e3
#tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents:
10546
diff
changeset
|
896 |
|
4924bf1ce2e3
#tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents:
10546
diff
changeset
|
897 |
"Make sure, that the TempDirectory exists - it might have been removed |
10663
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
898 |
by a cleanup (cron) job. |
19114 | 899 |
Since it is shared between users, it must be accessible by all users." |
10551
4924bf1ce2e3
#tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents:
10546
diff
changeset
|
900 |
|
4924bf1ce2e3
#tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents:
10546
diff
changeset
|
901 |
TempDirectory exists ifFalse:[ |
23043 | 902 |
TempDirectory |
903 |
makeDirectory; |
|
904 |
addAccessRights:#(readUser readGroup readOthers |
|
905 |
writeUser writeGroup writeOthers |
|
906 |
executeUser executeGroup executeOthers |
|
907 |
removeOnlyByOwner). |
|
10551
4924bf1ce2e3
#tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents:
10546
diff
changeset
|
908 |
]. |
9806 | 909 |
^ TempDirectory |
3959 | 910 |
|
911 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
912 |
Filename tempDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
913 |
Filename tempDirectory pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
914 |
Filename tempDirectory exists |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
915 |
Filename tempDirectory isWritable |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
916 |
(Filename tempDirectory construct:'foo') makeDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
917 |
(Filename tempDirectory construct:'foo') remove |
3959 | 918 |
" |
919 |
||
9806 | 920 |
"Created: / 07-03-1996 / 14:51:18 / cg" |
13781 | 921 |
"Modified: / 07-10-2011 / 18:39:25 / cg" |
23043 | 922 |
"Modified (comment): / 31-05-2018 / 09:58:23 / Claus Gittinger" |
11757
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
923 |
! |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
924 |
|
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
925 |
tempDirectory:aFilename |
17048 | 926 |
"set the default temporary directory. |
927 |
This allows overwriting the automatically determined tmpDirectory |
|
928 |
by a knowledgable stand alone startup program. |
|
19114 | 929 |
Do not use elsewhere (and only if absolutely required)" |
11757
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
930 |
|
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
931 |
|temp| |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
932 |
|
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
933 |
aFilename isNil ifTrue:[ |
24017 | 934 |
TempDirectory := nil. |
935 |
^ self. |
|
11757
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
936 |
]. |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
937 |
|
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
938 |
temp := aFilename asFilename. |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
939 |
self assert:temp isDirectory. |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
940 |
TempDirectory := temp. |
16382 | 941 |
! |
942 |
||
943 |
trashDirectoryOrNil |
|
944 |
"if the underlying OS uses/supports a trash folder, |
|
945 |
return it. Otherwise return nil. |
|
946 |
Asks the OS for the pathname; for example, on OSX, '~/.Trash' is returned." |
|
947 |
||
948 |
|s| |
|
949 |
||
950 |
s := OperatingSystem getTrashDirectory. |
|
951 |
s isNil ifTrue:[ |
|
24017 | 952 |
^ nil |
16382 | 953 |
]. |
954 |
^ self named:s |
|
955 |
||
956 |
" |
|
24049 | 957 |
Filename trashDirectoryOrNil |
16382 | 958 |
" |
959 |
||
960 |
"Created: / 16-05-2007 / 13:18:34 / cg" |
|
24049 | 961 |
"Modified (comment): / 10-04-2019 / 05:51:00 / Claus Gittinger" |
16648 | 962 |
! |
963 |
||
964 |
usersPrivateSmalltalkDirectory |
|
965 |
^ Filename homeDirectory / '.smalltalk' |
|
966 |
||
967 |
" |
|
968 |
Filename usersPrivateSmalltalkDirectory |
|
969 |
" |
|
3959 | 970 |
! ! |
971 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
972 |
!Filename class methodsFor:'defaults'! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
973 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
974 |
concreteClass |
6256 | 975 |
"different subclasses of Filename are used for different |
976 |
OperatingSystems; concreteClass is supposed to return an appropriate class." |
|
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
977 |
|
2906 | 978 |
^ ConcreteClass ? self |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
979 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
980 |
"Created: 14.2.1997 / 16:36:13 / cg" |
2906 | 981 |
"Modified: 7.9.1997 / 23:29:20 / cg" |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
982 |
! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
983 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
984 |
defaultClass |
6256 | 985 |
"different subclasses of Filename are used for different |
986 |
OperatingSystems; defaultClass is supposed to return an appropriate class" |
|
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
987 |
|
2906 | 988 |
^ ConcreteClass |
989 |
||
990 |
"Modified: 8.9.1997 / 00:36:01 / cg" |
|
7836 | 991 |
! |
992 |
||
993 |
defaultTempDirectoryName |
|
994 |
"return the default temp directory as a filename. |
|
995 |
This is used, if no special preferences were defined in |
|
996 |
any of the TEMP-environment variables (see tempDirectory)." |
|
997 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
998 |
self isAbstract ifTrue:[ |
24017 | 999 |
^ ConcreteClass defaultTempDirectoryName |
7836 | 1000 |
]. |
1001 |
||
10994
1a3776d0b845
always return a fileName from defaultTempDirectoryName
fm
parents:
10969
diff
changeset
|
1002 |
^ '/tmp' asFilename |
7836 | 1003 |
|
1004 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1005 |
Filename defaultTempDirectoryName |
7836 | 1006 |
" |
1007 |
||
1008 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
|
1009 |
"Created: 7.3.1996 / 14:51:18 / cg" |
|
1010 |
"Modified: 8.9.1997 / 00:24:53 / cg" |
|
19599 | 1011 |
! |
1012 |
||
1013 |
defaultVolumeName |
|
1014 |
^ '/' |
|
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1015 |
! ! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1016 |
|
2922 | 1017 |
!Filename class methodsFor:'misc'! |
1018 |
||
3077 | 1019 |
filterSeps:aFilenameString |
1020 |
"ST80 compatibility: |
|
1021 |
filter out (invalid) separators in aFilenameString. |
|
1022 |
We recommend using #makeLegalFilename" |
|
1023 |
||
16762 | 1024 |
^ aFilenameString copyReplaceAll:(Character space) with:$_ ifNone:aFilenameString. |
3077 | 1025 |
|
1026 |
"Created: / 1.11.1997 / 12:39:50 / cg" |
|
3658 | 1027 |
"Modified: / 18.7.1998 / 22:53:24 / cg" |
3077 | 1028 |
! |
1029 |
||
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1030 |
nameWithSpecialExpansions:aString |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1031 |
"return the nameString, expanding any OS specific macros. |
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1032 |
Here, a ~/ or ~user/ prefix is expanded to the users home dir (as in csh)" |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1033 |
|
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1034 |
|dir user cutIdx idx userInfo| |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1035 |
|
23623 | 1036 |
self isAbstract ifTrue:[ |
1037 |
^ ConcreteClass nameWithSpecialExpansions:aString |
|
1038 |
]. |
|
1039 |
||
1040 |
||
19670 | 1041 |
(aString startsWith:$~) ifFalse:[ |
1042 |
^ aString. |
|
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1043 |
]. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1044 |
|
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1045 |
aString size > 1 ifTrue:[ |
19670 | 1046 |
idx := aString indexOf:self separator. |
1047 |
idx == 0 ifTrue:[ |
|
1048 |
"aString is '~user'" |
|
1049 |
user := aString copyFrom:2. |
|
1050 |
cutIdx := aString size + 1. |
|
1051 |
] ifFalse:[ |
|
1052 |
"aString is '~user/something'" |
|
1053 |
user := aString copyFrom:2 to:(idx - 1). |
|
1054 |
cutIdx := idx. |
|
1055 |
]. |
|
1056 |
user notEmpty ifTrue:[ |
|
1057 |
userInfo := OperatingSystem userInfoOf:user. |
|
1058 |
userInfo notNil ifTrue:[ |
|
1059 |
dir := userInfo at:#dir ifAbsent:nil. |
|
1060 |
]. |
|
1061 |
dir isNil ifTrue:[ |
|
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1062 |
"/ ('Filename [info]: unknown user: ' , user) infoPrintCR. |
19670 | 1063 |
^ aString |
1064 |
]. |
|
1065 |
]. |
|
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1066 |
]. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1067 |
dir isNil ifTrue:[ |
19670 | 1068 |
"aString is '~' or '~/'" |
1069 |
dir := OperatingSystem getHomeDirectory. |
|
1070 |
cutIdx := 2. |
|
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1071 |
]. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1072 |
|
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1073 |
^ dir , (aString copyFrom:cutIdx) |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1074 |
|
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1075 |
" |
20709 | 1076 |
Filename nameWithSpecialExpansions:'~' |
1077 |
Filename nameWithSpecialExpansions:'~\work' |
|
1078 |
Filename nameWithSpecialExpansions:'~stefan' |
|
1079 |
Filename nameWithSpecialExpansions:'~stefan\work' |
|
1080 |
Filename nameWithSpecialExpansions:'~foo' |
|
1081 |
Filename nameWithSpecialExpansions:'~foo\bar' |
|
1082 |
" |
|
1083 |
||
1084 |
" |
|
1085 |
UnixFilename nameWithSpecialExpansions:'~' |
|
1086 |
UnixFilename nameWithSpecialExpansions:'~/work' |
|
1087 |
UnixFilename nameWithSpecialExpansions:'~stefan' |
|
1088 |
UnixFilename nameWithSpecialExpansions:'~stefan/work' |
|
1089 |
UnixFilename nameWithSpecialExpansions:'~foo' |
|
1090 |
UnixFilename nameWithSpecialExpansions:'~foo/bar' |
|
1091 |
" |
|
1092 |
||
1093 |
" |
|
1094 |
PCFilename nameWithSpecialExpansions:'~' |
|
1095 |
PCFilename nameWithSpecialExpansions:'~\work' |
|
1096 |
PCFilename nameWithSpecialExpansions:'~stefan' |
|
1097 |
PCFilename nameWithSpecialExpansions:'~stefan\work' |
|
1098 |
PCFilename nameWithSpecialExpansions:'~foo' |
|
1099 |
PCFilename nameWithSpecialExpansions:'~foo\bar' |
|
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1100 |
" |
23623 | 1101 |
|
1102 |
"Modified: / 21-01-2019 / 16:26:56 / Stefan Vogel" |
|
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1103 |
! |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1104 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1105 |
suggest:aFilenameString |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1106 |
"return a fileNamestring based on the argument, |
3077 | 1107 |
which is legal on the current platform." |
1108 |
||
1109 |
^ self canonicalize:aFilenameString |
|
1110 |
||
1111 |
"Created: / 1.11.1997 / 12:42:39 / cg" |
|
2922 | 1112 |
! ! |
1113 |
||
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1114 |
!Filename class methodsFor:'queries'! |
2 | 1115 |
|
10663
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1116 |
currentDirectoryName |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1117 |
"return a filename for the current directory" |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1118 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1119 |
self isAbstract ifTrue:[ |
24017 | 1120 |
^ ConcreteClass currentDirectoryName |
10663
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1121 |
]. |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1122 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1123 |
"/ fallBack - works on Unix & MSDOS (but not on VMS) |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1124 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1125 |
^ '.' |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1126 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1127 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1128 |
Filename currentDirectoryName |
10663
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1129 |
" |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1130 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1131 |
"Modified: / 8.9.1997 / 00:24:15 / cg" |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1132 |
"Created: / 21.10.1998 / 17:49:57 / cg" |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1133 |
! |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1134 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1135 |
defaultDirectoryName |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1136 |
"ST80 compatibility: return the defaultDirectories name (as a string)" |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1137 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1138 |
^ self defaultDirectory name |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1139 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1140 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1141 |
Filename defaultDirectoryName |
10663
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1142 |
" |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1143 |
! |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1144 |
|
2963 | 1145 |
directorySuffix |
1146 |
"Return the OS dependent directory suffix string, or nil if there is none. |
|
1147 |
The default is nil here, redefined for VMS" |
|
1148 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1149 |
self isAbstract ifTrue:[ |
24017 | 1150 |
^ ConcreteClass directorySuffix |
2963 | 1151 |
]. |
1152 |
||
1153 |
^ nil |
|
1154 |
! |
|
1155 |
||
1523 | 1156 |
errorReporter |
1157 |
"who knows the signals to report errors?" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1158 |
|
1523 | 1159 |
^ FileStream |
1160 |
||
1161 |
"Created: 2.7.1996 / 12:30:25 / stefan" |
|
1162 |
! |
|
1163 |
||
440 | 1164 |
filenameCompletionFor:aString directory:inDirectory directoriesOnly:directoriesOnly filesOnly:filesOnly ifMultiple:aBlock |
1165 |
"perform filename completion on aString in some directory; |
|
1166 |
return the longest matching filename prefix as a string. |
|
1318 | 1167 |
The boolean directoriesOnly and filesOnly control respectively, |
1168 |
if only directories or only regular files are to be considered for completion. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1169 |
If multiple files match, the exception block aBlock is evaluated with a |
1318 | 1170 |
filename representing the directory (where the match was done) as argument. |
440 | 1171 |
(this may be different from the inDirectory argument, if aString is absolute |
1172 |
or starts with ../)" |
|
1173 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1174 |
self isAbstract ifTrue:[ |
23837 | 1175 |
^ ConcreteClass |
1176 |
filenameCompletionFor:aString |
|
1177 |
directory:inDirectory |
|
1178 |
directoriesOnly:directoriesOnly |
|
1179 |
filesOnly:filesOnly |
|
1180 |
ifMultiple:aBlock |
|
1181 |
]. |
|
1182 |
^ self |
|
1183 |
filenameCompletionFor:aString |
|
1184 |
directory:inDirectory |
|
1185 |
directoriesOnly:directoriesOnly |
|
1186 |
filesOnly:filesOnly |
|
1187 |
ifMultiple:aBlock |
|
1188 |
forMultipleDo:nil |
|
1189 |
||
1190 |
" |
|
1191 |
self |
|
1192 |
filenameCompletionFor:'/tm' |
|
1193 |
directory:nil |
|
1194 |
directoriesOnly:true |
|
1195 |
filesOnly:false |
|
1196 |
ifMultiple:[] |
|
1197 |
" |
|
1198 |
||
1199 |
"Modified (comment): / 04-03-2019 / 15:43:52 / Claus Gittinger" |
|
6839
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1200 |
! |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1201 |
|
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1202 |
filenameCompletionFor:aString directory:inDirectory directoriesOnly:directoriesOnly filesOnly:filesOnly ifMultiple:aBlock forMultipleDo:aMultipleBlock |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1203 |
"perform filename completion on aString in some directory; |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1204 |
return the longest matching filename prefix as a string. |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1205 |
The boolean directoriesOnly and filesOnly control respectively, |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1206 |
if only directories or only regular files are to be considered for completion. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1207 |
If multiple files match, the exception block aBlock is evaluated with a |
6839
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1208 |
filename representing the directory (where the match was done) as argument and the aMultipleBlock |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1209 |
is evaluated with both the directory (where the match was done) and the matchSet |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1210 |
(list of matched filenames) as arguments. |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1211 |
(this may be different from the inDirectory argument, if aString is absolute |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1212 |
or starts with ../)" |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1213 |
|
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1214 |
|s f matchSet nMatch name dir isAbsolute sep| |
2906 | 1215 |
|
5642
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1216 |
aString size == 0 ifTrue:[ |
24017 | 1217 |
aBlock value:(self named:'.'). |
1218 |
^ '' |
|
440 | 1219 |
]. |
1220 |
||
5642
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1221 |
sep := self separator. |
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1222 |
|
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1223 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1224 |
|
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1225 |
f := self named:aString. |
3854
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
1226 |
isAbsolute := f isAbsolute. |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1227 |
matchSet := f filenameCompletionIn:inDirectory. "/ BAD DESIGN: has side effect on f |
440 | 1228 |
dir := f directory. |
1229 |
||
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
1230 |
matchSet := matchSet select:[:aFilename | |
24017 | 1231 |
|f isDir| |
1232 |
||
1233 |
isAbsolute ifTrue:[ |
|
1234 |
f := aFilename asFilename |
|
1235 |
] ifFalse:[ |
|
1236 |
f := (dir construct:aFilename). |
|
1237 |
]. |
|
1238 |
isDir := f isDirectory. |
|
1239 |
directoriesOnly ifTrue:[ |
|
1240 |
isDir |
|
1241 |
] ifFalse:[ |
|
1242 |
filesOnly ifTrue:[ |
|
1243 |
isDir not |
|
1244 |
] ifFalse:[ |
|
1245 |
true |
|
1246 |
] |
|
1247 |
] |
|
440 | 1248 |
]. |
1249 |
||
6803 | 1250 |
f := f asCanonicalizedFilename. |
24017 | 1251 |
(nMatch := matchSet size) ~~ 1 ifTrue:[ |
1252 |
" |
|
1253 |
more than one possible completion - |
|
1254 |
" |
|
1255 |
aMultipleBlock notNil ifTrue:[ |
|
1256 |
aMultipleBlock value:f value:matchSet. |
|
1257 |
]. |
|
1258 |
aBlock value:f |
|
440 | 1259 |
]. |
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
1260 |
|
440 | 1261 |
" |
1262 |
even with more than one possible completion, |
|
1263 |
f's name is now the common prefix |
|
1264 |
" |
|
1265 |
name := f asString. |
|
4323
8b3752e1b060
add trailing filename separator if match is a directory
Claus Gittinger <cg@exept.de>
parents:
4246
diff
changeset
|
1266 |
|
8b3752e1b060
add trailing filename separator if match is a directory
Claus Gittinger <cg@exept.de>
parents:
4246
diff
changeset
|
1267 |
nMatch <= 1 ifTrue:[ |
24017 | 1268 |
" |
1269 |
exactly one possible completion - |
|
1270 |
" |
|
3752 | 1271 |
"/ f := dir construct:matchSet first. |
24017 | 1272 |
false "directoriesOnly" ifFalse:[ |
1273 |
(f exists and:[f isDirectory]) ifTrue:[ |
|
1274 |
(name endsWith:sep) ifFalse:[ |
|
1275 |
name := name , sep asString |
|
1276 |
]. |
|
1277 |
]. |
|
1278 |
] |
|
440 | 1279 |
]. |
1280 |
||
5642
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1281 |
s := name. |
440 | 1282 |
|
1283 |
"/ special: if there was no change, and the string represented |
|
1284 |
"/ is a directories name, add a directory separator |
|
3503
0734014ecea8
apped '/' if there is exactly one match and its a directory
Claus Gittinger <cg@exept.de>
parents:
3373
diff
changeset
|
1285 |
((nMatch == 1) or:[s = aString]) ifTrue:[ |
24017 | 1286 |
(s endsWith:sep) ifFalse:[ |
1287 |
(self named:s) isDirectory ifTrue:[ |
|
1288 |
^ s , sep asString |
|
1289 |
] |
|
1290 |
]. |
|
440 | 1291 |
]. |
1292 |
||
1293 |
^ s |
|
1318 | 1294 |
|
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
1295 |
"Modified: / 30.4.1999 / 09:40:13 / cg" |
615 | 1296 |
! |
1297 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1298 |
filesMatching:aPattern |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1299 |
"return a collection of strings, representing the names |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1300 |
of files matching aPattern. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1301 |
If aPattern contains a directory path, files are tried there; |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1302 |
otherwise, files from the currentDirectory are tried. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1303 |
The returned strings are the expanded names, in the same form |
2550 | 1304 |
as given in pattern. |
1305 |
The pattern should be a simple pattern." |
|
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1306 |
|
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1307 |
|basePattern dir d files| |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1308 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1309 |
self isAbstract ifTrue:[ |
24017 | 1310 |
^ ConcreteClass filesMatching:aPattern |
2906 | 1311 |
]. |
1312 |
||
1313 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
|
1314 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1315 |
dir := aPattern asFilename directoryName. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1316 |
basePattern := aPattern asFilename baseName. |
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1317 |
d := dir asFilename. |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1318 |
files := dir asFilename filesMatchingWithoutDotDirs:basePattern. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1319 |
dir = '.' ifTrue:[^ files]. |
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1320 |
^ files collect:[:base | d constructString:base]. |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1321 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1322 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1323 |
Filename filesMatching:'*' |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1324 |
Filename filesMatching:'/*' |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1325 |
Filename filesMatching:'/usr/local/*' |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1326 |
" |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1327 |
|
2906 | 1328 |
"Modified: 8.9.1997 / 00:32:31 / cg" |
615 | 1329 |
! |
1330 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1331 |
isAbstract |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1332 |
"return true, if this is not a concrete class" |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1333 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1334 |
^ self == Filename |
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1335 |
! |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1336 |
|
2903 | 1337 |
isBadCharacter:aCharacter |
1338 |
"return true, if aCharacter is unallowed in a filename." |
|
1339 |
||
22127 | 1340 |
self isAbstract ifTrue:[ |
1341 |
^ ConcreteClass isBadCharacter:aCharacter |
|
2906 | 1342 |
]. |
1343 |
||
8095
bfbd1309a4a6
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
8036
diff
changeset
|
1344 |
^ aCharacter isControlCharacter |
22127 | 1345 |
|
1346 |
"Modified (format): / 27-07-2017 / 14:25:01 / stefan" |
|
2903 | 1347 |
! |
1348 |
||
1349 |
isCaseSensitive |
|
1350 |
"return true, if filenames are case sensitive. |
|
19821 | 1351 |
We ask the OS about this, to be independent here. |
1352 |
This is not really correct, as the sensitivity may depend on |
|
1353 |
the paricular mounted file system (NFS, for example). |
|
1354 |
So we need a query on the instance side" |
|
2903 | 1355 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1356 |
self isAbstract ifTrue:[ |
19821 | 1357 |
^ ConcreteClass isCaseSensitive |
2906 | 1358 |
]. |
1359 |
||
2903 | 1360 |
^ OperatingSystem caseSensitiveFilenames |
2906 | 1361 |
|
1362 |
"Modified: 8.9.1997 / 00:33:32 / cg" |
|
2903 | 1363 |
! |
1364 |
||
615 | 1365 |
localNameStringFrom:aString |
1366 |
"ST-80 compatibility. |
|
1367 |
what does this do ? (used in FileNavigator-goody). |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1368 |
GUESS: |
24017 | 1369 |
does it strip off any volume characters and make a path relative ?" |
2922 | 1370 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1371 |
self isAbstract ifTrue:[ |
24017 | 1372 |
^ ConcreteClass localNameStringFrom:aString |
2906 | 1373 |
]. |
1374 |
||
15227 | 1375 |
^ aString withoutPrefix:self separatorString |
615 | 1376 |
|
1377 |
"Modified: 7.9.1995 / 10:44:56 / claus" |
|
2906 | 1378 |
"Modified: 8.9.1997 / 00:33:51 / cg" |
615 | 1379 |
! |
1380 |
||
2908 | 1381 |
maxComponentLength |
1382 |
"return the maximum number of characters a filename component may |
|
1383 |
be in size. This depends on the OperatingSystem." |
|
1384 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1385 |
self isAbstract ifTrue:[ |
24017 | 1386 |
^ ConcreteClass maxComponentLength |
2908 | 1387 |
]. |
1388 |
^ OperatingSystem maxFileNameLength |
|
1389 |
! |
|
1390 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1391 |
maxLength |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1392 |
"return the maximum number of characters a filename may be in size. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1393 |
This depends on the OperatingSystem." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1394 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1395 |
self isAbstract ifTrue:[ |
24017 | 1396 |
^ ConcreteClass maxLength |
2908 | 1397 |
]. |
1398 |
^ OperatingSystem maxPathLength |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1399 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1400 |
"Created: 29.2.1996 / 20:57:11 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1401 |
"Modified: 29.2.1996 / 20:57:46 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1402 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1403 |
|
3171 | 1404 |
nullFilename |
1405 |
"Return the OS dependent filename for /dev/null, or nil if there is none. |
|
1406 |
The default is nil here" |
|
1407 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1408 |
self isAbstract ifTrue:[ |
24017 | 1409 |
^ ConcreteClass nullFilename |
3171 | 1410 |
]. |
1411 |
||
8754 | 1412 |
^ OperatingSystem getNullDevice |
3171 | 1413 |
|
1414 |
"Created: / 12.1.1998 / 12:15:30 / stefan" |
|
1415 |
! |
|
1416 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1417 |
parentDirectoryName |
615 | 1418 |
"return the name used for the parent directory. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1419 |
This is '..' for unix and dos-like systems. |
615 | 1420 |
(there may be more in the future." |
1421 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1422 |
self isAbstract ifTrue:[ |
24017 | 1423 |
^ ConcreteClass parentDirectoryName |
2906 | 1424 |
]. |
1425 |
||
1426 |
^ OperatingSystem parentDirectoryName |
|
1427 |
||
1428 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1429 |
Filename parentDirectoryName |
2906 | 1430 |
" |
1431 |
||
1432 |
"Modified: 8.9.1997 / 00:34:39 / cg" |
|
615 | 1433 |
! |
1434 |
||
1435 |
separator |
|
1436 |
"return the file/directory separator. |
|
15246 | 1437 |
This is to be redefined in concrete classes." |
1438 |
||
1439 |
^ ConcreteClass separator |
|
8243 | 1440 |
|
1441 |
" |
|
8754 | 1442 |
Filename separator |
1443 |
PCFilename separator |
|
8243 | 1444 |
" |
2906 | 1445 |
|
1446 |
"Modified: 8.9.1997 / 00:20:28 / cg" |
|
615 | 1447 |
! |
1448 |
||
8243 | 1449 |
separatorString |
1450 |
"return the file/directory separator as a string." |
|
1451 |
||
1452 |
^ self separator asString |
|
1453 |
||
1454 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1455 |
Filename separatorString |
8243 | 1456 |
" |
1457 |
! |
|
1458 |
||
615 | 1459 |
suffixSeparator |
1460 |
"return the filename suffix separator. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1461 |
Usually, this is $. for unix-like and msdos systems |
1318 | 1462 |
(there is currently no known system, where this differs)" |
615 | 1463 |
|
1464 |
^ $. |
|
1465 |
||
1466 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1467 |
Filename suffixSeparator |
615 | 1468 |
" |
1469 |
||
1470 |
"Modified: 7.9.1995 / 11:10:43 / claus" |
|
1318 | 1471 |
"Modified: 30.4.1996 / 12:14:25 / cg" |
615 | 1472 |
! |
1473 |
||
2906 | 1474 |
tempFileNameTemplate |
1475 |
"return a template for temporary files. |
|
1476 |
This is expanded with the current processID and a sequenceNumber |
|
1477 |
to generate a unique filename." |
|
1478 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1479 |
self isAbstract ifTrue:[ |
24017 | 1480 |
^ ConcreteClass tempFileNameTemplate |
2906 | 1481 |
]. |
1482 |
||
1483 |
^ 'stxtmp_%1_%2' |
|
1484 |
||
1485 |
"Created: 8.9.1997 / 00:01:46 / cg" |
|
1486 |
"Modified: 8.9.1997 / 00:35:02 / cg" |
|
1487 |
! |
|
1488 |
||
615 | 1489 |
volumes |
1490 |
"ST-80 compatibility. |
|
2896 | 1491 |
GUESS: does it return the available drives on MSDOS systems ? |
1492 |
Q: what does this do on Unix systems ? (used in FileNavigator-goody)." |
|
1493 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1494 |
self isAbstract ifTrue:[ |
24017 | 1495 |
^ ConcreteClass volumes |
2906 | 1496 |
]. |
1497 |
||
2896 | 1498 |
^ OperatingSystem getDriveList |
615 | 1499 |
|
8679 | 1500 |
" |
1501 |
Filename volumes |
|
1502 |
" |
|
615 | 1503 |
! ! |
1504 |
||
6383 | 1505 |
!Filename class methodsFor:'utilities'! |
1506 |
||
16389 | 1507 |
canonicalize:aPathString |
1508 |
"convert the argument, aPathString to a good format. |
|
1509 |
This should eliminate useless directory components (i.e. '././') |
|
1510 |
and useless tree walks (i.e. '../foo/..')." |
|
1511 |
||
1512 |
^ self nameFromComponents:(self canonicalizedNameComponents:aPathString) |
|
1513 |
||
1514 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1515 |
Filename canonicalize:'/etc/../etc' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1516 |
Filename canonicalize:'/home/cg/../' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1517 |
Filename canonicalize:'/home/cg/../././' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1518 |
Filename canonicalize:'./home/cg/../././' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1519 |
Filename canonicalize:'/home/././cg/../././' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1520 |
Filename canonicalize:'/home/././cg/././' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1521 |
Filename canonicalize:'/home/cg/../../..' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1522 |
Filename canonicalize:'cg/../../..' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1523 |
Filename canonicalize:'./' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1524 |
Filename canonicalize:'/home/.' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1525 |
Filename canonicalize:'/home/../..' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1526 |
Filename canonicalize:'//foo' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1527 |
Filename canonicalize:'///foo' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1528 |
Filename canonicalize:'//foo//bar' |
16389 | 1529 |
" |
1530 |
! |
|
1531 |
||
1532 |
canonicalizedNameComponents:aPathString |
|
1533 |
"convert the argument, aPathString to a good format. |
|
1534 |
This should eliminate useless directory components (i.e. '././') |
|
1535 |
and useless tree walks (i.e. '../foo/..'). |
|
1536 |
||
1537 |
Answer a sequenceable collection of name components." |
|
1538 |
||
1539 |
|comps newComps rootName dotDot dot| |
|
1540 |
||
1541 |
dotDot := self parentDirectoryName. |
|
1542 |
dot := self currentDirectoryName. |
|
1543 |
rootName := self separatorString. |
|
1544 |
||
1545 |
comps := self components:aPathString. |
|
1546 |
newComps := OrderedCollection new:comps size. |
|
1547 |
comps do:[:eachComponent | |
|
24017 | 1548 |
eachComponent ~= dot ifTrue:[ |
1549 |
eachComponent = dotDot ifTrue:[ |
|
1550 |
(newComps isEmpty |
|
1551 |
or:[(newComps size == 1 and:[newComps first startsWith:rootName]) |
|
1552 |
or:[newComps last = dotDot]]) ifTrue:[ |
|
1553 |
newComps add:eachComponent |
|
1554 |
] ifFalse:[ |
|
1555 |
newComps removeLast |
|
1556 |
]. |
|
1557 |
] ifFalse:[ |
|
1558 |
newComps add:eachComponent |
|
1559 |
]. |
|
1560 |
] |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1561 |
]. |
16389 | 1562 |
"/ add current Directory if empty |
1563 |
newComps isEmpty ifTrue:[ |
|
24017 | 1564 |
newComps add:dot. |
16389 | 1565 |
]. |
1566 |
^ newComps |
|
1567 |
||
1568 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1569 |
Filename canonicalizedNameComponents:'/etc/../etc' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1570 |
Filename canonicalizedNameComponents:'/home/cg/../' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1571 |
Filename canonicalizedNameComponents:'/home/cg/../././' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1572 |
Filename canonicalizedNameComponents:'./home/cg/../././' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1573 |
Filename canonicalizedNameComponents:'/home/././cg/../././' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1574 |
Filename canonicalizedNameComponents:'/home/././cg/././' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1575 |
Filename canonicalizedNameComponents:'/home/cg/../../..' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1576 |
Filename canonicalizedNameComponents:'cg/../../..' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1577 |
Filename canonicalizedNameComponents:'/' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1578 |
Filename canonicalizedNameComponents:'./' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1579 |
Filename canonicalizedNameComponents:'/.' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1580 |
Filename canonicalizedNameComponents:'/home/.' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1581 |
Filename canonicalizedNameComponents:'/home' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1582 |
Filename canonicalizedNameComponents:'/home/../..' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1583 |
Filename canonicalizedNameComponents:'//foo' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1584 |
Filename canonicalizedNameComponents:'///foo' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1585 |
Filename canonicalizedNameComponents:'//foo//bar' |
16389 | 1586 |
" |
1587 |
! |
|
1588 |
||
1589 |
components:aString |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1590 |
"separate the pathName given by aString into |
16578 | 1591 |
a collection containing the directory components and the file's name as |
16389 | 1592 |
the final component. |
1593 |
If the argument names an absolute path, the first component will be the |
|
1594 |
name of the root directory (i.e. '/')." |
|
1595 |
||
1596 |
|sep f vol rest components| |
|
1597 |
||
1598 |
self isAbstract ifTrue:[ |
|
19821 | 1599 |
^ ConcreteClass components:aString |
16389 | 1600 |
]. |
1601 |
||
1602 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
|
1603 |
"/ However, MSDOS drive-letters and network drives are |
|
1604 |
"/ not correctly handled here. |
|
1605 |
||
1606 |
sep := self separator. |
|
1607 |
f := aString asFilename. |
|
1608 |
vol := f volume. |
|
1609 |
vol size ~~ 0 ifTrue:[ |
|
19821 | 1610 |
rest := f localPathName. |
16389 | 1611 |
] ifFalse:[ |
19821 | 1612 |
rest := aString |
16389 | 1613 |
]. |
1614 |
||
1615 |
components := rest asCollectionOfSubstringsSeparatedBy:sep. |
|
1616 |
(rest startsWith:sep) ifTrue:[ |
|
19821 | 1617 |
"first was a separator - root directory - restore" |
1618 |
(rest size > 1 and:[rest second = sep and:[vol isEmptyOrNil]]) ifTrue:[ |
|
1619 |
"keep \\ for windows network paths" |
|
1620 |
components at:1 put:(String with:sep with:sep). |
|
1621 |
] ifFalse:[ |
|
1622 |
components at:1 put:sep asString. |
|
1623 |
]. |
|
16389 | 1624 |
]. |
1625 |
||
1626 |
"/ prepend volume to first component (the root directory) |
|
1627 |
vol size ~~ 0 ifTrue:[ |
|
20694 | 1628 |
vol last = $: ifTrue:[ |
1629 |
vol := vol, (components at:1). |
|
1630 |
]. |
|
1631 |
components at:1 put:vol. |
|
1632 |
]. |
|
1633 |
components := components select:[:each| each notEmpty]. |
|
1634 |
||
16389 | 1635 |
^ components |
1636 |
||
1637 |
" |
|
19821 | 1638 |
Unix: |
1639 |
UnixFilename components:'/foo/bar/baz' |
|
1640 |
UnixFilename components:'/' |
|
1641 |
UnixFilename components:'//' |
|
1642 |
UnixFilename components:'foo/bar/baz' |
|
1643 |
UnixFilename components:'foo/bar' |
|
1644 |
UnixFilename components:'foo' |
|
1645 |
UnixFilename components:'/foo' |
|
1646 |
UnixFilename components:'//foo' |
|
1647 |
UnixFilename components:'' |
|
1648 |
||
1649 |
Windows: |
|
1650 |
PCFilename components:'\' |
|
1651 |
PCFilename components:'\foo' |
|
1652 |
PCFilename components:'\foo\' |
|
1653 |
PCFilename components:'\foo\bar' |
|
1654 |
PCFilename components:'\foo\bar\' |
|
1655 |
PCFilename components:'c:' |
|
1656 |
PCFilename components:'c:\' |
|
1657 |
PCFilename components:'c:\foo' |
|
1658 |
PCFilename components:'c:\foo\' |
|
1659 |
PCFilename components:'c:\foo\bar' |
|
1660 |
PCFilename components:'c:\foo\bar\' |
|
1661 |
PCFilename components:'\\idefix' |
|
1662 |
PCFilename components:'\\idefix\home' |
|
1663 |
PCFilename components:'\\idefix\home\bar' |
|
16389 | 1664 |
" |
1665 |
||
1666 |
"Modified: / 24.9.1998 / 19:10:52 / cg" |
|
1667 |
! |
|
1668 |
||
19821 | 1669 |
filesMatchingGLOB:pattern |
1670 |
"does a GLOB filename expansion. |
|
1671 |
Generates and returns a possibly empty list of files which match |
|
1672 |
the given glob pattern" |
|
1673 |
||
1674 |
^ OrderedCollection withCollectedContents:[:coll | |
|
1675 |
pattern asFilename filesMatchingGLOBDo:[:each | coll add:each] |
|
1676 |
] |
|
1677 |
||
1678 |
" |
|
1679 |
Filename filesMatchingGLOB:'./A*' |
|
1680 |
Filename filesMatchingGLOB:'/etc/A*' |
|
1681 |
Filename filesMatchingGLOB:'/*/A*' |
|
1682 |
'.' asFilename filesMatchingGLOB:'A*' |
|
1683 |
" |
|
1684 |
! |
|
1685 |
||
6802 | 1686 |
nameFromComponents:aCollectionOfDirectoryNames |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1687 |
"return a filenameString from components given in aCollectionOfDirectoryNames. |
6802 | 1688 |
If the first component is the name of the root directory (i.e. '/'), |
1689 |
an absolute path-string is returned." |
|
1690 |
||
1691 |
|sep s| |
|
1692 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1693 |
self isAbstract ifTrue:[ |
24017 | 1694 |
^ ConcreteClass nameFromComponents:aCollectionOfDirectoryNames |
6802 | 1695 |
]. |
1696 |
||
1697 |
"/ fallBack - works on Unix & MSDOS |
|
1698 |
||
8243 | 1699 |
sep := self separatorString. |
6802 | 1700 |
s := ''. |
1701 |
aCollectionOfDirectoryNames keysAndValuesDo:[:index :component | |
|
24017 | 1702 |
index == 1 ifTrue:[ |
1703 |
s := component. |
|
1704 |
] ifFalse:[ |
|
1705 |
(index == 2 and:[ (s endsWith:sep) ]) ifTrue:[ |
|
1706 |
s := s , component |
|
1707 |
] ifFalse:[ |
|
1708 |
s := s , sep , component |
|
1709 |
] |
|
1710 |
]. |
|
6802 | 1711 |
]. |
1712 |
^ s |
|
1713 |
||
1714 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1715 |
Filename nameFromComponents:#('/' 'foo' 'bar' 'baz') |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1716 |
Filename nameFromComponents:#('foo' 'bar' 'baz') |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1717 |
Filename nameFromComponents:#('/') |
7074 | 1718 |
|
1719 |
|comps| |
|
1720 |
comps := Filename components:'/foo/bar/baz'. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1721 |
Filename nameFromComponents:comps |
7074 | 1722 |
|
1723 |
|comps| |
|
1724 |
comps := Filename components:'\foo\bar\baz'. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1725 |
Filename nameFromComponents:comps |
7074 | 1726 |
|
1727 |
|comps| |
|
1728 |
comps := Filename components:'c:\foo\bar\baz'. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1729 |
Filename nameFromComponents:comps |
7074 | 1730 |
|
1731 |
|comps| |
|
1732 |
comps := Filename components:'foo\bar\baz'. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1733 |
Filename nameFromComponents:comps |
7074 | 1734 |
|
1735 |
|comps| |
|
1736 |
comps := Filename components:'foo'. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1737 |
Filename nameFromComponents:comps |
7074 | 1738 |
|
1739 |
|comps| |
|
1740 |
comps := Filename components:'\'. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1741 |
Filename nameFromComponents:comps |
7074 | 1742 |
|
1743 |
|comps| |
|
1744 |
comps := Filename components:'c:\'. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1745 |
Filename nameFromComponents:comps |
6802 | 1746 |
" |
1747 |
||
1748 |
"Modified: 8.9.1997 / 00:23:16 / cg" |
|
1749 |
! |
|
1750 |
||
24017 | 1751 |
possiblyQuotedPathname:aPath |
1752 |
"return a filename path usable as command line argument, |
|
1753 |
by quoting in double quotes if there are any embedded special characters. |
|
1754 |
On Unix systems, special characters might also be prefixed by a backslash character." |
|
1755 |
||
1756 |
(aPath startsWith:$") ifFalse:[ |
|
1757 |
(aPath includes:Character space) ifTrue:[ |
|
24016 | 1758 |
^ '"',aPath,'"' |
24017 | 1759 |
]. |
24016 | 1760 |
]. |
1761 |
^ aPath |
|
1762 |
||
24017 | 1763 |
|
1764 |
" |
|
1765 |
Filename possiblyQuotedPathname:'/tmp/bla' |
|
1766 |
Filename possiblyQuotedPathname:'/tmp directory/bla' |
|
1767 |
Filename possiblyQuotedPathname:'/tmp directory/bla file' |
|
1768 |
" |
|
24016 | 1769 |
! |
1770 |
||
6383 | 1771 |
readingFile:aPathName do:aBlock |
20158 | 1772 |
"Create a read stream on a file, evaluate aBlock, passing that stream, |
1773 |
and return the block's value. |
|
6383 | 1774 |
Ensures that the stream is closed." |
1775 |
||
6529 | 1776 |
^ aPathName asFilename readingFileDo:aBlock. |
1777 |
||
1778 |
" |
|
1779 |
read the first line from some file: |
|
1780 |
||
1781 |
|rslt| |
|
1782 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1783 |
rslt := |
20158 | 1784 |
Filename |
1785 |
readingFile:'/etc/passwd' |
|
1786 |
do:[:s | |
|
1787 |
s nextLine |
|
1788 |
]. |
|
6529 | 1789 |
Transcript showCR:rslt. |
1790 |
" |
|
1791 |
||
1792 |
" |
|
1793 |
find all used shells in /etc/passwd and count their usage: |
|
1794 |
||
6383 | 1795 |
|rslt| |
1796 |
||
6529 | 1797 |
rslt := |
20158 | 1798 |
Filename |
1799 |
readingFile:'/etc/passwd' |
|
1800 |
do: |
|
1801 |
[:s | |
|
1802 |
|shells| |
|
1803 |
||
1804 |
shells := Bag new. |
|
1805 |
s linesDo: |
|
1806 |
[:line | |
|
1807 |
|parts| |
|
1808 |
||
1809 |
parts := line asCollectionOfSubstringsSeparatedBy:$:. |
|
1810 |
shells add:(parts seventh). |
|
1811 |
]. |
|
1812 |
shells contents |
|
1813 |
]. |
|
6529 | 1814 |
Transcript showCR:rslt. |
1815 |
" |
|
6383 | 1816 |
! ! |
1817 |
||
7261 | 1818 |
!Filename methodsFor:'Compatibility-VW5.4'! |
6139 | 1819 |
|
1820 |
asLogicalFileSpecification |
|
1821 |
^ self |
|
1822 |
||
1823 |
"Created: / 30.10.2001 / 17:31:10 / cg" |
|
6447 | 1824 |
! |
1825 |
||
10583 | 1826 |
canBeWritten |
1827 |
"same as isWritable - for ST-80 compatibility" |
|
1828 |
||
1829 |
^ self isWritable |
|
1830 |
||
1831 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1832 |
'/foo/bar' asFilename canBeWritten |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1833 |
'/tmp' asFilename canBeWritten |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1834 |
'Makefile' asFilename canBeWritten |
10583 | 1835 |
" |
1836 |
! |
|
1837 |
||
7596 | 1838 |
definitelyExists |
1839 |
"for now - a kludge" |
|
1840 |
||
1841 |
^ self exists |
|
1842 |
! |
|
1843 |
||
22943 | 1844 |
delete |
1845 |
"remove the file - same as remove, for ST-80 compatibility" |
|
1846 |
||
1847 |
self remove |
|
1848 |
! |
|
1849 |
||
6447 | 1850 |
extension |
6454 | 1851 |
"return the receiver's extension; |
1852 |
that is the characters from and including |
|
1853 |
the last period or nil, if there is none." |
|
1854 |
||
1855 |
|string idx| |
|
1856 |
||
1857 |
string := self asString. |
|
1858 |
idx := string lastIndexOf:$.. |
|
1859 |
idx > 1 ifTrue:[ |
|
24017 | 1860 |
^ string copyFrom:idx |
6454 | 1861 |
]. |
1862 |
^ nil |
|
1863 |
||
1864 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1865 |
'foo.html' asFilename extension |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1866 |
'foo.bar' asFilename extension |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1867 |
'foo.bar.baz' asFilename extension |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1868 |
'foo.' asFilename extension |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1869 |
'foo' asFilename extension |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1870 |
'.login' asFilename extension |
6454 | 1871 |
" |
6139 | 1872 |
! ! |
1873 |
||
23719 | 1874 |
!Filename methodsFor:'attribute setter'! |
1875 |
||
1876 |
clearHidden |
|
1877 |
"ignored here |
|
1878 |
- redefined for windows to clear the file's hidden flag" |
|
1879 |
||
1880 |
^ false "nothing changed" |
|
1881 |
||
1882 |
"Modified: / 12-02-2019 / 12:43:37 / Stefan Vogel" |
|
1883 |
! |
|
1884 |
||
1885 |
setHidden |
|
1886 |
"ignored here |
|
1887 |
- redefined for windows to set the file's hidden flag" |
|
1888 |
||
1889 |
^ false "nothing changed" |
|
1890 |
||
1891 |
"Created: / 22-12-2018 / 18:03:43 / Claus Gittinger" |
|
1892 |
"Modified: / 12-02-2019 / 12:37:25 / Stefan Vogel" |
|
1893 |
! ! |
|
1894 |
||
615 | 1895 |
!Filename methodsFor:'comparing'! |
1896 |
||
16255 | 1897 |
< aFilename |
1898 |
"compare file names - used for sorting" |
|
1899 |
||
1900 |
^ self asString < aFilename asString |
|
1901 |
! |
|
1902 |
||
615 | 1903 |
= aFilename |
1904 |
"return true, if the argument represents the same filename" |
|
1905 |
||
1906 |
|str| |
|
1907 |
||
1908 |
self species == aFilename species ifTrue:[ |
|
24017 | 1909 |
str := aFilename asString. |
1910 |
self species isCaseSensitive ifTrue:[ |
|
1911 |
^ nameString = str |
|
1912 |
]. |
|
1913 |
^ nameString sameAs:str |
|
615 | 1914 |
]. |
1915 |
^ false |
|
1916 |
! |
|
1917 |
||
5877 | 1918 |
contentsIsPrefixOf:aFilename |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1919 |
"return true if the contents of the file represented by the receiver |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1920 |
is the same as or a prefix of the contents of the file represented by the argument, aFilename. |
16578 | 1921 |
This compares the files' actual contents; not the filenames." |
3868 | 1922 |
|
8771 | 1923 |
|f2 s1 s2 bufferSize buffer1 buffer2 n| |
1924 |
||
1925 |
bufferSize := 8192 * 4. |
|
4979 | 1926 |
|
1927 |
f2 := aFilename asFilename. |
|
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1928 |
self fileSize > f2 fileSize ifTrue:[^ false]. |
3868 | 1929 |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1930 |
[ |
22401 | 1931 |
s1 := self readStream. |
1932 |
s2 := f2 readStream. |
|
1933 |
s1 binary. |
|
1934 |
s2 binary. |
|
1935 |
||
1936 |
buffer1 := ByteArray new:bufferSize. |
|
1937 |
buffer2 := ByteArray new:bufferSize. |
|
1938 |
||
1939 |
[s1 atEnd] whileFalse:[ |
|
1940 |
n := s1 nextBytes:bufferSize into:buffer1 startingAt:1. |
|
1941 |
n == 0 ifTrue:[ |
|
1942 |
"/ receiver at end. |
|
1943 |
^ true |
|
1944 |
]. |
|
1945 |
(s2 nextBytes:n into:buffer2 startingAt:1) ~~ n ifTrue:[ |
|
1946 |
"/ aFilename shorter (cannot happen as mySize is <= argument file's size) |
|
1947 |
^ false |
|
1948 |
]. |
|
1949 |
buffer1 ~= buffer2 ifTrue:[ |
|
1950 |
^ false |
|
1951 |
] |
|
1952 |
]. |
|
1953 |
"/ receiver shorter or same size and no difference encountered. |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1954 |
] ensure:[ |
22401 | 1955 |
s1 notNil ifTrue:[s1 close]. |
1956 |
s2 notNil ifTrue:[s2 close]. |
|
3868 | 1957 |
]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1958 |
^ true |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1959 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1960 |
" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1961 |
|s| |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1962 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1963 |
s := 'testFile1' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1964 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1965 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1966 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1967 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1968 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1969 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1970 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1971 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1972 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1973 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1974 |
|
5877 | 1975 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifFalse:[self halt]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1976 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1977 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1978 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1979 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1980 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1981 |
s nextPutAll:'44444'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1982 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1983 |
|
5877 | 1984 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifFalse:[self halt]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1985 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1986 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1987 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1988 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1989 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1990 |
|
5877 | 1991 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifTrue:[self halt]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1992 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1993 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1994 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1995 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1996 |
s nextPutAll:'33334'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1997 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1998 |
|
5877 | 1999 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifTrue:[self halt]. |
2000 |
||
2001 |
" |
|
2002 |
! |
|
2003 |
||
2004 |
contentsStartsWithContentsOf:aFilename |
|
2005 |
"return true if the contents of the file represented by aFilename |
|
2006 |
is the same as or a prefix of the contents of the file represented by the receiver. |
|
16578 | 2007 |
This compares the files' actual contents; not the filenames." |
5877 | 2008 |
|
2009 |
^ aFilename asFilename contentsIsPrefixOf:self |
|
2010 |
||
2011 |
" |
|
2012 |
|s| |
|
2013 |
||
2014 |
s := 'testFile1' asFilename writeStream. |
|
2015 |
s nextPutAll:'11111'. |
|
2016 |
s nextPutAll:'22222'. |
|
2017 |
s nextPutAll:'33333'. |
|
2018 |
s close. |
|
2019 |
||
2020 |
s := 'testFile2' asFilename writeStream. |
|
2021 |
s nextPutAll:'11111'. |
|
2022 |
s nextPutAll:'22222'. |
|
2023 |
s nextPutAll:'33333'. |
|
2024 |
s close. |
|
2025 |
||
2026 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifFalse:[self halt]. |
|
2027 |
||
2028 |
s := 'testFile2' asFilename writeStream. |
|
2029 |
s nextPutAll:'11111'. |
|
2030 |
s nextPutAll:'22222'. |
|
2031 |
s nextPutAll:'33333'. |
|
2032 |
s nextPutAll:'44444'. |
|
2033 |
s close. |
|
2034 |
||
2035 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifFalse:[self halt]. |
|
2036 |
||
2037 |
s := 'testFile2' asFilename writeStream. |
|
2038 |
s nextPutAll:'11111'. |
|
2039 |
s nextPutAll:'22222'. |
|
2040 |
s close. |
|
2041 |
||
2042 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifTrue:[self halt]. |
|
2043 |
||
2044 |
s := 'testFile2' asFilename writeStream. |
|
2045 |
s nextPutAll:'11111'. |
|
2046 |
s nextPutAll:'22222'. |
|
2047 |
s nextPutAll:'33334'. |
|
2048 |
s close. |
|
2049 |
||
2050 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifTrue:[self halt]. |
|
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2051 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2052 |
" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2053 |
! |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2054 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2055 |
hash |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2056 |
"return an integer useful as a hash-key" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2057 |
|
15811 | 2058 |
self species isCaseSensitive ifFalse:[ |
24017 | 2059 |
"/ asLowercase is slightly better: |
2060 |
"/ it never converts single-byte strings to double one's, |
|
2061 |
"/ whereas asUppercase might (for umlaut-y) |
|
2062 |
^ nameString asUppercase hash |
|
11424
c169cc34afe9
fixed hash for case-insensitive files
Claus Gittinger <cg@exept.de>
parents:
11406
diff
changeset
|
2063 |
]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2064 |
^ nameString hash |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2065 |
! |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2066 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2067 |
sameContentsAs:aFilename |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2068 |
"return true if the file represented by the receiver has the |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2069 |
same contents as the file represented by the argument, aFilename. |
16578 | 2070 |
This compares the file's actual contents; not the filenames." |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2071 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2072 |
|f2| |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2073 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2074 |
f2 := aFilename asFilename. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2075 |
f2 fileSize = self fileSize ifFalse:[^ false]. |
5877 | 2076 |
^ self contentsIsPrefixOf:f2. |
3868 | 2077 |
|
2078 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2079 |
'Make.proto' asFilename sameContentsAs:'Makefile' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2080 |
'Make.proto' asFilename sameContentsAs:'Make.proto' |
3868 | 2081 |
" |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2082 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2083 |
" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2084 |
|s| |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2085 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2086 |
s := 'testFile1' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2087 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2088 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2089 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2090 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2091 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2092 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2093 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2094 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2095 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2096 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2097 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2098 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifFalse:[self halt]. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2099 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2100 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2101 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2102 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2103 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2104 |
s nextPutAll:'44444'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2105 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2106 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2107 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifTrue:[self halt]. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2108 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2109 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2110 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2111 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2112 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2113 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2114 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifTrue:[self halt]. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2115 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2116 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2117 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2118 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2119 |
s nextPutAll:'33334'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2120 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2121 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2122 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifTrue:[self halt]. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2123 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2124 |
" |
615 | 2125 |
! ! |
2126 |
||
2127 |
!Filename methodsFor:'converting'! |
|
2128 |
||
2129 |
asAbsoluteFilename |
|
2130 |
"return the receiver converted to a filename with |
|
24060 | 2131 |
an absolute pathname. |
2132 |
||
2133 |
If the receiver does not exist, no absolute filename is generated. |
|
2134 |
||
2135 |
This makes sense, if you want to send #asString or #printString |
|
2136 |
or #hash or #= to it." |
|
615 | 2137 |
|
23740 | 2138 |
^ self species named:self pathName |
7332 | 2139 |
|
2140 |
" |
|
2141 |
'.' asFilename |
|
24060 | 2142 |
'.' asFilename pathName |
7332 | 2143 |
'.' asFilename asAbsoluteFilename |
9173 | 2144 |
'c:' asFilename asAbsoluteFilename |
23654 | 2145 |
'foo' asFilename |
2146 |
'foo' asFilename asAbsoluteFilename |
|
2147 |
" |
|
2148 |
||
23655 | 2149 |
"Modified: / 31-01-2019 / 23:00:41 / Claus Gittinger" |
23740 | 2150 |
"Modified: / 19-02-2019 / 12:29:37 / Stefan Vogel" |
24060 | 2151 |
"Modified (comment): / 11-04-2019 / 18:24:23 / Stefan Vogel" |
615 | 2152 |
! |
2153 |
||
10769 | 2154 |
asAutoDeletedFilename |
13653
6821135a2e1a
comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents:
13424
diff
changeset
|
2155 |
"will automatically delete myself, when no longer referenced" |
6821135a2e1a
comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents:
13424
diff
changeset
|
2156 |
|
11784 | 2157 |
^ AutoDeletedFilename basicNew setName:self name |
13653
6821135a2e1a
comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents:
13424
diff
changeset
|
2158 |
|
6821135a2e1a
comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents:
13424
diff
changeset
|
2159 |
"Modified (comment): / 07-09-2011 / 12:20:59 / cg" |
10769 | 2160 |
! |
2161 |
||
21390 | 2162 |
asBackupFilename |
2163 |
"return the receiver converted to a backup filename." |
|
2164 |
||
2165 |
"/ ^ self species named:(nameString, '~'). |
|
2166 |
"/ ^ self species named:(self directoryName, '/~', self baseName). |
|
2167 |
||
2168 |
^ self addSuffix:'bak' |
|
2169 |
||
2170 |
" |
|
2171 |
'bla' asFilename asBackupFilename |
|
2172 |
'/home/user/directory/bla' asFilename asBackupFilename |
|
2173 |
'directory/bla' asFilename asBackupFilename |
|
2174 |
" |
|
2175 |
||
2176 |
"Created: / 09-02-2017 / 12:57:28 / stefan" |
|
2177 |
! |
|
2178 |
||
6802 | 2179 |
asCanonicalizedFilename |
2180 |
"return the receiver converted to a filename without intermediate ..'s and .'s |
|
2181 |
(similar to an absolute pathname, but symlinks are not resolved)." |
|
2182 |
||
15811 | 2183 |
^ self species named:(self species canonicalize:nameString) |
7074 | 2184 |
|
2185 |
" |
|
2186 |
'c:\test\work' asFilename asCanonicalizedFilename |
|
2187 |
'/test/work' asFilename asCanonicalizedFilename |
|
2188 |
" |
|
6802 | 2189 |
! |
2190 |
||
23407 | 2191 |
asFileURL |
2192 |
"return a file URL-object from myself" |
|
2193 |
||
2194 |
^ (URL fromString:self pathName) method:'file'; yourself. |
|
2195 |
||
2196 |
"Created: / 07-10-2018 / 11:55:18 / Claus Gittinger" |
|
2197 |
! |
|
2198 |
||
615 | 2199 |
asFilename |
20413 | 2200 |
"return the receiver converted to a filename; here, that's the receiver itself." |
2201 |
||
2202 |
"That's pretty easy here :-)" |
|
615 | 2203 |
^ self |
1970 | 2204 |
|
2205 |
"Modified: 12.11.1996 / 12:40:03 / cg" |
|
615 | 2206 |
! |
2207 |
||
21390 | 2208 |
asNonBackupFilename |
2209 |
"return the receiver converted to a backup filename." |
|
2210 |
||
2211 |
nameString last == $~ ifTrue:[ |
|
2212 |
^ self class named:(nameString copyButLast:1). |
|
2213 |
]. |
|
2214 |
(self hasSuffix:'bak') ifTrue:[ |
|
2215 |
^ self withoutSuffix |
|
2216 |
]. |
|
2217 |
^ self. |
|
2218 |
||
2219 |
" |
|
2220 |
'bla.bak' asFilename asNonBackupFilename |
|
2221 |
'/home/user/directory/bla.bak' asFilename asNonBackupFilename |
|
2222 |
'directory/bla.bak' asFilename asNonBackupFilename |
|
2223 |
'directory/bla~' asFilename asNonBackupFilename |
|
2224 |
" |
|
2225 |
||
2226 |
"Created: / 09-02-2017 / 14:01:47 / stefan" |
|
2227 |
! |
|
2228 |
||
615 | 2229 |
asString |
2230 |
"return the receiver converted to a string" |
|
2231 |
||
2232 |
^ nameString |
|
2233 |
! |
|
2234 |
||
6256 | 2235 |
asURI |
15001 | 2236 |
"return the receiver converted to a file URI" |
6256 | 2237 |
|
2238 |
^ FileURI fromFilename:self. |
|
2239 |
! |
|
2240 |
||
15001 | 2241 |
asURL |
2242 |
"return an URL-object from myself" |
|
2243 |
||
2244 |
^ URL fromString:self pathName. |
|
2245 |
! |
|
2246 |
||
19665 | 2247 |
asUniqueFilename |
22939 | 2248 |
"If a file by my name already exists, return a new filename with a unique string appended. |
2249 |
Here, a somewhat naive strategy is performed, by trying _1, _2,... |
|
2250 |
until a new name is generated." |
|
19665 | 2251 |
|
2252 |
|fn baseFn nextSeqNr| |
|
2253 |
||
2254 |
fn := baseFn := self. |
|
2255 |
nextSeqNr := 0. |
|
2256 |
[ fn exists ] whileTrue:[ |
|
23667 | 2257 |
|suff| |
19665 | 2258 |
|
2259 |
nextSeqNr := (nextSeqNr ? 0) + 1. |
|
20453 | 2260 |
suff := baseFn suffix. |
2261 |
suff notEmpty ifTrue:[ suff := '.',suff ]. |
|
2262 |
fn := self class named:((baseFn withoutSuffix name,'_',nextSeqNr asString),suff). |
|
19665 | 2263 |
]. |
2264 |
^ fn |
|
2265 |
||
2266 |
" |
|
2267 |
'aaa.txt' asFilename contents:'bla'. |
|
20453 | 2268 |
'aaa.1.2.3.apk.txt' asFilename asUniqueFilename contents:'bla2'. |
19665 | 2269 |
'aaa.txt' asFilename asUniqueFilename contents:'bla3'. |
2270 |
'aaa.txt' asFilename asUniqueFilename contents:'bla4'. |
|
2271 |
#('aaa.txt' 'aaa_1.txt' 'aaa_2.txt' 'aaa_3.txt') do:[:f | f asFilename delete]. |
|
2272 |
" |
|
23667 | 2273 |
|
2274 |
"Modified (format): / 06-02-2019 / 11:48:44 / Stefan Vogel" |
|
19665 | 2275 |
! |
2276 |
||
5890 | 2277 |
components |
19440 | 2278 |
"return the receiver's filename components - that is the name of each directory |
5890 | 2279 |
along the pathName (that DOES include the root directory)" |
2280 |
||
15811 | 2281 |
^ self species components:self name |
5890 | 2282 |
|
2283 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2284 |
'.' asFilename asAbsoluteFilename components |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2285 |
'Makefile' asFilename asAbsoluteFilename components |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2286 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2287 |
! |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2288 |
|
23129 | 2289 |
makeLegalBasename |
2290 |
"convert the receiver's name to be a legal basename. |
|
2291 |
This removes/replaces invalid characters and/or compresses |
|
2292 |
the name as required by the OS. |
|
2293 |
It also replaces the directory separator (i.e. '/') by an inderscore. |
|
2294 |
The implementation may change in the future to be more |
|
2295 |
OS specific." |
|
2296 |
||
2297 |
" |
|
2298 |
actually, in Unix spaces are allowed - but it makes life |
|
2299 |
so hard; therefore, replace them by underscores ... |
|
2300 |
" |
|
2301 |
nameString := nameString copy |
|
2302 |
replaceAllForWhich:[:each| |
|
2303 |
each isSeparator |
|
2304 |
or:[self class isBadCharacter:each]] |
|
2305 |
with:$_. |
|
2306 |
" |
|
2307 |
need more - especially on SYS5.3 type systems, |
|
2308 |
we may want to contract the fileName to 14 characters. |
|
2309 |
" |
|
2310 |
^ self |
|
2311 |
||
2312 |
" |
|
2313 |
'hello world' asFilename makeLegalBasename |
|
2314 |
('abc' copyWith:Character return) asFilename makeLegalBasename |
|
2315 |
('a/b/c' copyWith:Character return) asFilename makeLegalBasename |
|
2316 |
" |
|
2317 |
||
2318 |
"Created: / 25-06-2018 / 17:11:41 / Claus Gittinger" |
|
2319 |
! |
|
2320 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2321 |
makeLegalFilename |
19440 | 2322 |
"convert the receiver's name to be a legal filename. |
1970 | 2323 |
This removes/replaces invalid characters and/or compresses |
2324 |
the name as required by the OS. |
|
615 | 2325 |
The implementation may change in the future to be more |
2326 |
OS specific." |
|
2327 |
||
2328 |
" |
|
2329 |
actually, in Unix spaces are allowed - but it makes life |
|
2330 |
so hard; therefore, replace them by underscores ... |
|
2331 |
" |
|
22127 | 2332 |
|separator| |
2333 |
||
2334 |
separator := self separator. |
|
23129 | 2335 |
nameString := nameString copy |
2336 |
replaceAllForWhich:[:each| |
|
2337 |
each == Character space |
|
2338 |
or:[each ~= separator and:[self class isBadCharacter:each]]] |
|
2339 |
with:$_. |
|
615 | 2340 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2341 |
need more - especially on SYS5.3 type systems, |
615 | 2342 |
we may want to contract the fileName to 14 characters. |
2343 |
" |
|
2344 |
^ self |
|
2345 |
||
2346 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2347 |
'hello world' asFilename makeLegalFilename |
22127 | 2348 |
('abc' copyWith:Character return) asFilename makeLegalFilename |
2349 |
" |
|
2350 |
||
2351 |
"Modified: / 20-07-1998 / 13:16:51 / cg" |
|
2352 |
"Modified (comment): / 27-07-2017 / 15:53:53 / stefan" |
|
23129 | 2353 |
"Modified (format): / 25-06-2018 / 17:09:23 / Claus Gittinger" |
2707
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2354 |
! |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2355 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2356 |
withEncoding:encodingSymbol |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2357 |
"dummy for now - for ST80 compatibility" |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2358 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2359 |
^ self |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2360 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2361 |
"Created: 20.6.1997 / 17:01:28 / cg" |
2 | 2362 |
! ! |
2363 |
||
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2364 |
!Filename methodsFor:'enumerating-contents'! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2365 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2366 |
allDirectoriesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2367 |
"evaluate aBlock for all (recursive) directories contained in the directory represented by the receiver. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2368 |
The block is invoked with a filename-arguments. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2369 |
The enumerations order within a directory is undefined - i.e. usually NOT sorted by |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2370 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2371 |
This excludes entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2372 |
NoOp for non-existing directories; however, this behavior |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2373 |
may be changed in the near future, to raise an exception instead. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2374 |
So users of this method better test for existing directory before." |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2375 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2376 |
self recursiveDirectoryContentsDo:[:eachFileOrDirectoryName | |
24017 | 2377 |
|eachFileOrDirectory| |
2378 |
||
2379 |
eachFileOrDirectory := self construct:eachFileOrDirectoryName. |
|
2380 |
eachFileOrDirectory isDirectory ifTrue:[ |
|
2381 |
aBlock value:eachFileOrDirectory |
|
2382 |
] |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2383 |
]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2384 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2385 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2386 |
'.' asFilename allDirectoriesDo:[:fn | Transcript showCR:fn name]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2387 |
'.' asFilename directoriesDo:[:fn | Transcript showCR:fn name]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2388 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2389 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2390 |
|
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2391 |
allParentDirectoriesDo:aBlock |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2392 |
"evaluate aBlock for all (recursive) directories along the parent directory path. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2393 |
The block is invoked with a filename-arguments." |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2394 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2395 |
|parent here| |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2396 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2397 |
here := self. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2398 |
parent := here directory. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2399 |
[here notNil and:[parent ~= here]] whileTrue:[ |
24017 | 2400 |
aBlock value:parent. |
2401 |
here := parent. |
|
2402 |
parent := here directory. |
|
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2403 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2404 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2405 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2406 |
'.' asFilename allParentDirectoriesDo:[:fn | Transcript showCR:fn pathName]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2407 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2408 |
! |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2409 |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2410 |
directoriesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2411 |
"evaluate aBlock for directories contained in the directory represented by the receiver. |
23159 | 2412 |
The block is invoked with a filename-argument. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2413 |
The enumerations order is undefined - i.e. usually NOT sorted by |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2414 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2415 |
This excludes entries for '.' or '..'. |
18686 | 2416 |
OpenError is raised if I represent a non-existent or non-readable directories. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2417 |
So users of this method better test for existing directory before." |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2418 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2419 |
self directoryContentsAsFilenamesDo:[:eachFileOrDirectory | |
23159 | 2420 |
eachFileOrDirectory isDirectory ifTrue:[ |
2421 |
aBlock value:eachFileOrDirectory |
|
2422 |
] |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2423 |
]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2424 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2425 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2426 |
'.' asFilename directoriesDo:[:fn | Transcript showCR:fn baseName]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2427 |
" |
23159 | 2428 |
|
2429 |
"Modified (comment): / 30-06-2018 / 18:22:41 / Claus Gittinger" |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2430 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2431 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2432 |
directoryContentsAsFilenamesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2433 |
"evaluate aBlock for each file in the directory represented by the receiver. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2434 |
The block is invoked with a filename-argument. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2435 |
The enumerations order is undefined - i.e. usually NOT sorted by |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2436 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2437 |
This excludes entries for '.' or '..'. |
17310 | 2438 |
An OpenError exception is raised it the directory does not exist or is not readable. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2439 |
So users of this method better test for existing directory before. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2440 |
Notice: this enumerates fileName objects; see also |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2441 |
#directoryContentsDo:, which enumerates strings." |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2442 |
|
6776
11df52e55905
better loop (dont preread all items in ..asFilenamesDo:)
penk
parents:
6773
diff
changeset
|
2443 |
self directoryContentsDo:[:entry | |
24017 | 2444 |
aBlock value:(self construct:entry). |
6776
11df52e55905
better loop (dont preread all items in ..asFilenamesDo:)
penk
parents:
6773
diff
changeset
|
2445 |
] |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2446 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2447 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2448 |
'.' asFilename directoryContentsAsFilenamesDo:[:fn | Transcript showCR:fn pathName]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2449 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2450 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2451 |
"Modified: / 18.9.1997 / 18:42:23 / stefan" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2452 |
"Modified: / 23.12.1999 / 20:56:35 / cg" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2453 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2454 |
|
7464 | 2455 |
directoryContentsDo:aBlock |
2456 |
"evaluate aBlock for each file in the directory represented by the receiver. |
|
2457 |
The block is invoked with a string as argument. |
|
2458 |
The enumerations order is undefined - i.e. usually NOT sorted by |
|
2459 |
filenames (but by creation time - on some systems). |
|
2460 |
This excludes entries for '.' or '..'. |
|
17310 | 2461 |
An OpenError exception is raised it the directory does not exist or is not readable. |
7464 | 2462 |
So users of this method better test for existing directory before. |
2463 |
Notice: this enumerates strings; see also |
|
2464 |
#directoryContentsAsFilenamesDo:, which enumerates fileName objects." |
|
2465 |
||
20533 | 2466 |
|s files| |
17310 | 2467 |
|
2468 |
s := DirectoryStream directoryNamed:self osNameForDirectoryContents. |
|
2469 |
"check for nil, in order to allow to proceed from an OpenError" |
|
23667 | 2470 |
s isNil ifTrue:[ |
2471 |
^ self. |
|
2472 |
]. |
|
2473 |
||
2474 |
"/ the old code did a recursive call with the stream open. |
|
2475 |
"/ for very very deep hierarchies, this lead to having too many file streams open for |
|
2476 |
"/ some operating systems. |
|
2477 |
"/ (and therefore to a blocked system, sooner or later, when running out of open files) |
|
2478 |
"/ new code reads the directory first, then does the recursion. |
|
20533 | 2479 |
|
2480 |
"/ [ |
|
2481 |
"/ [s atEnd] whileFalse:[ |
|
2482 |
"/ |fn| |
|
2483 |
"/ |
|
2484 |
"/ fn := s nextLine. |
|
2485 |
"/ (fn notNil and:[fn ~= '.' and:[fn ~= '..']]) ifTrue:[ |
|
2486 |
"/ aBlock value:fn |
|
2487 |
"/ ]. |
|
2488 |
"/ ]. |
|
2489 |
"/ ] ensure:[ |
|
2490 |
"/ s close. |
|
2491 |
"/ ]. |
|
23667 | 2492 |
files := OrderedCollection new. |
2493 |
[ |
|
2494 |
[s atEnd] whileFalse:[ |
|
2495 |
|fn| |
|
2496 |
||
2497 |
fn := s nextLine. |
|
2498 |
(fn notNil and:[fn ~= '.' and:[fn ~= '..']]) ifTrue:[ |
|
2499 |
files add:fn |
|
19821 | 2500 |
]. |
23667 | 2501 |
]. |
2502 |
] ensure:[ |
|
2503 |
s close. |
|
2504 |
]. |
|
2505 |
files do:aBlock |
|
7464 | 2506 |
|
2507 |
" |
|
2508 |
'.' asFilename directoryContentsDo:[:fn | Transcript showCR:fn]. |
|
7473 | 2509 |
'doeSnotExIST' asFilename directoryContentsDo:[:fn | Transcript showCR:fn]. |
17310 | 2510 |
[ |
19821 | 2511 |
'doeSnotExIST' asFilename directoryContentsDo:[:fn | Transcript showCR:fn]. |
17310 | 2512 |
] on:OpenError do:[:ex| ex proceed] |
7464 | 2513 |
" |
2514 |
||
23667 | 2515 |
"Modified: / 18-09-1997 / 18:42:23 / stefan" |
2516 |
"Modified: / 23-12-1999 / 20:56:35 / cg" |
|
2517 |
"Modified: / 06-02-2019 / 12:00:19 / Stefan Vogel" |
|
7464 | 2518 |
! |
2519 |
||
9806 | 2520 |
filesDo:aBlock |
18734 | 2521 |
"evaluate aBlock for all regular files (i.e. subdirs are ignored) |
2522 |
contained in the directory represented by the receiver." |
|
9806 | 2523 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2524 |
^ self directoryContentsAsFilenamesDo:[:eachFileOrDirectory | |
24017 | 2525 |
eachFileOrDirectory isRegularFile ifTrue:[ |
2526 |
aBlock value: eachFileOrDirectory |
|
2527 |
]. |
|
17310 | 2528 |
]. |
9806 | 2529 |
|
2530 |
" |
|
2531 |
'.' asFilename filesDo:[:f | Transcript showCR:f]. |
|
2532 |
" |
|
2533 |
||
2534 |
"Created: / 29-08-2006 / 11:03:15 / cg" |
|
10557 | 2535 |
"Modified: / 29-05-2007 / 12:02:46 / cg" |
9806 | 2536 |
! |
2537 |
||
19821 | 2538 |
filesMatchingGLOB:pattern do:aBlock |
2539 |
"Interpreting pattern as a GLOB pattern, |
|
2540 |
evaluate aBlock for each file in me, which matches. |
|
2541 |
Returns the number of matches." |
|
2542 |
||
2543 |
self assert:(pattern asFilename isAbsolute not). |
|
23667 | 2544 |
^ self filesMatchingGLOBComponents:(self class components:pattern) do:aBlock |
19821 | 2545 |
|
2546 |
" |
|
2547 |
'..' asFilename filesMatchingGLOB:'A*' do:[:fn | Transcript showCR:fn]. |
|
2548 |
'../..' asFilename filesMatchingGLOB:'lib*/*.st' do:[:fn | Transcript showCR:fn]. |
|
23393 | 2549 |
'/Library/Java/JavaVirtualMachines' asFilename filesMatchingGLOB:'*.jdk' do:[:fn | Transcript showCR:fn]. |
2550 |
" |
|
2551 |
||
2552 |
"Modified (comment): / 30-09-2018 / 10:59:19 / Claus Gittinger" |
|
23667 | 2553 |
"Modified: / 06-02-2019 / 11:55:35 / Stefan Vogel" |
19821 | 2554 |
! |
2555 |
||
2556 |
filesMatchingGLOBComponents:patternComponents do:aBlock |
|
2557 |
"patternComponents is a component-collection with possible GLOB patterns. |
|
2558 |
Evaluate aBlock for each file in me, which matches. |
|
2559 |
Returns the number of matches" |
|
2560 |
||
2561 |
|dirPath subComponents count| |
|
2562 |
||
2563 |
dirPath := patternComponents first. |
|
2564 |
subComponents := patternComponents copyFrom:2. |
|
2565 |
||
2566 |
dirPath includesMatchCharacters ifFalse:[ |
|
2567 |
| sub | |
|
2568 |
||
2569 |
sub := (self / dirPath). |
|
2570 |
subComponents isEmpty ifTrue:[ |
|
2571 |
"/ I am a leaf |
|
2572 |
sub exists ifTrue:[ |
|
2573 |
aBlock value:sub. |
|
2574 |
^ 1. |
|
2575 |
]. |
|
2576 |
^ 0 |
|
2577 |
] ifFalse:[ |
|
2578 |
^ sub filesMatchingGLOBComponents:subComponents do:aBlock |
|
2579 |
]. |
|
2580 |
] ifTrue:[ |
|
2581 |
count := 0. |
|
2582 |
subComponents isEmpty ifTrue:[ |
|
2583 |
"/ I am a leaf |
|
2584 |
self isDirectory ifTrue:[ |
|
2585 |
self filesMatching:dirPath do:[:eachMatchingFile | |
|
2586 |
aBlock value:(self / eachMatchingFile). |
|
2587 |
count := count + 1. |
|
2588 |
] |
|
2589 |
] |
|
2590 |
] ifFalse:[ |
|
2591 |
self filesMatching:dirPath do:[:eachMatchingSubDir | |
|
2592 |
|sub| |
|
2593 |
sub := (self / eachMatchingSubDir). |
|
2594 |
sub isDirectory ifTrue:[ |
|
2595 |
count := count + (sub filesMatchingGLOBComponents:subComponents do:aBlock) |
|
2596 |
]. |
|
2597 |
]. |
|
2598 |
]. |
|
2599 |
^ count |
|
2600 |
]. |
|
2601 |
||
2602 |
" |
|
2603 |
'/etc/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2604 |
'../A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2605 |
'../../lib*/*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2606 |
" |
|
2607 |
! |
|
2608 |
||
2609 |
filesMatchingGLOBDo:aBlock |
|
2610 |
"Interpreting myself as a GLOB pattern, |
|
2611 |
evaluate aBlock for each file which matches." |
|
2612 |
||
2613 |
|parts dirPath subComponents count top| |
|
2614 |
||
2615 |
parts := self components. |
|
2616 |
dirPath := parts first. |
|
2617 |
subComponents := parts copyFrom:2. |
|
2618 |
||
2619 |
OpenError handle:[:ex | |
|
2620 |
('%1 [info]: failed to open %2: %3' |
|
2621 |
bindWith:self class name |
|
2622 |
with:ex pathName |
|
2623 |
with:ex description) infoPrintCR. |
|
2624 |
self breakPoint:#cg. |
|
2625 |
ex proceed. |
|
2626 |
] do:[ |
|
2627 |
top := dirPath asFilename. |
|
2628 |
||
2629 |
dirPath includesMatchCharacters ifFalse:[ |
|
2630 |
top isAbsolute ifFalse:[ |
|
23667 | 2631 |
top := self class currentDirectory construct:dirPath. |
19821 | 2632 |
]. |
2633 |
^ top filesMatchingGLOBComponents:subComponents do:aBlock |
|
2634 |
]. |
|
2635 |
||
2636 |
top isAbsolute ifFalse:[ |
|
23667 | 2637 |
top := self class currentDirectory. |
19821 | 2638 |
]. |
2639 |
count := 0. |
|
2640 |
top filesMatching:dirPath do:[:sub | |
|
2641 |
count := count + ((self / sub) filesMatchingGLOBComponents:subComponents do:aBlock) |
|
2642 |
]. |
|
2643 |
^ count |
|
2644 |
]. |
|
2645 |
||
2646 |
" |
|
2647 |
'/etc/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2648 |
'/etc/a*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2649 |
'../A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2650 |
'../../lib*/*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2651 |
'../../lib*/[A-D]*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2652 |
'../../*/[A-D]*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2653 |
'../../*/*/[A-D]*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2654 |
'../../*java*/*/[A-D]*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2655 |
'../../*java*/*/Ary.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2656 |
'/*/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2657 |
'*/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2658 |
'../*/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2659 |
'./*/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2660 |
'./*/*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2661 |
'././A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2662 |
" |
|
23667 | 2663 |
|
2664 |
"Modified: / 06-02-2019 / 11:56:05 / Stefan Vogel" |
|
19821 | 2665 |
! |
2666 |
||
18734 | 2667 |
filesWithSuffix:suffix do:aBlock |
2668 |
"evaluate aBlock for all regular files with a given suffix |
|
2669 |
contained in the directory represented by the receiver. |
|
2670 |
(i.e. subdirs are ignored)" |
|
2671 |
||
2672 |
^ self directoryContentsAsFilenamesDo:[:eachFileOrDirectory | |
|
24017 | 2673 |
(eachFileOrDirectory hasSuffix:suffix) ifTrue:[ |
2674 |
eachFileOrDirectory isRegularFile ifTrue:[ |
|
2675 |
aBlock value: eachFileOrDirectory |
|
2676 |
]. |
|
2677 |
]. |
|
18734 | 2678 |
]. |
2679 |
||
2680 |
" |
|
2681 |
'.' asFilename filesWithSuffix:'so' do:[:f | Transcript showCR:f]. |
|
2682 |
" |
|
2683 |
! |
|
2684 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2685 |
recursiveDirectoryContentsAsFilenamesDo:aBlock |
13191
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2686 |
"evaluate aBlock for all files and directories found under the receiver. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2687 |
The block is invoked with the filenames as argument. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2688 |
The walk is bread-first. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2689 |
This excludes any entries for '.' or '..'. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2690 |
Subdirectory files are included with a relative pathname. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2691 |
Warning: this may take a long time to execute (especially with deep and/or remote fileSystems)." |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2692 |
|
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2693 |
self recursiveDirectoryContentsDo:[:relFn | |
19664 | 2694 |
aBlock value:(self construct:relFn) |
13191
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2695 |
]. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2696 |
|
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2697 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2698 |
'.' asFilename recursiveDirectoryContentsAsFilenamesDo:[:f | Transcript showCR:f] |
13191
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2699 |
" |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2700 |
|
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2701 |
"Modified: / 12-09-2010 / 15:43:22 / cg" |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2702 |
! |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2703 |
|
20686 | 2704 |
recursiveDirectoryContentsAsFilenamesDo:aBlock filterForVisitingDirectories:filterOrNil |
2705 |
"evaluate aBlock for all files and directories found under the receiver. |
|
2706 |
The block is invoked with the filenames as argument. |
|
2707 |
The walk is bread-first. |
|
2708 |
This excludes any entries for '.' or '..'. |
|
2709 |
Subdirectory files are included with a relative pathname. |
|
2710 |
If filterOrNil is nonNil, it is passed every directory about to be walked into; |
|
2711 |
if it returns false, that directory is not entered. |
|
2712 |
Warning: this may take a long time to execute |
|
2713 |
(especially with deep and/or remote fileSystems)." |
|
2714 |
||
2715 |
self |
|
2716 |
recursiveDirectoryContentsDo:[:relFn | |
|
2717 |
aBlock value:(self construct:relFn) |
|
2718 |
] |
|
2719 |
filterForVisitingDirectories:filterOrNil. |
|
2720 |
||
2721 |
" |
|
2722 |
'.' asFilename recursiveDirectoryContentsAsFilenamesDo:[:f | Transcript showCR:f] |
|
2723 |
" |
|
2724 |
||
2725 |
"Modified: / 12-09-2010 / 15:43:22 / cg" |
|
2726 |
! |
|
2727 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2728 |
recursiveDirectoryContentsDo:aBlock |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2729 |
"evaluate aBlock for all files and directories found under the receiver. |
13057
4f7fa62156ac
comment/format in: #recursiveDirectoryContentsDo:
Claus Gittinger <cg@exept.de>
parents:
12975
diff
changeset
|
2730 |
The block is invoked with the relative filenames as string-argument. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2731 |
The walk is bread-first. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2732 |
This excludes any entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2733 |
Subdirectory files are included with a relative pathname. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2734 |
Warning: this may take a long time to execute (especially with deep and/or remote fileSystems)." |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2735 |
|
19664 | 2736 |
self |
2737 |
recursiveDirectoryContentsWithPrefix:'' |
|
2738 |
filesDo:aBlock |
|
2739 |
directoriesDo:aBlock |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2740 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2741 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2742 |
'.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2743 |
" |
13057
4f7fa62156ac
comment/format in: #recursiveDirectoryContentsDo:
Claus Gittinger <cg@exept.de>
parents:
12975
diff
changeset
|
2744 |
|
4f7fa62156ac
comment/format in: #recursiveDirectoryContentsDo:
Claus Gittinger <cg@exept.de>
parents:
12975
diff
changeset
|
2745 |
"Modified: / 12-09-2010 / 15:43:22 / cg" |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2746 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2747 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2748 |
recursiveDirectoryContentsDo:aBlock directoryPrefix:aPrefix |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2749 |
"evaluate aBlock for all files and directories found under the receiver. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2750 |
The block is invoked with a string-argument. |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2751 |
The walk is breadth-first. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2752 |
This excludes any entries for '.' or '..'. |
19664 | 2753 |
The argument to aBlock is a pathname relative to aPrefix. |
19114 | 2754 |
A proceedable exception is raised forn non-accessible directories. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2755 |
Warning: this may take a long time to execute (especially with deep and/or remote fileSystems)." |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2756 |
|
19664 | 2757 |
self |
2758 |
recursiveDirectoryContentsWithPrefix:aPrefix |
|
2759 |
filesDo:aBlock |
|
2760 |
directoriesDo:aBlock |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2761 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2762 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2763 |
'.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2764 |
'/etc' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2765 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2766 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2767 |
|
20686 | 2768 |
recursiveDirectoryContentsDo:aBlock filterForVisitingDirectories:filterOrNil |
2769 |
"evaluate aBlock for all files and directories found under the receiver. |
|
2770 |
The block is invoked with the relative filenames as string-argument. |
|
2771 |
The walk is bread-first. |
|
2772 |
This excludes any entries for '.' or '..'. |
|
2773 |
Subdirectory files are included with a relative pathname. |
|
2774 |
If filterOrNil is nonNil, it is passed every directory about to be walked into; |
|
2775 |
if it returns false, that directory is not entered. |
|
2776 |
Warning: this may take a long time to execute |
|
2777 |
(especially with deep and/or remote fileSystems)." |
|
2778 |
||
2779 |
self |
|
2780 |
recursiveDirectoryContentsWithPrefix:'' |
|
2781 |
filesDo:aBlock |
|
2782 |
directoriesDo:aBlock |
|
2783 |
filterForVisitingDirectories:filterOrNil |
|
2784 |
||
2785 |
" |
|
2786 |
'.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] |
|
2787 |
" |
|
2788 |
||
2789 |
"Modified: / 12-09-2010 / 15:43:22 / cg" |
|
2790 |
! |
|
2791 |
||
19664 | 2792 |
recursiveDirectoryContentsWithPrefix:aPrefix filesDo:fileBlock directoriesDo:dirBlock |
2793 |
"evaluate aBlock for all files and directories found under the receiver. |
|
2794 |
The blocks are invoked with a relative pathname as string-argument. |
|
2795 |
The walk is breadth-first (first files, then directories). |
|
2796 |
This excludes any entries for '.' or '..'. |
|
2797 |
A proceedable exception is raised for non-accessible directories. |
|
20686 | 2798 |
Warning: this may take a long time to execute |
2799 |
(especially with deep and/or remote fileSystems)." |
|
2800 |
||
2801 |
self |
|
2802 |
recursiveDirectoryContentsWithPrefix:aPrefix |
|
2803 |
filesDo:fileBlock |
|
2804 |
directoriesDo:dirBlock |
|
2805 |
filterForVisitingDirectories:nil |
|
2806 |
||
2807 |
" |
|
2808 |
'.' asFilename |
|
2809 |
recursiveDirectoryContentsWithPrefix:'bla' |
|
2810 |
filesDo:[:f | Transcript show:'file: '; showCR:f] |
|
2811 |
directoriesDo:[:f | Transcript show:'dir: '; showCR:f] |
|
2812 |
" |
|
2813 |
! |
|
2814 |
||
22500 | 2815 |
recursiveDirectoryContentsWithPrefix:aPrefix filesDo:fileBlock directoriesDo:dirBlock |
2816 |
filterForVisitingDirectories:filterOrNil |
|
2817 |
||
20686 | 2818 |
"evaluate aBlock for all files and directories found under the receiver. |
2819 |
The blocks are invoked with a relative pathname as string-argument. |
|
2820 |
The walk is breadth-first (first files, then directories). |
|
2821 |
This excludes any entries for '.' or '..'. |
|
2822 |
A proceedable exception is raised for non-accessible directories. |
|
2823 |
If filterOrNil is nonNil, it is passed every directory about to be walked into; |
|
2824 |
if it returns false, that directory is not entered. |
|
2825 |
Warning: this may take a long time to execute |
|
2826 |
(especially with deep and/or remote fileSystems). |
|
2827 |
" |
|
19664 | 2828 |
|
2829 |
|fileNames dirNames p| |
|
2830 |
||
2831 |
"/ first collect files and dirs |
|
2832 |
fileNames := OrderedCollection new. |
|
2833 |
dirNames := OrderedCollection new. |
|
2834 |
||
2835 |
self directoryContentsDo:[:f | |t| |
|
2836 |
t := self construct:f. |
|
2837 |
t isDirectory ifTrue:[ |
|
20686 | 2838 |
(filterOrNil isNil or:[filterOrNil value:t]) ifTrue:[ |
2839 |
dirBlock notNil ifTrue:[ |
|
2840 |
t isSymbolicLink ifFalse:[ |
|
2841 |
dirNames add:f |
|
2842 |
] |
|
19664 | 2843 |
] |
2844 |
] |
|
2845 |
] ifFalse:[ |
|
2846 |
fileBlock notNil ifTrue:[ |
|
2847 |
fileNames add:f |
|
2848 |
] |
|
2849 |
] |
|
2850 |
]. |
|
2851 |
||
23667 | 2852 |
aPrefix size ~~ 0 ifTrue:[ |
19664 | 2853 |
p := aPrefix , self separator |
2854 |
] ifFalse:[ |
|
2855 |
p := '' |
|
2856 |
]. |
|
2857 |
||
2858 |
fileBlock notNil ifTrue:[ |
|
2859 |
fileNames do:[:aFile | fileBlock value:(p , aFile)]. |
|
2860 |
]. |
|
2861 |
dirBlock notNil ifTrue:[ |
|
2862 |
dirNames do:[:dN | |
|
20686 | 2863 |
|subDir| |
2864 |
||
2865 |
subDir := (self construct:dN). |
|
2866 |
(filterOrNil isNil or:[filterOrNil value:subDir]) ifTrue:[ |
|
2867 |
dirBlock value:(p , dN). |
|
2868 |
subDir |
|
2869 |
recursiveDirectoryContentsWithPrefix:(p , dN) |
|
2870 |
filesDo:fileBlock directoriesDo:dirBlock |
|
22500 | 2871 |
filterForVisitingDirectories:filterOrNil |
20686 | 2872 |
]. |
19664 | 2873 |
]. |
2874 |
]. |
|
2875 |
||
2876 |
" |
|
2877 |
'.' asFilename |
|
2878 |
recursiveDirectoryContentsWithPrefix:'bla' |
|
2879 |
filesDo:[:f | Transcript show:'file: '; showCR:f] |
|
2880 |
directoriesDo:[:f | Transcript show:'dir: '; showCR:f] |
|
2881 |
" |
|
23667 | 2882 |
|
2883 |
"Modified: / 06-02-2019 / 11:45:22 / Stefan Vogel" |
|
19664 | 2884 |
! |
2885 |
||
24235 | 2886 |
recursiveFilesDo:fileBlock directoriesDo:dirBlock filterForVisitingDirectories:filterOrNil |
2887 |
"evaluate aBlock for all files and directories found under the receiver. |
|
2888 |
The blocks are invoked with a relative pathname as string-argument. |
|
2889 |
The walk is depth-first (but files first, then directories). |
|
2890 |
This excludes any entries for '.' or '..'. |
|
2891 |
A proceedable exception is raised for non-accessible directories. |
|
2892 |
If filterOrNil is nonNil, it is passed every directory about to be walked into; |
|
2893 |
if it returns false, that directory is not entered. |
|
2894 |
Warning: this may take a long time to execute |
|
2895 |
(especially with deep and/or remote fileSystems). |
|
2896 |
Names are enumerated in the order they appear in the folder, |
|
2897 |
(which is not required to be sorted). |
|
2898 |
" |
|
2899 |
||
2900 |
self |
|
2901 |
recursiveFilesDo:fileBlock directoriesDo:dirBlock |
|
2902 |
filterForVisitingDirectories:filterOrNil sortedBy:nil |
|
2903 |
||
2904 |
" |
|
2905 |
'.' asFilename |
|
2906 |
recursiveFilesDo:[:f | Transcript show:'file: '; showCR:f] |
|
2907 |
directoriesDo:[:f | Transcript show:'dir: '; showCR:f] |
|
2908 |
filterForVisitingDirectories:nil |
|
2909 |
" |
|
2910 |
||
2911 |
"Created: / 29-05-2019 / 09:58:12 / Claus Gittinger" |
|
2912 |
"Modified (comment): / 29-05-2019 / 11:24:57 / Claus Gittinger" |
|
2913 |
! |
|
2914 |
||
2915 |
recursiveFilesDo:fileBlock directoriesDo:dirBlock filterForVisitingDirectories:filterOrNil sortedBy:sortedByBlock |
|
2916 |
"evaluate aBlock for all files and directories found under the receiver. |
|
2917 |
The blocks are invoked with a relative pathname as string-argument. |
|
2918 |
The walk is breadth-first (files first, then directories). |
|
2919 |
This excludes any entries for '.' or '..'. |
|
2920 |
A proceedable exception is raised for non-accessible directories. |
|
2921 |
If filterOrNil is nonNil, it is passed every directory about to be walked into; |
|
2922 |
if it returns false, that directory is not entered. |
|
2923 |
Warning: this may take a long time to execute |
|
2924 |
(especially with deep and/or remote fileSystems). |
|
2925 |
By default, names are enumerated in the order they appear in the folder, |
|
2926 |
(which is not required to be sorted). |
|
2927 |
If sortedByBlock is non nil, it is applied with the file names to sort them |
|
2928 |
(usually a block is provided to sort by name, aka [:a :b | a name < b name] |
|
2929 |
or by caseless name, like [:a :b | a name caselessBefore: b name] |
|
2930 |
" |
|
2931 |
||
2932 |
|getFilesAndDirs toDo fileNames dirNames job thisDir| |
|
2933 |
||
2934 |
toDo := OrderedCollection new. |
|
2935 |
||
2936 |
getFilesAndDirs := |
|
2937 |
[:aRoot | |
|
2938 |
|contents fileNames dirNames wrap| |
|
2939 |
||
2940 |
"/ first collect files and dirs |
|
2941 |
fileNames := OrderedCollection new. |
|
2942 |
dirNames := OrderedCollection new. |
|
2943 |
||
2944 |
contents := aRoot directoryContents. |
|
2945 |
sortedByBlock notNil ifTrue:[ |
|
2946 |
contents sort:[:a :b | sortedByBlock value:(aRoot construct:a) value:(aRoot construct:b)]. |
|
2947 |
]. |
|
2948 |
contents do:[:f | |t| |
|
2949 |
t := aRoot construct:f. |
|
2950 |
t isDirectory ifTrue:[ |
|
2951 |
(filterOrNil isNil or:[filterOrNil value:t]) ifTrue:[ |
|
2952 |
dirBlock notNil ifTrue:[ |
|
2953 |
t isSymbolicLink ifFalse:[ |
|
2954 |
dirNames add:f |
|
2955 |
] |
|
2956 |
] |
|
2957 |
] |
|
2958 |
] ifFalse:[ |
|
2959 |
fileBlock notNil ifTrue:[ |
|
2960 |
fileNames add:f |
|
2961 |
] |
|
2962 |
] |
|
2963 |
]. |
|
2964 |
toDo add:{ aRoot . fileNames . dirNames } |
|
2965 |
]. |
|
2966 |
||
2967 |
getFilesAndDirs value:self. |
|
2968 |
||
2969 |
[toDo notEmpty] whileTrue:[ |
|
2970 |
job := toDo removeFirst. |
|
2971 |
"/ process files.. |
|
2972 |
thisDir := job at:1. |
|
2973 |
fileNames := job at:2. |
|
2974 |
dirNames := job at:3. |
|
2975 |
||
2976 |
fileNames do:[:fN | fileBlock value:(thisDir constructString:fN)]. |
|
2977 |
dirNames do:[:dN | |
|
2978 |
|subDir| |
|
2979 |
||
2980 |
subDir := (thisDir construct:dN). |
|
2981 |
(filterOrNil isNil or:[filterOrNil value:subDir]) ifTrue:[ |
|
2982 |
dirBlock value:(subDir name). |
|
2983 |
getFilesAndDirs value:subDir. |
|
2984 |
]. |
|
2985 |
]. |
|
2986 |
]. |
|
2987 |
||
2988 |
" |
|
2989 |
'.' asFilename |
|
2990 |
recursiveFilesDo:[:f | Transcript show:'file: '; showCR:f] |
|
2991 |
directoriesDo:[:f | Transcript show:'dir: '; showCR:f] |
|
2992 |
filterForVisitingDirectories:nil |
|
2993 |
sortedBy:[:a :b | a name caselessBefore: b name] |
|
2994 |
||
2995 |
'.' asFilename |
|
2996 |
recursiveFilesDo:[:f | Transcript showCR:f] |
|
2997 |
directoriesDo:[:f | Transcript showCR:f] |
|
2998 |
filterForVisitingDirectories:nil |
|
2999 |
sortedBy:[:a :b | a name caselessBefore: b name] |
|
3000 |
||
3001 |
'../../..' asFilename |
|
3002 |
recursiveFilesDo:[:f | Transcript show:'file: '; showCR:f] |
|
3003 |
directoriesDo:[:f | Transcript show:'dir: '; showCR:f] |
|
3004 |
filterForVisitingDirectories:nil |
|
3005 |
sortedBy:[:a :b | a name caselessBefore: b name] |
|
3006 |
||
3007 |
'../../..' asFilename |
|
3008 |
recursiveFilesDo:[:f | Transcript show:'file: '; showCR:f] |
|
3009 |
directoriesDo:[:f | Transcript show:'dir: '; showCR:f] |
|
3010 |
filterForVisitingDirectories:nil |
|
3011 |
sortedBy:nil |
|
3012 |
" |
|
3013 |
||
3014 |
"Created: / 29-05-2019 / 10:15:40 / Claus Gittinger" |
|
3015 |
"Modified (comment): / 29-05-2019 / 11:28:57 / Claus Gittinger" |
|
3016 |
! |
|
3017 |
||
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
3018 |
withAllDirectoriesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
3019 |
"evaluate aBlock for myself and all (recursive) directories contained in the directory represented by the receiver. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
3020 |
The block is invoked with a filename-arguments. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
3021 |
The enumerations order within a directory is undefined - i.e. usually NOT sorted by |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
3022 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
3023 |
This excludes entries for '.' or '..'. |
17310 | 3024 |
OpenError is raised if the name I represent does not exist or is not readable. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
3025 |
So users of this method better test for existing directory before." |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
3026 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
3027 |
self isDirectory ifTrue:[ |
24017 | 3028 |
aBlock value:self. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
3029 |
]. |
17310 | 3030 |
self allDirectoriesDo:aBlock. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
3031 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
3032 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
3033 |
'.' asFilename withAllDirectoriesDo:[:fn | Transcript showCR:fn name]. |
17310 | 3034 |
'IdoNOTexist' asFilename withAllDirectoriesDo:[:fn | Transcript showCR:fn name]. |
3035 |
'/etc/hosts' asFilename withAllDirectoriesDo:[:fn | Transcript showCR:fn name]. |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
3036 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
3037 |
! ! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
3038 |
|
542 | 3039 |
!Filename methodsFor:'error handling'! |
3040 |
||
615 | 3041 |
fileCreationError:filename |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
3042 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
3043 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
3044 |
"report an error that some file could not be created" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
3045 |
|
615 | 3046 |
^ OperatingSystem accessDeniedErrorSignal |
24017 | 3047 |
raiseRequestWith:filename?self |
3048 |
errorString:(' - cannot create/write file: "%1"' bindWith:(filename ? self) asString) |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3049 |
! |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3050 |
|
615 | 3051 |
reportError:string with:filename |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
3052 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
3053 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
3054 |
"report an error" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
3055 |
|
15192 | 3056 |
^ OsError |
24017 | 3057 |
raiseRequestWith:filename?self |
3058 |
errorString:string |
|
615 | 3059 |
! ! |
3060 |
||
3061 |
!Filename methodsFor:'file access'! |
|
3062 |
||
3015 | 3063 |
appendStream |
3064 |
"return a stream for appending to the file represented by the receiver. |
|
3065 |
If the file does not already exist, it is created. |
|
3066 |
Same as #appendingWriteStream for ST-80 compatibility." |
|
3067 |
||
3068 |
^ self appendingWriteStream |
|
3069 |
! |
|
3070 |
||
615 | 3071 |
appendingWriteStream |
3072 |
"return a stream for appending to the file represented by the receiver. |
|
5720 | 3073 |
If the file does not already exist, it is created; |
3074 |
if it does exist, writes are appended at the end." |
|
615 | 3075 |
|
2947 | 3076 |
^ FileStream appendingOldFileNamed:(self osNameForAccess) |
5720 | 3077 |
|
3078 |
" |
|
3079 |
|s| |
|
3080 |
||
3081 |
s := '/tmp/foo' asFilename writeStream. |
|
3082 |
s nextPutAll:'1234567890'. |
|
3083 |
s close. |
|
3084 |
||
3085 |
s := '/tmp/foo' asFilename appendingWriteStream. |
|
3086 |
s nextPutAll:'abcdef'. |
|
3087 |
s close. |
|
3088 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3089 |
'/tmp/foo' asFilename contents |
5720 | 3090 |
" |
615 | 3091 |
! |
3092 |
||
15490 | 3093 |
existingReadWriteStream |
3094 |
"return a stream for read/write the file represented by the receiver. |
|
3095 |
If the file does not already exist, an exception is raised." |
|
3096 |
||
3097 |
^ FileStream oldFileNamed:(self osNameForAccess) |
|
3098 |
||
3099 |
" |
|
3100 |
'/tmp/blaFaselQuall666666' asFilename remove. |
|
3101 |
'/tmp/blaFaselQuall666666' asFilename existingReadWriteStream. |
|
3102 |
" |
|
3103 |
" |
|
3104 |
|s| |
|
3105 |
s := '/tmp/foo' asFilename readWriteStream. |
|
3106 |
s nextPutAll:'1234567890'; close. |
|
3107 |
s := '/tmp/foo' asFilename existingReadWriteStream. |
|
3108 |
s nextPutAll:'abcdef'; close. |
|
3109 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3110 |
'/tmp/foo' asFilename contents inspect. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3111 |
'/tmp/foo' asFilename remove |
15490 | 3112 |
" |
3113 |
! |
|
3114 |
||
615 | 3115 |
newReadWriteStream |
3116 |
"return a stream for read/write the file represented by the receiver. |
|
5720 | 3117 |
If the file does not already exist, it is created; |
3118 |
if it does exist, it is truncated." |
|
615 | 3119 |
|
2947 | 3120 |
^ FileStream newFileNamed:(self osNameForAccess) |
5720 | 3121 |
|
3122 |
" |
|
3123 |
|s| |
|
3124 |
||
3125 |
s := '/tmp/foo' asFilename writeStream. |
|
3126 |
s nextPutAll:'1234567890'. |
|
3127 |
s close. |
|
3128 |
||
3129 |
s := '/tmp/foo' asFilename newReadWriteStream. |
|
3130 |
s nextPutAll:'12345'. |
|
3131 |
s close. |
|
3132 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3133 |
'/tmp/foo' asFilename contents |
5720 | 3134 |
" |
615 | 3135 |
! |
3136 |
||
15459 | 3137 |
openWithMode:anArrayOrString |
3138 |
"return a stream for read/write the file represented by the receiver. |
|
3139 |
If the file does not already exist, it is created; |
|
3140 |
if it does exist, it is truncated." |
|
3141 |
||
3142 |
^ FileStream open:self osNameForAccess withMode:anArrayOrString |
|
3143 |
||
3144 |
" |
|
3145 |
|s| |
|
3146 |
||
3147 |
s := '/tmp/foo' asFilename openWithMode:'r+'. |
|
3148 |
s nextPutAll:'1234567890'. |
|
3149 |
s close. |
|
3150 |
||
3151 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3152 |
'/tmp/foo' asFilename contents |
15459 | 3153 |
" |
3154 |
! |
|
3155 |
||
615 | 3156 |
readStream |
20156 | 3157 |
"Return a stream for reading from the file represented by the receiver. |
7828 | 3158 |
Raises an error if the file does not exist." |
615 | 3159 |
|
2947 | 3160 |
^ FileStream readonlyFileNamed:(self osNameForAccess) |
615 | 3161 |
|
3162 |
" |
|
20156 | 3163 |
'/tmp/foo' asFilename readStream |
615 | 3164 |
" |
3165 |
! |
|
3166 |
||
3167 |
readWriteStream |
|
3168 |
"return a stream for read/write the file represented by the receiver. |
|
7828 | 3169 |
If the file does not already exist, it is created. |
3170 |
If the file does exist, it is NOT truncated, but rewritten at the beginning." |
|
615 | 3171 |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
3172 |
^ FileStream fileNamed:(self osNameForAccess) |
5720 | 3173 |
|
3174 |
" |
|
3175 |
|s| |
|
3176 |
||
3177 |
s := '/tmp/foo' asFilename writeStream. |
|
3178 |
s nextPutAll:'1234567890'. |
|
3179 |
s close. |
|
3180 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3181 |
s := '/tmp/foo' asFilename readWriteStream. |
5720 | 3182 |
s nextPutAll:'abcdef'. |
3183 |
s close. |
|
3184 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3185 |
'/tmp/foo' asFilename contents |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3186 |
'/tmp/foo' asFilename remove |
5720 | 3187 |
" |
615 | 3188 |
! |
3189 |
||
3190 |
writeStream |
|
3191 |
"return a stream for writing to the file represented by the receiver. |
|
5720 | 3192 |
If the file does not already exist, it is created; |
3193 |
if it does exist, it is truncated." |
|
615 | 3194 |
|
2947 | 3195 |
^ FileStream newFileForWritingNamed:(self osNameForAccess) |
615 | 3196 |
|
3197 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3198 |
'/tmp/foo' asFilename writeStream |
615 | 3199 |
" |
5720 | 3200 |
|
3201 |
" |
|
3202 |
|s| |
|
3203 |
||
3204 |
s := '/tmp/foo' asFilename writeStream. |
|
3205 |
s nextPutAll:'1234567890'. |
|
3206 |
s close. |
|
3207 |
||
3208 |
s := '/tmp/foo' asFilename writeStream. |
|
3209 |
s nextPutAll:'12345'. |
|
3210 |
s close. |
|
3211 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3212 |
'/tmp/foo' asFilename contents |
5720 | 3213 |
" |
615 | 3214 |
! ! |
3215 |
||
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3216 |
!Filename methodsFor:'file access - migration'! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3217 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3218 |
appendingWriteStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3219 |
"return a stream for appending to the file represented by the receiver. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3220 |
If the file does not already exist, it is created; |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3221 |
if it does exist, writes are appended at the end. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3222 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3223 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3224 |
Use this method for migration of old smalltalk code that expects a nil return code |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3225 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3226 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
3227 |
^ [ |
24017 | 3228 |
FileStream appendingOldFileNamed:(self osNameForAccess) |
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
3229 |
] on:FileStream openErrorSignal do:[:ex| nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3230 |
! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3231 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3232 |
newReadWriteStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3233 |
"return a stream for read/write the file represented by the receiver. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3234 |
If the file does not already exist, it is created; |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3235 |
if it does exist, it is truncated. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3236 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3237 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3238 |
Use this method for migration of old smalltalk code that expects a nil return code |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3239 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3240 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
3241 |
^ [ |
24017 | 3242 |
FileStream newFileNamed:(self osNameForAccess) |
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
3243 |
] on:FileStream openErrorSignal do:[:ex|nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3244 |
! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3245 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3246 |
readStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3247 |
"return a stream for reading from the file represented by the receiver. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3248 |
If the file does not already exist, nil is returned. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3249 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3250 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3251 |
Use this method for migration of old smalltalk code that expects a nil return code |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3252 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3253 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
3254 |
^ [ |
24017 | 3255 |
FileStream readonlyFileNamed:(self osNameForAccess) |
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
3256 |
] on:FileStream openErrorSignal do:[:ex|nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3257 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3258 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3259 |
'/tmp/foo' asFilename readStreamOrNil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3260 |
'/tmp/foo' asFilename readStream |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3261 |
" |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3262 |
! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3263 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3264 |
readWriteStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3265 |
"return a stream for read/write the file represented by the receiver. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3266 |
If the file does not already exist, it is created. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3267 |
If the file does exist, it is NOT truncated, but rewritten at the beginning |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3268 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3269 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3270 |
Use this method for migration of old smalltalk code that expects a nil return code |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3271 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3272 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
3273 |
^ [ |
24017 | 3274 |
FileStream fileNamed:(self osNameForAccess) |
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
3275 |
] on:FileStream openErrorSignal do:[:ex|^ nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3276 |
! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3277 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3278 |
writeStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3279 |
"return a stream for writing to the file represented by the receiver. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3280 |
If the file does not already exist, it is created; |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3281 |
if it does exist, it is truncated. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3282 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3283 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3284 |
Use this method for migration of old smalltalk code that expects a nil return code |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3285 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3286 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
3287 |
^ [ |
24017 | 3288 |
FileStream newFileForWritingNamed:(self osNameForAccess) |
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
3289 |
] on:FileStream openErrorSignal do:[:ex|^ nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3290 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3291 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3292 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3293 |
'/etc/foo' asFilename writeStreamOrNil |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3294 |
" |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3295 |
! ! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3296 |
|
16310 | 3297 |
!Filename methodsFor:'file access rights'! |
615 | 3298 |
|
12529 | 3299 |
accessRights |
3300 |
"return the access rights of the file as opaque data |
|
3301 |
(SmallInteger in unix/linux)" |
|
3302 |
||
21071 | 3303 |
|access| |
3304 |
||
24066 | 3305 |
access := OperatingSystem accessModeOf:self osNameForAccess. |
21071 | 3306 |
access isOSErrorHolder ifTrue:[ |
3307 |
access reportProceedableError:'get access rights failed'. |
|
3308 |
]. |
|
3309 |
^ access. |
|
12529 | 3310 |
|
3311 |
" |
|
24066 | 3312 |
'Make.proto' asFilename accessRights printStringRadix:8 |
3313 |
'foo' asFilename accessRights printStringRadix:8 |
|
3314 |
" |
|
3315 |
||
3316 |
"Modified (comment): / 12-04-2019 / 12:05:34 / Stefan Vogel" |
|
12529 | 3317 |
! |
3318 |
||
3319 |
accessRights:opaqueData |
|
3320 |
"set the access rights of the file to opaqueData, |
|
3321 |
which is normally retrieved by Filename>>#accessRights." |
|
3322 |
||
21064 | 3323 |
|osErrorHolder| |
3324 |
||
3325 |
osErrorHolder := OperatingSystem changeAccessModeOf:self osNameForFile to:opaqueData. |
|
3326 |
osErrorHolder notNil ifTrue:[ |
|
3327 |
osErrorHolder reportProceedableError:'change access rights failed'. |
|
3328 |
]. |
|
3329 |
||
12529 | 3330 |
|
3331 |
" |
|
3332 |
|rights| |
|
3333 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3334 |
rights := 'Make.proto' asFilename accessRights. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3335 |
'Make.proto' asFilename accessRights:rights. |
12529 | 3336 |
" |
3337 |
||
3338 |
"Modified: / 5.5.1999 / 13:41:21 / cg" |
|
3339 |
! |
|
3340 |
||
615 | 3341 |
addAccessRights:aCollection |
3342 |
"add the access rights as specified in aCollection for the file represented |
|
3343 |
by the receiver. The argument must be a collection of symbols, |
|
3344 |
such as #readUser, #writeGroup etc." |
|
3345 |
||
21064 | 3346 |
|access osName osErrorHolder| |
2922 | 3347 |
|
2947 | 3348 |
osName := self osNameForFile. |
2922 | 3349 |
access := OperatingSystem accessModeOf:osName. |
21071 | 3350 |
access isOSErrorHolder ifTrue:[ |
3351 |
access reportProceedableError:'get access rights failed'. |
|
3352 |
]. |
|
3353 |
||
615 | 3354 |
aCollection do:[:accessSymbol | |
21064 | 3355 |
access := access bitOr:(OperatingSystem accessMaskFor:accessSymbol). |
3356 |
]. |
|
3357 |
osErrorHolder := OperatingSystem changeAccessModeOf:osName to:access. |
|
3358 |
osErrorHolder notNil ifTrue:[ |
|
3359 |
osErrorHolder reportProceedableError:'change access rights failed'. |
|
3360 |
]. |
|
615 | 3361 |
|
3362 |
" |
|
3363 |
'foo' asFilename writeStream close. |
|
3364 |
'foo' asFilename addAccessRights:#(readUser readGroup readOthers). |
|
3365 |
'foo' asFilename addAccessRights:#(writeUser writeGroup writeOthers). |
|
3366 |
'foo' asFilename addAccessRights:#(executeUser executeGroup executeOthers). |
|
3367 |
" |
|
3368 |
! |
|
3369 |
||
6223 | 3370 |
makeExecutable |
3371 |
"make the file executable - you must have permission to do so. |
|
3372 |
For directories, execution means: 'allow changing into it'" |
|
3373 |
||
3374 |
^ self addAccessRights:#(executeUser) |
|
3375 |
||
3376 |
"Created: 9.1.1996 / 15:32:47 / cg" |
|
3377 |
! |
|
3378 |
||
3379 |
makeExecutableForAll |
|
3380 |
"make the file executable for all - you must have permission to do so. |
|
3381 |
For directories, execution means: 'allow changing into it'" |
|
3382 |
||
3383 |
^ self addAccessRights:#(executeUser executeGroup executeOthers) |
|
3384 |
||
3385 |
"Created: 9.1.1996 / 15:32:28 / cg" |
|
3386 |
! |
|
3387 |
||
3388 |
makeExecutableForGroup |
|
3389 |
"make the file executable for the group - you must have permission to do so. |
|
3390 |
For directories, execution means: 'allow changing into it'" |
|
3391 |
||
3392 |
^ self addAccessRights:#(executeGroup) |
|
3393 |
||
3394 |
"Created: 9.1.1996 / 15:32:28 / cg" |
|
3395 |
! |
|
3396 |
||
3397 |
makeReadable |
|
3398 |
"make the file readable for the owner - you must have permission to do so." |
|
3399 |
||
3400 |
^ self addAccessRights:#(readUser) |
|
3401 |
! |
|
3402 |
||
3403 |
makeReadableForAll |
|
3404 |
"make the file readable for all - you must have permission to do so." |
|
3405 |
||
3406 |
^ self addAccessRights:#(readUser readGroup readOthers) |
|
3407 |
! |
|
3408 |
||
3409 |
makeReadableForGroup |
|
3410 |
"make the file readable for the group - you must have permission to do so." |
|
3411 |
||
3412 |
^ self addAccessRights:#(readGroup) |
|
3413 |
! |
|
3414 |
||
3415 |
makeUnwritable |
|
3416 |
"make the file unwritable for all - you must have permission to do so." |
|
3417 |
||
3418 |
^ self removeAccessRights:#(writeUser writeGroup writeOthers) |
|
3419 |
! |
|
3420 |
||
3421 |
makeWritable |
|
3422 |
"make the file writableable for all - you must have permission to do so." |
|
3423 |
||
3424 |
^ self addAccessRights:#(writeUser) |
|
3425 |
! |
|
3426 |
||
3427 |
makeWritableForAll |
|
3428 |
"make the file writable for all - you must have permission to do so." |
|
3429 |
||
3430 |
^ self addAccessRights:#(writeUser writeGroup writeOthers) |
|
3431 |
! |
|
3432 |
||
3433 |
makeWritableForGroup |
|
3434 |
"make the file writable for the group - you must have permission to do so." |
|
3435 |
||
3436 |
^ self addAccessRights:#(writeGroup) |
|
3437 |
! |
|
3438 |
||
3439 |
removeAccessRights:aCollection |
|
3440 |
"remove the access rights as specified in aCollection for the file represented |
|
3441 |
by the receiver. The argument must be a collection of symbols, |
|
3442 |
such as #readUser, #writeGroup etc. |
|
3443 |
Raises an exception if not successful." |
|
3444 |
||
21064 | 3445 |
|access osName osErrorHolder| |
6223 | 3446 |
|
3447 |
osName := self osNameForFile. |
|
3448 |
access := OperatingSystem accessModeOf:osName. |
|
21071 | 3449 |
access isOSErrorHolder ifTrue:[ |
3450 |
access reportProceedableError:'get access rights failed'. |
|
3451 |
]. |
|
3452 |
||
6223 | 3453 |
aCollection do:[:accessSymbol | |
21064 | 3454 |
access := access bitAnd:(OperatingSystem accessMaskFor:accessSymbol) bitInvert. |
3455 |
]. |
|
3456 |
osErrorHolder := OperatingSystem changeAccessModeOf:osName to:access. |
|
3457 |
osErrorHolder notNil ifTrue:[ |
|
3458 |
osErrorHolder reportProceedableError:'change access rights failed'. |
|
6223 | 3459 |
]. |
3460 |
||
3461 |
" |
|
3462 |
'foo' asFilename writeStream close. |
|
3463 |
'foo' asFilename removeAccessRights:#(readUser readGroup readOthers). |
|
3464 |
'foo' asFilename removeAccessRights:#(writeUser writeGroup writeOthers). |
|
3465 |
'foo' asFilename removeAccessRights:#(executeUser executeGroup executeOthers). |
|
3466 |
" |
|
3467 |
||
3468 |
"Modified: / 5.5.1999 / 13:41:21 / cg" |
|
3469 |
! |
|
3470 |
||
3471 |
symbolicAccessRights |
|
3472 |
"return the access rights of the file as a aCollection of access symbols. |
|
3473 |
The returned collection consists of symbols like: |
|
21071 | 3474 |
#readUser, #writeGroup etc." |
6223 | 3475 |
|
3476 |
|access osName| |
|
3477 |
||
3478 |
osName := self osNameForFile. |
|
3479 |
access := OperatingSystem accessModeOf:osName. |
|
21071 | 3480 |
access isOSErrorHolder ifTrue:[ |
3481 |
access reportProceedableError:'get access rights failed'. |
|
3482 |
]. |
|
6223 | 3483 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3484 |
^ |
21071 | 3485 |
#( readUser writeUser executeUser |
3486 |
readGroup writeGroup executeGroup |
|
3487 |
readOthers writeOthers executeOthers |
|
3488 |
) select:[:eachSymbolicAccessSymbol | |
|
3489 |
access bitTest:(OperatingSystem accessMaskFor:eachSymbolicAccessSymbol). |
|
3490 |
]. |
|
3491 |
||
3492 |
" |
|
3493 |
'Make.proto' asFilename symbolicAccessRights |
|
6223 | 3494 |
" |
3495 |
||
3496 |
"Modified: / 5.5.1999 / 13:41:21 / cg" |
|
3497 |
! |
|
3498 |
||
3499 |
symbolicAccessRights:aCollectionOfSymbols |
|
3500 |
"set the access rights of the file given a aCollection of access symbols. |
|
3501 |
The collection must consist of symbols like: |
|
21064 | 3502 |
#readUser, #writeGroup etc." |
3503 |
||
3504 |
|access osName osErrorHolder| |
|
6223 | 3505 |
|
3506 |
osName := self osNameForFile. |
|
3507 |
access := aCollectionOfSymbols inject:0 into:[:bitsSoFar :eachSymbolicAccessSymbol | |
|
21064 | 3508 |
bitsSoFar bitOr:(OperatingSystem accessMaskFor:eachSymbolicAccessSymbol) |
3509 |
]. |
|
3510 |
||
3511 |
osErrorHolder := OperatingSystem changeAccessModeOf:osName to:access. |
|
3512 |
osErrorHolder notNil ifTrue:[ |
|
3513 |
osErrorHolder reportProceedableError:'change access rights failed'. |
|
6223 | 3514 |
]. |
3515 |
||
3516 |
" |
|
3517 |
|rights| |
|
3518 |
||
21071 | 3519 |
rights := 'Make.proto' asFilename symbolicAccessRights. |
3520 |
'Make.proto' asFilename symbolicAccessRights:(rights , #(executeOthers)). |
|
6223 | 3521 |
" |
3522 |
||
3523 |
"Modified: / 5.5.1999 / 13:41:21 / cg" |
|
3524 |
! ! |
|
3525 |
||
3526 |
!Filename methodsFor:'file operations'! |
|
3527 |
||
23911 | 3528 |
appendTo:streamOrNewName |
3529 |
"append the file - the argument must be a stream or convertable to a filename. |
|
7329 | 3530 |
Raises an exception, if an error occurs." |
3531 |
||
23911 | 3532 |
|inStream outStream outStreamToClose resetBinary| |
3533 |
||
3534 |
resetBinary := false. |
|
7329 | 3535 |
inStream := self readStream. |
3536 |
[ |
|
23911 | 3537 |
streamOrNewName isStream ifTrue:[ |
3538 |
outStream := streamOrNewName. |
|
3539 |
resetBinary := (outStream binary:true) not. |
|
3540 |
outStream isBinary ifTrue:[ |
|
3541 |
"Transcript ignores the binary setting" |
|
3542 |
inStream binary. |
|
3543 |
] ifFalse:[ |
|
3544 |
resetBinary := false. |
|
3545 |
]. |
|
21064 | 3546 |
] ifFalse:[ |
23911 | 3547 |
outStream := outStreamToClose := streamOrNewName asFilename appendingWriteStream. |
3548 |
"switch both streams to binary mode, in order to use |
|
3549 |
a faster ExternalStream buffer in #copyToEndInto:" |
|
3550 |
outStream binary. |
|
3551 |
inStream binary. |
|
21064 | 3552 |
]. |
3553 |
||
3554 |
inStream copyToEndInto:outStream. |
|
7329 | 3555 |
] ensure:[ |
21064 | 3556 |
inStream close. |
23911 | 3557 |
outStreamToClose notNil ifTrue:[ |
3558 |
outStreamToClose close |
|
3559 |
] ifFalse:[ |
|
3560 |
resetBinary ifTrue:[ |
|
3561 |
outStream binary:false. |
|
3562 |
]. |
|
3563 |
]. |
|
3564 |
]. |
|
3565 |
||
3566 |
" |
|
3567 |
'Make.proto' asFilename appendTo:'/tmp/Makefile.foo'. |
|
3568 |
'Make.proto' asFilename appendTo:Transcript. |
|
3569 |
'Make.proto' asFilename appendTo:'/tmp/Makefile.foo' asFilename |
|
3570 |
'Make.proto' asFilename appendTo:'/dev/null' |
|
3571 |
" |
|
3572 |
||
3573 |
"Modified: / 23-12-1999 / 21:52:36 / cg" |
|
3574 |
"Modified (comment): / 13-03-2019 / 19:45:03 / Stefan Vogel" |
|
3575 |
! |
|
3576 |
||
3577 |
copyTo:streamOrNewName |
|
3578 |
"Copy the file's contents into another file or stream. |
|
3579 |
The argument must be a stream or convertable to a filename. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3580 |
Raises an exception, if an error occurs." |
615 | 3581 |
|
23911 | 3582 |
|inStream outStream outStreamToClose newFilename newNameAlreadyExists resetBinary| |
3583 |
||
3584 |
streamOrNewName isStream ifTrue:[ |
|
3585 |
outStream := streamOrNewName. |
|
3586 |
"Contents is not copied if the out stream represent same file as myself." |
|
3587 |
(outStream isFileStream |
|
3588 |
and:[outStream asFilename pathName = self pathName]) ifTrue:[ |
|
3589 |
^ self |
|
3590 |
]. |
|
3591 |
] ifFalse:[ |
|
3592 |
newFilename := streamOrNewName asFilename. |
|
3593 |
"Contents is not copied if newName represents the same file as myself." |
|
3594 |
newFilename pathName = self pathName ifTrue:[ |
|
3595 |
^ self |
|
3596 |
]. |
|
3597 |
newNameAlreadyExists := newFilename exists. |
|
3598 |
(newNameAlreadyExists and:[newFilename isDirectory]) ifTrue:[ |
|
3599 |
newFilename := newFilename construct:(self baseName). |
|
3600 |
newNameAlreadyExists := newFilename exists. |
|
3601 |
]. |
|
19957 | 3602 |
]. |
3603 |
||
615 | 3604 |
inStream := self readStream. |
17143 | 3605 |
inStream isNil ifTrue:[ |
19957 | 3606 |
"open failed, but somenone did a proceed for the OpenError. |
3607 |
Ignore this file but continue in order to copy the rest when |
|
3608 |
doing a recursive copy" |
|
3609 |
^ self. |
|
17143 | 3610 |
]. |
3611 |
||
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
3612 |
[ |
23911 | 3613 |
newFilename notNil ifTrue:[ |
3614 |
"argument is a name" |
|
3615 |
outStream := outStreamToClose := newFilename writeStream. |
|
3616 |
newNameAlreadyExists ifFalse:[ |
|
3617 |
"ignore the error - may occur when copying to a network drive" |
|
3618 |
OsError catch:[ |
|
3619 |
"would be nice to keep the access rights of the original test suite" |
|
3620 |
newFilename accessRights:self accessRights. |
|
3621 |
]. |
|
3622 |
]. |
|
3623 |
"switch both streams to binary mode, in order to use |
|
3624 |
a faster ExternalStream buffer in #copyToEndInto:" |
|
3625 |
outStream binary:true; buffered:false. |
|
3626 |
inStream binary:true. |
|
3627 |
] ifFalse:[ |
|
3628 |
"argument is a Stream" |
|
3629 |
resetBinary := (outStream binary:true) not. |
|
3630 |
outStream isBinary ifTrue:[ |
|
3631 |
"internalStreams ignore the binary setting..." |
|
3632 |
inStream binary:true. |
|
19957 | 3633 |
]. |
3634 |
]. |
|
23911 | 3635 |
|
3636 |
inStream buffered:false. |
|
19957 | 3637 |
inStream copyToEndInto:outStream. |
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
3638 |
] ensure:[ |
19957 | 3639 |
inStream close. |
23911 | 3640 |
outStreamToClose notNil ifTrue:[ |
3641 |
outStreamToClose close |
|
3642 |
] ifFalse:[ |
|
3643 |
resetBinary ifTrue:[ |
|
3644 |
outStream binary:false. |
|
3645 |
]. |
|
3646 |
]. |
|
615 | 3647 |
]. |
3648 |
||
3649 |
" |
|
12529 | 3650 |
'Make.proto' asFilename copyTo:'/tmp/Makefile.foo' |
23911 | 3651 |
'Make.proto' asFilename copyTo:'/tmp' |
3652 |
'Make.proto' asFilename copyTo:Transcript |
|
615 | 3653 |
'smalltalk' asFilename copyTo:'/dev/null' |
3654 |
" |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3655 |
|
10020 | 3656 |
"Modified: / 10-09-2004 / 09:49:28 / janfrog" |
19957 | 3657 |
"Modified: / 06-06-2016 / 12:15:25 / cg" |
23911 | 3658 |
"Modified: / 13-03-2019 / 22:51:26 / Stefan Vogel" |
615 | 3659 |
! |
3660 |
||
15465 | 3661 |
copyToStream:outStream |
23911 | 3662 |
"Copy the file's contents into outStream. |
15465 | 3663 |
Raises an exception, if an error occurs." |
3664 |
||
15858 | 3665 |
|inStream resetBinary| |
15465 | 3666 |
|
3667 |
"Contents is not copied if newName represent same file as me." |
|
23911 | 3668 |
(outStream isFileStream |
3669 |
and:[outStream fileName pathName = self pathName]) ifTrue:[ |
|
3670 |
^ self |
|
15465 | 3671 |
]. |
3672 |
||
3673 |
inStream := self readStream. |
|
3674 |
[ |
|
23911 | 3675 |
resetBinary := (outStream binary:true) not. |
3676 |
outStream isBinary ifTrue:[ |
|
3677 |
"internal streams ignore the #binary:true setting" |
|
3678 |
inStream binary:true. "inStream buffered:false." |
|
3679 |
]. |
|
3680 |
inStream copyToEndInto:outStream. |
|
15465 | 3681 |
] ensure:[ |
23911 | 3682 |
inStream close. |
3683 |
resetBinary ifTrue:[ |
|
3684 |
outStream binary:false. |
|
3685 |
]. |
|
15465 | 3686 |
]. |
3687 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3688 |
" |
15465 | 3689 |
|out| |
3690 |
out := FileStream newTemporary. |
|
3691 |
'Make.proto' asFilename copyToStream:out. |
|
3692 |
out reset; contents |
|
3693 |
" |
|
23911 | 3694 |
|
3695 |
"Modified: / 13-03-2019 / 19:57:11 / Stefan Vogel" |
|
15465 | 3696 |
! |
3697 |
||
6983 | 3698 |
createAsEmptyFile |
19440 | 3699 |
"create an empty file with the receiver's name. |
6983 | 3700 |
Raises an exception if not successful |
3701 |
(either already existing or creation not possible)" |
|
3702 |
||
3703 |
|writeStream| |
|
3704 |
||
3705 |
self exists ifTrue:[ |
|
24017 | 3706 |
OperatingSystem accessDeniedErrorSignal |
3707 |
raiseRequestWith:self |
|
3708 |
errorString:(' - file exists: ' , self asString). |
|
3709 |
^ self |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3710 |
]. |
6983 | 3711 |
|
3712 |
FileStream openErrorSignal handle:[:ex| |
|
24017 | 3713 |
self fileCreationError:self. |
3714 |
^ self |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3715 |
] do:[ |
24017 | 3716 |
writeStream := self newReadWriteStream. |
6983 | 3717 |
]. |
3718 |
writeStream close. |
|
3719 |
! |
|
3720 |
||
21064 | 3721 |
createAsHardLinkTo:linkFilenameString |
3722 |
"create a directory with the receiver's name. |
|
3723 |
Raises an exception if not successful" |
|
3724 |
||
3725 |
|errorHolder| |
|
3726 |
||
3727 |
errorHolder := OperatingSystem createHardLinkFrom:linkFilenameString asFilename osName to:self osName. |
|
3728 |
errorHolder notNil ifTrue:[ |
|
3729 |
errorHolder reportProceedableError:'hard link failed'. |
|
3730 |
]. |
|
3731 |
||
3732 |
" |
|
3733 |
'/tmp/link' asFilename createAsHardLinkTo:'bla' |
|
3734 |
" |
|
3735 |
! |
|
3736 |
||
17143 | 3737 |
createAsSymbolicLinkTo:linkFilenameString |
23057 | 3738 |
"create a symbolic link named linkFilenameString which points to me |
17143 | 3739 |
Raises an exception if not successful" |
3740 |
||
21064 | 3741 |
|errorHolder| |
3742 |
||
3743 |
errorHolder := OperatingSystem createSymbolicLinkFrom:linkFilenameString asFilename osName to:self osName. |
|
3744 |
errorHolder notNil ifTrue:[ |
|
3745 |
errorHolder reportError:'symbolic link failed'. |
|
3746 |
]. |
|
3747 |
||
3748 |
" |
|
3749 |
'/tmp/link' asFilename createAsSymbolicLinkTo:'bla' |
|
17143 | 3750 |
" |
23057 | 3751 |
|
3752 |
"Modified (comment): / 07-06-2018 / 17:16:01 / Claus Gittinger" |
|
17143 | 3753 |
! |
3754 |
||
615 | 3755 |
makeDirectory |
19440 | 3756 |
"create a directory with the receiver's name. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3757 |
Raises an exception if not successful" |
615 | 3758 |
|
21064 | 3759 |
|osErrorHolder| |
3760 |
||
3761 |
osErrorHolder := OperatingSystem createDirectory:(self osNameForDirectory). |
|
3762 |
osErrorHolder notNil ifTrue:[ |
|
3763 |
"/ |
|
3764 |
"/ could have existed before ... |
|
3765 |
"/ |
|
3766 |
(self exists and:[self isDirectory]) ifFalse:[ |
|
3767 |
osErrorHolder reportProceedableError:'make directory failed'. |
|
3768 |
] |
|
3769 |
]. |
|
3770 |
^ nil |
|
1970 | 3771 |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3772 |
"Modified: / 5.5.1999 / 13:36:33 / cg" |
615 | 3773 |
! |
3774 |
||
6996
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3775 |
moveFileTo:newName |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3776 |
"copy the file represented by the receiver, then delete it. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3777 |
This is different to renaming in case of cross device moves. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3778 |
Raise an exception if not successful. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3779 |
(Notice, that a rename is tried first, in case of non-cross device move)" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3780 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3781 |
[self renameTo:newName] |
24017 | 3782 |
on:OsError |
3783 |
do:[:ex | |
|
3784 |
ex creator == OperatingSystem fileNotFoundErrorSignal ifTrue:[ |
|
3785 |
ex reject |
|
3786 |
]. |
|
3787 |
self safeCopyTo:newName. |
|
3788 |
self remove |
|
3789 |
]. |
|
6996
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3790 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3791 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3792 |
|f s| |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3793 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3794 |
f := '/tmp/foo' asFilename. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3795 |
s := f writeStream. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3796 |
s nextPutLine:'hello'. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3797 |
s close. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3798 |
f renameTo:'./foo' |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3799 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3800 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3801 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3802 |
|f s| |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3803 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3804 |
f := '/tmp/foo' asFilename. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3805 |
s := f writeStream. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3806 |
s nextPutLine:'hello'. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3807 |
s close. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3808 |
f moveTo:'./foo' |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3809 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3810 |
! |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3811 |
|
16490 | 3812 |
moveTo:newNameArg |
615 | 3813 |
"copy the file represented by the receiver, then delete it. |
3814 |
This is different to renaming in case of cross device moves. |
|
5594
3d801043be3f
dont read the whole directory in #directoryContentsDo:
Claus Gittinger <cg@exept.de>
parents:
5577
diff
changeset
|
3815 |
Raise an exception if not successful. |
3d801043be3f
dont read the whole directory in #directoryContentsDo:
Claus Gittinger <cg@exept.de>
parents:
5577
diff
changeset
|
3816 |
(Notice, that a rename is tried first, in case of non-cross device move)" |
615 | 3817 |
|
16490 | 3818 |
|newName| |
3819 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3820 |
newName := newNameArg asFilename. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3821 |
[self renameTo:newName] |
24017 | 3822 |
on:(OSErrorHolder inappropriateReferentSignal) |
3823 |
do:[:ex | |
|
3824 |
"handle renames accross device boundaries (Unix. cross device link)" |
|
3825 |
self isDirectory ifTrue:[ |
|
3826 |
self recursiveMoveDirectoryTo:newName. |
|
3827 |
] ifFalse:[ |
|
3828 |
self safeCopyTo:newName. |
|
3829 |
self remove. |
|
3830 |
]. |
|
3831 |
]. |
|
5507
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3832 |
|
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3833 |
" |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3834 |
|f s| |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3835 |
|
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3836 |
f := '/tmp/foo' asFilename. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3837 |
s := f writeStream. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3838 |
s nextPutLine:'hello'. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3839 |
s close. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3840 |
f renameTo:'./foo' |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3841 |
" |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3842 |
|
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3843 |
" |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3844 |
|f s| |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3845 |
|
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3846 |
f := '/tmp/foo' asFilename. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3847 |
s := f writeStream. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3848 |
s nextPutLine:'hello'. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3849 |
s close. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3850 |
f moveTo:'./foo' |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3851 |
" |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3852 |
! |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3853 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3854 |
recursiveCopyTo:destination |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3855 |
"if I represent a regular file, copy it. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3856 |
Otherwise, copy the directory and recursively |
12975 | 3857 |
all of its subfiles/subdirectories. |
17143 | 3858 |
|
3859 |
Raises an exception if not successful. |
|
3860 |
Do not resolve symbolic links. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3861 |
If a whole directory is to be copied and the destination directory |
17143 | 3862 |
does not exist, it will be created." |
3863 |
||
3864 |
|ok destinationFilename| |
|
3865 |
||
3866 |
destinationFilename := destination asFilename. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3867 |
self isDirectory ifFalse:[ |
23911 | 3868 |
self copyTo:destinationFilename. |
3869 |
^ self. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3870 |
]. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3871 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3872 |
"/ typically, an 'cp -r' is faster; |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3873 |
"/ however, if the command fails (or the OS does not support it), |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3874 |
"/ fallBack doing a manual directory walk. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3875 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3876 |
ok := OperatingSystem |
23911 | 3877 |
recursiveCopyDirectory:(self osNameForDirectory) |
3878 |
to:(destinationFilename osNameForDirectory). |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3879 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3880 |
ok ifFalse:[ |
23911 | 3881 |
self recursiveCopyWithoutOSCommandTo:destinationFilename |
3882 |
]. |
|
3883 |
||
3884 |
" |
|
3885 |
'.' asFilename recursiveCopyTo:'/temp/xxx'. |
|
17143 | 3886 |
" |
3887 |
||
12975 | 3888 |
"Created: / 05-05-1999 / 13:35:01 / cg" |
3889 |
"Modified: / 31-05-1999 / 13:11:34 / cg" |
|
3890 |
"Modified: / 29-07-2010 / 12:41:06 / sr" |
|
23911 | 3891 |
"Modified: / 13-03-2019 / 20:04:44 / Stefan Vogel" |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3892 |
! |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3893 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3894 |
recursiveCopyWithoutOSCommandTo:destination |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3895 |
"if I represent a regular file, copy it. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3896 |
Otherwise, copy the directory and all of its subfiles/subdirectories. |
11192
828184f29182
recursiveCopyWithoutOSCommandTo: - if target does not exist,
Claus Gittinger <cg@exept.de>
parents:
11004
diff
changeset
|
3897 |
This one walks down the directory hierarchy, not using any OS command to do the copy. |
17143 | 3898 |
Raises an exception if not successful. |
3899 |
||
3900 |
Do not resolve symbolic links. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3901 |
If a whole directory is to be copied and the destination directory |
17143 | 3902 |
does not exist, it will be created." |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3903 |
|
12529 | 3904 |
|destinationFilename| |
3905 |
||
3906 |
destinationFilename := destination asFilename. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3907 |
|
23911 | 3908 |
self isDirectory ifFalse:[ |
3909 |
"plain file copy" |
|
3910 |
self copyTo:destinationFilename. |
|
3911 |
^ self. |
|
3912 |
]. |
|
3913 |
||
3914 |
"copy a whole directory tree" |
|
3915 |
||
3916 |
destinationFilename exists ifFalse:[ |
|
3917 |
destinationFilename makeDirectory. |
|
3918 |
OsError catch:[ |
|
3919 |
destinationFilename accessRights:self accessRights. |
|
21064 | 3920 |
]. |
23911 | 3921 |
]. |
3922 |
||
3923 |
self directoryContentsDo:[:aFilenameString | |
|
3924 |
|src srcInfo dst| |
|
3925 |
||
3926 |
src := self construct:aFilenameString. |
|
3927 |
dst := destinationFilename construct:aFilenameString. |
|
3928 |
||
3929 |
srcInfo := src linkInfo. |
|
3930 |
srcInfo isDirectory ifTrue:[ |
|
3931 |
src recursiveCopyWithoutOSCommandTo:dst |
|
3932 |
] ifFalse:[srcInfo isSymbolicLink ifTrue:[ |
|
3933 |
dst |
|
3934 |
remove; |
|
3935 |
createAsSymbolicLinkTo:srcInfo path. |
|
3936 |
] ifFalse:[ |
|
3937 |
src copyTo:dst. |
|
3938 |
]]. |
|
3939 |
]. |
|
3940 |
||
3941 |
" |
|
3942 |
'.' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3943 |
'smalltalk.rc' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3944 |
" |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3945 |
|
23667 | 3946 |
"Modified: / 31-05-1999 / 18:12:31 / cg" |
23911 | 3947 |
"Modified (format): / 13-03-2019 / 20:12:18 / Stefan Vogel" |
615 | 3948 |
! |
3949 |
||
659 | 3950 |
recursiveMakeDirectory |
18490 | 3951 |
"create a directory with the receiver's name and all required intermediate |
659 | 3952 |
directories. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3953 |
Raises an exception if not successful." |
659 | 3954 |
|
21064 | 3955 |
|osErrorHolder| |
3956 |
||
3957 |
osErrorHolder := OperatingSystem recursiveCreateDirectory:(self osNameForDirectory). |
|
3958 |
osErrorHolder notNil ifTrue:[ |
|
3959 |
osErrorHolder reportProceedableError:'recursive makedir failed'. |
|
3960 |
]. |
|
3961 |
||
3962 |
" |
|
3963 |
'k:\bla\quark' asFilename recursiveMakeDirectory |
|
3964 |
" |
|
659 | 3965 |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3966 |
"Created: / 27.11.1995 / 23:36:40 / cg" |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3967 |
"Modified: / 5.5.1999 / 13:38:42 / cg" |
21064 | 3968 |
|
3969 |
" |
|
3970 |
'C:\windows\bla\xx' asFilename recursiveMakeDirectory |
|
3971 |
'C:\windows\bla' asFilename recursiveRemoveAll |
|
3972 |
" |
|
659 | 3973 |
! |
3974 |
||
24008 | 3975 |
recursiveMakeDirectoryForEachCreatedDo:aOneArgBlock |
3976 |
"create a directory with the receiver's name and all required intermediate directories. |
|
3977 |
For each created directory evaluate aOneArgBlock with the |
|
3978 |
filename of the created directory. |
|
3979 |
||
3980 |
Raises an exception if not successful." |
|
3981 |
||
3982 |
|osErrorHolder| |
|
3983 |
||
3984 |
osErrorHolder := OperatingSystem |
|
3985 |
recursiveCreateDirectory:(self osNameForDirectory) |
|
3986 |
forEachCreatedDo:aOneArgBlock. |
|
3987 |
||
3988 |
osErrorHolder notNil ifTrue:[ |
|
3989 |
osErrorHolder reportProceedableError:'recursive makedir failed'. |
|
3990 |
]. |
|
3991 |
||
3992 |
" |
|
3993 |
'/tmp/bla/fasel/murks' asFilename recursiveMakeDirectoryForEachCreatedDo:[:name| Transcript show:'Created: '; showCR:name]. |
|
3994 |
'/tmp/bla' asFilename recursiveRemove. |
|
3995 |
||
3996 |
'k:\bla\quark' asFilename recursiveMakeDirectory |
|
3997 |
" |
|
3998 |
||
3999 |
"Created: / 27.11.1995 / 23:36:40 / cg" |
|
4000 |
"Modified: / 5.5.1999 / 13:38:42 / cg" |
|
4001 |
||
4002 |
" |
|
4003 |
'C:\windows\bla\xx' asFilename recursiveMakeDirectory |
|
4004 |
'C:\windows\bla' asFilename recursiveRemoveAll |
|
4005 |
" |
|
4006 |
! |
|
4007 |
||
6997 | 4008 |
recursiveMoveDirectoryTo:newName |
4009 |
"recursively copy the directory represented by the receiver, then delete it. |
|
4010 |
This is different to renaming in case of cross device moves. |
|
4011 |
Raise an exception if not successful. |
|
4012 |
(Notice, that a rename is tried first, in case of non-cross device move)" |
|
4013 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4014 |
[self renameTo:newName] |
24017 | 4015 |
on:OsError |
4016 |
do:[ |
|
4017 |
self recursiveCopyTo:newName. |
|
4018 |
self recursiveRemove |
|
4019 |
]. |
|
6997 | 4020 |
! |
4021 |
||
615 | 4022 |
recursiveRemove |
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
4023 |
"if I represent a regular file, remove it. |
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
4024 |
Otherwise, remove the directory and all of its subfiles/subdirectories. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
4025 |
Raise an exception if not successful." |
615 | 4026 |
|
4027 |
|ok| |
|
4028 |
||
3302 | 4029 |
"/ typically, an 'rm -rf' is faster and removes better; |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4030 |
"/ however, if the command fails (or the OS does not support it), |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
4031 |
"/ fallBack doing a manual directory walk. |
3302 | 4032 |
|
4033 |
ok := OperatingSystem recursiveRemoveDirectory:(self osNameForDirectory). |
|
4034 |
ok ifFalse:[ |
|
24017 | 4035 |
self recursiveRemoveWithoutOSCommand |
18952 | 4036 |
]. |
4037 |
||
4038 |
" |
|
4039 |
'foo/bar' asFilename recursiveMakeDirectory. |
|
4040 |
'foo' asFilename remove. |
|
4041 |
self assert:('foo' asFilename exists not). |
|
4042 |
||
4043 |
||
4044 |
'foo' asFilename recursiveRemove. |
|
4045 |
'foo/bar' asFilename recursiveMakeDirectory. |
|
4046 |
'foo' asFilename recursiveRemove. |
|
4047 |
self assert:('foo' asFilename exists not). |
|
3302 | 4048 |
" |
4049 |
||
4050 |
"Created: / 14.11.1995 / 11:19:29 / cg" |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
4051 |
"Modified: / 5.5.1999 / 13:43:35 / cg" |
3302 | 4052 |
! |
4053 |
||
13246 | 4054 |
recursiveRemoveAll |
13247
9e47a0e73ba4
comment/format in: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents:
13246
diff
changeset
|
4055 |
"Remove all of my subfiles/subdirectories. |
3302 | 4056 |
Raise an error if not successful. |
4057 |
This one walks down the directory hierarchy, not using any OS |
|
4058 |
command to do the remove." |
|
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
4059 |
|
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
4060 |
self isDirectory ifTrue:[ |
21064 | 4061 |
self directoryContentsAsFilenamesDo:[:eachFilename | |
4062 |
OsError handle:[:ex | |
|
4063 |
eachFilename isDirectory ifFalse:[ ex reject ]. |
|
4064 |
eachFilename |
|
4065 |
recursiveRemoveAll; |
|
4066 |
removeDirectory. |
|
4067 |
] do:[ |
|
4068 |
eachFilename remove |
|
4069 |
]. |
|
18952 | 4070 |
|
4071 |
"/ eachFilename isDirectory ifTrue:[ |
|
4072 |
"/ eachFilename recursiveRemoveWithoutOSCommand |
|
4073 |
"/ ] ifFalse:[ |
|
4074 |
"/ eachFilename remove |
|
4075 |
"/ ]. |
|
21064 | 4076 |
] |
615 | 4077 |
]. |
13246 | 4078 |
|
4079 |
" |
|
4080 |
'foo' asFilename makeDirectory. |
|
4081 |
'foo/bar' asFilename writeStream close. |
|
4082 |
'foo' asFilename remove |
|
4083 |
" |
|
4084 |
" |
|
4085 |
'foo' asFilename makeDirectory. |
|
4086 |
'foo/bar' asFilename writeStream close. |
|
18952 | 4087 |
'foo' asFilename recursiveRemove. |
4088 |
self assert:('foo' asFilename exists not). |
|
13246 | 4089 |
" |
4090 |
||
4091 |
"Created: / 25-01-2011 / 16:42:15 / cg" |
|
4092 |
! |
|
4093 |
||
4094 |
recursiveRemoveWithoutOSCommand |
|
4095 |
"if I represent a regular file, remove it. |
|
4096 |
Otherwise, remove the directory and all of its subfiles/subdirectories. |
|
4097 |
Raise an error if not successful. |
|
4098 |
This one walks down the directory hierarchy, not using any OS |
|
4099 |
command to do the remove." |
|
4100 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4101 |
self |
24017 | 4102 |
recursiveRemoveAll; |
4103 |
remove. |
|
615 | 4104 |
|
4105 |
" |
|
4106 |
'foo' asFilename makeDirectory. |
|
4107 |
'foo/bar' asFilename writeStream close. |
|
4940 | 4108 |
'foo' asFilename remove |
615 | 4109 |
" |
4110 |
" |
|
4111 |
'foo' asFilename makeDirectory. |
|
4112 |
'foo/bar' asFilename writeStream close. |
|
4940 | 4113 |
'foo' asFilename recursiveRemove |
615 | 4114 |
" |
4115 |
||
13246 | 4116 |
"Created: / 25-02-1998 / 19:50:40 / cg" |
13949 | 4117 |
"Modified: / 19-01-2012 / 17:18:28 / cg" |
615 | 4118 |
! |
4119 |
||
4120 |
remove |
|
845 | 4121 |
"remove the file/directory. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
4122 |
Raises an exception if not successful. |
845 | 4123 |
Use #recursiveRemove in order to (recursively) remove non empty directories." |
615 | 4124 |
|
21064 | 4125 |
|linkInfo osName osErrorHolder| |
8741 | 4126 |
|
18952 | 4127 |
osName := self osNameForAccess. |
21064 | 4128 |
osErrorHolder := OperatingSystem removeFile:osName. |
4129 |
osErrorHolder notNil ifTrue:[ |
|
4130 |
linkInfo := self linkInfo. |
|
4131 |
linkInfo isNil ifTrue:[ |
|
4132 |
"file does not exist - no error" |
|
4133 |
^ self. |
|
4134 |
] ifFalse:[linkInfo isDirectory ifTrue:[ |
|
4135 |
osErrorHolder := OperatingSystem removeDirectory:osName |
|
4136 |
]]. |
|
4137 |
osErrorHolder notNil ifTrue:[ |
|
4138 |
self exists ifTrue:[ |
|
4139 |
osErrorHolder reportProceedableError:'remove failed'. |
|
4140 |
] |
|
4141 |
] |
|
615 | 4142 |
]. |
4143 |
||
4144 |
" |
|
4145 |
(FileStream newFileNamed:'foo') close. |
|
4146 |
'foo' asFilename remove |
|
4147 |
" |
|
4148 |
||
4149 |
" |
|
4150 |
'foo' asFilename makeDirectory. |
|
4151 |
'foo/bar' asFilename writeStream close. |
|
8738 | 4152 |
'foo' asFilename remove. 'expect an exception' |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4153 |
'foo' asFilename recursiveRemove. |
615 | 4154 |
" |
4155 |
||
13793
3f1c660956ce
added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents:
13781
diff
changeset
|
4156 |
"Modified: / 20-11-1997 / 17:40:22 / stefan" |
3f1c660956ce
added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents:
13781
diff
changeset
|
4157 |
"Modified: / 11-10-2011 / 10:20:01 / cg" |
615 | 4158 |
! |
4159 |
||
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4160 |
removeDirectory |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4161 |
"remove the directory. |
21441 | 4162 |
Raises an exception if not successful (or if it's not a directory). |
5596 | 4163 |
Use #remove if it is not known if the receiver is a directory or file. |
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4164 |
Use #recursiveRemove in order to (recursively) remove non empty directories." |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4165 |
|
21064 | 4166 |
|osErrorHolder| |
4167 |
||
4168 |
osErrorHolder := OperatingSystem removeDirectory:self osNameForAccess. |
|
4169 |
osErrorHolder notNil ifTrue:[ |
|
4170 |
self exists ifTrue:[ |
|
4171 |
osErrorHolder reportProceedableError:'remove directory failed'. |
|
4172 |
]. |
|
4173 |
]. |
|
4174 |
||
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4175 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4176 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4177 |
(FileStream newFileNamed:'foo') close. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4178 |
'foo' asFilename removeDirectory |
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4179 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4180 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4181 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4182 |
'foo' asFilename writeStream close. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4183 |
'foo' asFilename removeDirectory |
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4184 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4185 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4186 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4187 |
'foo' asFilename makeDirectory. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4188 |
'foo/bar' asFilename writeStream close. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4189 |
('foo' asFilename remove) ifFalse:[ |
21064 | 4190 |
Transcript showCR:'could not remove foo' |
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4191 |
] |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4192 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4193 |
|
21441 | 4194 |
"Modified: / 20-11-1997 / 17:40:22 / stefan" |
4195 |
"Modified: / 05-05-1999 / 13:41:12 / cg" |
|
4196 |
"Modified (comment): / 13-02-2017 / 20:19:10 / cg" |
|
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4197 |
! |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4198 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4199 |
removeFile |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4200 |
"remove the file. |
21441 | 4201 |
Raises an exception if not successful (or if it's not a file). |
5596 | 4202 |
Use #remove if it is not known if the receiver is a directory or file. |
4203 |
Use #recursiveRemove in order to (recursively) remove non empty directories." |
|
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4204 |
|
21064 | 4205 |
|osErrorHolder| |
4206 |
||
4207 |
osErrorHolder := OperatingSystem removeFile:self osNameForAccess. |
|
4208 |
osErrorHolder notNil ifTrue:[ |
|
4209 |
self exists ifTrue:[ |
|
4210 |
osErrorHolder reportProceedableError:'remove of file failed'. |
|
4211 |
]. |
|
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4212 |
]. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4213 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4214 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4215 |
(FileStream newFileNamed:'foo') close. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4216 |
'foo' asFilename removeFile |
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4217 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4218 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4219 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4220 |
'foo' asFilename makeDirectory. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4221 |
'foo' asFilename removeFile |
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4222 |
" |
21441 | 4223 |
|
4224 |
"Modified (comment): / 13-02-2017 / 20:19:15 / cg" |
|
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4225 |
! |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
4226 |
|
21045 | 4227 |
renameTo:newName |
22503 | 4228 |
"rename the file - the argument must be convertable to a filename. |
15823 | 4229 |
Raises an exception if not successful. |
4230 |
If newName already exists, it will be replaced by myself." |
|
615 | 4231 |
|
21045 | 4232 |
|errorHolder| |
4233 |
||
4234 |
errorHolder := OperatingSystem |
|
4235 |
renameFile:(self osNameForFile) |
|
4236 |
to:(newName asFilename osNameForFile). |
|
4237 |
||
4238 |
errorHolder notNil ifTrue:[ |
|
4239 |
errorHolder |
|
4240 |
parameter:self; |
|
21064 | 4241 |
reportProceedableError:'rename failed'. |
615 | 4242 |
]. |
4243 |
||
4244 |
" |
|
4245 |
'/tmp/foo' asFilename renameTo:'/tmp/bar' |
|
21045 | 4246 |
'/tmp/' asFilename renameTo:'/etc/bar' |
21023 | 4247 |
'C:\windows' asFilename renameTo:'C:\win' |
615 | 4248 |
" |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
4249 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
4250 |
"Modified: / 5.5.1999 / 13:41:27 / cg" |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4251 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4252 |
|
15819 | 4253 |
safeCopyTo:newNameArg |
16578 | 4254 |
"Copy the file's contents into another file. |
22542 | 4255 |
Do it safe in an atomic operation which makes sure that no partially written file appears. |
15819 | 4256 |
The argument must be convertable to a filename. |
4257 |
Raises an exception, if an error occurs." |
|
4258 |
||
15823 | 4259 |
|newName inStream accessRights tempStream| |
15819 | 4260 |
|
4261 |
newName := newNameArg asFilename. |
|
4262 |
||
4263 |
"Contents is not copied if newName represent same file as me." |
|
4264 |
newName asAbsoluteFilename = self asAbsoluteFilename ifTrue: [ ^ self ]. |
|
4265 |
||
4266 |
inStream := self readStream. |
|
15823 | 4267 |
newName exists ifTrue:[ |
20252 | 4268 |
accessRights := newName accessRights. |
15819 | 4269 |
] ifFalse:[ |
20252 | 4270 |
accessRights := self accessRights. |
15819 | 4271 |
]. |
4272 |
||
4273 |
[ |
|
20252 | 4274 |
"let the temp filename start with a ~ to make it invisible" |
23623 | 4275 |
tempStream := FileStream newTemporaryIn:newName directory osNameForDirectory nameTemplate:'~%1_%2'. |
21064 | 4276 |
"ignore the error - may occur when copying to a network drive" |
4277 |
OsError catch:[ |
|
20252 | 4278 |
"would be nice to keep the access rights of the original file" |
4279 |
tempStream fileName accessRights:accessRights. |
|
4280 |
]. |
|
4281 |
||
4282 |
inStream binary; buffered:false. |
|
4283 |
tempStream binary; buffered:false. |
|
4284 |
[ |
|
4285 |
inStream copyToEndInto:tempStream. |
|
4286 |
] ifCurtailed:[ |
|
4287 |
tempStream close. |
|
4288 |
tempStream fileName remove. |
|
4289 |
tempStream := nil. |
|
4290 |
]. |
|
4291 |
tempStream syncData. |
|
15819 | 4292 |
] ensure:[ |
20252 | 4293 |
inStream close. |
4294 |
tempStream notNil ifTrue:[tempStream close]. |
|
15819 | 4295 |
]. |
4296 |
tempStream fileName renameTo:newName. |
|
4297 |
||
4298 |
" |
|
4299 |
'Make.proto' asFilename safeCopyTo:'/tmp/Makefile.foo' |
|
4300 |
'Make.proto' asFilename safeCopyTo:'/' |
|
4301 |
'smalltalk' asFilename safeCopyTo:'/xxxxxxxxxxxxxxxx/bla' |
|
4302 |
" |
|
4303 |
||
4304 |
"Modified: / 10-09-2004 / 09:49:28 / janfrog" |
|
4305 |
"Modified: / 29-09-2006 / 16:26:32 / cg" |
|
22542 | 4306 |
"Modified (comment): / 13-02-2018 / 11:59:48 / mawalch" |
23623 | 4307 |
"Modified: / 21-01-2019 / 16:01:21 / Stefan Vogel" |
15819 | 4308 |
! |
4309 |
||
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4310 |
truncateTo:newSize |
16578 | 4311 |
"change the file's size. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
4312 |
This may not be supported on all operating systems |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
4313 |
(raises an exception, if not)" |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4314 |
|
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
4315 |
(OperatingSystem truncateFile:self osNameForFile to:newSize) ifFalse:[ |
24017 | 4316 |
^ self reportError:'unsupported operation' with:self |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4317 |
] |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4318 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4319 |
" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4320 |
|s| |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4321 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4322 |
s := 'test' asFilename writeStream. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4323 |
s next:1000 put:$1. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4324 |
s close. |
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
4325 |
('test' asFilename fileSize) printCR. |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4326 |
'test' asFilename truncateTo:100. |
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
4327 |
('test' asFilename fileSize) printCR. |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4328 |
" |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
4329 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
4330 |
"Modified: / 5.5.1999 / 13:41:59 / cg" |
615 | 4331 |
! ! |
4332 |
||
4333 |
!Filename methodsFor:'file queries'! |
|
4334 |
||
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4335 |
accessTime |
16578 | 4336 |
"return a timeStamp containing the file's last access time." |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4337 |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4338 |
| i | |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4339 |
|
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4340 |
(i := self info) isNil ifTrue:[^ nil]. |
6793
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
4341 |
^ i accessTime |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4342 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4343 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4344 |
Filename currentDirectory accessTime |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4345 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4346 |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4347 |
"Created: / 9.7.1996 / 10:19:15 / cg" |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4348 |
"Modified: / 26.9.1997 / 13:05:51 / stefan" |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4349 |
"Modified: / 17.8.1998 / 10:23:44 / cg" |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4350 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4351 |
|
6977 | 4352 |
creationTime |
16578 | 4353 |
"return a timeStamp containing the file's creation time. |
6977 | 4354 |
NOTICE: only windoof distinguishes creation from modification; |
6978 | 4355 |
under unix, nil is returned (callers should fall back and use mod-time then" |
6977 | 4356 |
|
4357 |
|i| |
|
4358 |
||
4359 |
(i := self info) isNil ifTrue:[^ nil]. "/ non-existing |
|
6978 | 4360 |
^ i creationTime |
4361 |
||
4362 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4363 |
Filename currentDirectory creationTime |
6977 | 4364 |
" |
4365 |
||
4366 |
"Created: / 9.7.1996 / 10:18:59 / cg" |
|
4367 |
"Modified: / 26.9.1997 / 13:05:39 / stefan" |
|
4368 |
"Modified: / 14.8.1998 / 17:42:50 / cg" |
|
4369 |
! |
|
4370 |
||
615 | 4371 |
dates |
16578 | 4372 |
"return the file's modification and access times as an object (currently a dictionary) |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4373 |
that responds to the at: message with arguments |
615 | 4374 |
#modified, #accessed or #statusChanged." |
4375 |
||
2922 | 4376 |
|info dates osName| |
4377 |
||
2947 | 4378 |
osName := self osNameForAccess. |
2922 | 4379 |
info := OperatingSystem infoOf:osName. |
615 | 4380 |
info isNil ifTrue:[ |
24017 | 4381 |
"maybe this is a symbolic link with a broken link target. |
4382 |
Answer the dates of the link itself" |
|
4383 |
info := OperatingSystem linkInfoOf:osName. |
|
4384 |
info isNil ifTrue:[ |
|
4385 |
^ nil |
|
4386 |
] |
|
615 | 4387 |
]. |
4388 |
dates := IdentityDictionary new. |
|
6978 | 4389 |
dates at:#created put:(info creationTime). |
6793
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
4390 |
dates at:#modified put:(info modificationTime). |
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
4391 |
dates at:#accessed put:(info accessTime). |
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
4392 |
dates at:#statusChanged put:(info statusChangeTime). |
615 | 4393 |
^ dates |
4394 |
||
4395 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4396 |
Filename currentDirectory dates |
615 | 4397 |
'../regression' asFilename dates |
4398 |
" |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4399 |
|
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4400 |
"Modified: 1.11.1996 / 20:19:24 / cg" |
615 | 4401 |
! |
4402 |
||
4403 |
fileSize |
|
4404 |
"return the size of the file in bytes" |
|
4405 |
||
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4406 |
|i| |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4407 |
|
22395 | 4408 |
(i := self info) isNil ifTrue:[^ 0]. |
6794
498d85323172
use #fileSize instead of #size
Claus Gittinger <cg@exept.de>
parents:
6793
diff
changeset
|
4409 |
^ i fileSize |
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4410 |
|
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4411 |
"Modified: / 17.8.1998 / 10:23:46 / cg" |
615 | 4412 |
! |
4413 |
||
4414 |
fileType |
|
4415 |
"this returns a string describing the type of contents of |
|
4416 |
the file. This is done using the unix 'file' command, |
|
4417 |
(which usually is configurable by /etc/magic). |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4418 |
On non-unix systems, this may simply return 'file', |
2922 | 4419 |
not knowning about the contents. |
4420 |
Warning: |
|
23667 | 4421 |
Since the returned string differs among systems (and language settings), |
4422 |
it is only useful for user-information; |
|
4423 |
NOT as a tag to be used by a program." |
|
4424 |
||
4425 |
|info mime| |
|
3665 | 4426 |
|
4427 |
"/ since we cannot depend on a 'file' command being available, |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4428 |
"/ do the most obvious ones here. |
3665 | 4429 |
"/ (also useful since the 'file' command takes some time, and the code |
4430 |
"/ below is faster for common things like directories) |
|
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
4431 |
|
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4432 |
info := self linkInfo. |
9060 | 4433 |
info isNil ifTrue:[ |
23667 | 4434 |
^ 'removed' "/ could happen, when coming from a snapshot image |
9060 | 4435 |
]. |
4436 |
||
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4437 |
info isSymbolicLink ifTrue:[ |
23667 | 4438 |
^ 'symbolic link to ' , info path |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
4439 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4440 |
info isDirectory ifTrue:[ |
23667 | 4441 |
self isReadable ifFalse:[^ 'directory, unreadable']. |
4442 |
self isExecutable ifFalse:[^ 'directory, locked']. |
|
4443 |
^ 'directory' |
|
2573 | 4444 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4445 |
info isCharacterSpecial ifTrue:[ |
23667 | 4446 |
^ 'character device special file' |
3665 | 4447 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4448 |
info isBlockSpecial ifTrue:[ |
23667 | 4449 |
^ 'block device special file' |
3665 | 4450 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4451 |
info isSocket ifTrue:[ |
23667 | 4452 |
^ 'socket' |
3665 | 4453 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4454 |
info isFifo ifTrue:[ |
23667 | 4455 |
^ 'fifo' |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4456 |
]. |
3665 | 4457 |
|
1602 | 4458 |
self isReadable ifFalse:[^ 'unreadable']. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4459 |
info fileSize == 0 ifTrue:[^ 'empty']. |
1602 | 4460 |
|
17112 | 4461 |
"/ suffix := self suffix asLowercase. |
4462 |
"/ baseNm := self withoutSuffix baseName asLowercase. |
|
2922 | 4463 |
|
16755 | 4464 |
mime := self mimeTypeOfContents. |
4465 |
mime notNil ifTrue:[ |
|
23667 | 4466 |
"/ kludge to avoid making libview a prereq. of libbasic |
4467 |
(Smalltalk at:#MIMETypes) notNil ifTrue:[ |
|
4468 |
info := (Smalltalk at:#MIMETypes) fileInfoForMimeType:mime. |
|
4469 |
info notNil ifTrue:[^ info]. |
|
4470 |
]. |
|
1602 | 4471 |
]. |
2906 | 4472 |
^ 'file' |
615 | 4473 |
|
4474 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4475 |
'Makefile' asFilename fileType |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4476 |
'.' asFilename fileType |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4477 |
'/dev/null' asFilename fileType |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4478 |
'/usr/tmp' asFilename fileType |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4479 |
'/tmp/.X11-unix/X0' asFilename fileType |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4480 |
'smalltalk.rc' asFilename fileType |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4481 |
'bitmaps/SBrowser.xbm' asFilename fileType |
615 | 4482 |
" |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
4483 |
|
23667 | 4484 |
"Modified: / 21-07-1998 / 11:25:56 / cg" |
4485 |
"Modified (comment): / 06-02-2019 / 11:49:16 / Stefan Vogel" |
|
615 | 4486 |
! |
4487 |
||
2836 | 4488 |
id |
16578 | 4489 |
"return the file's/directory's file-id (inode number)" |
2836 | 4490 |
|
2947 | 4491 |
^ OperatingSystem idOf:(self osNameForAccess) |
2836 | 4492 |
|
4493 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4494 |
Filename currentDirectory id |
2836 | 4495 |
" |
4496 |
||
4497 |
"Modified: 9.7.1996 / 10:19:27 / cg" |
|
4498 |
"Created: 5.8.1997 / 19:26:01 / cg" |
|
4499 |
! |
|
4500 |
||
615 | 4501 |
info |
16578 | 4502 |
"return some object filled with the file's info; |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4503 |
the info (for which corresponding access methods are understood by |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4504 |
the returned object) is: |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4505 |
|
22401 | 4506 |
type - a symbol giving the files fileType |
4507 |
mode - numeric access mode |
|
4508 |
uid - owners user id |
|
4509 |
gid - owners group id |
|
4510 |
fileSize - files size |
|
4511 |
id - files number (i.e. inode number) |
|
20798 | 4512 |
accessed - last access time (as osTime-stamp) |
4513 |
modified - last modification time (as osTime-stamp) |
|
23152 | 4514 |
statusChangeTime - last status change (as osTime-stamp) |
615 | 4515 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4516 |
Some of the fields may be returned as nil on systems which do not provide |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4517 |
all of the information. |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4518 |
The minimum returned info (i.e. on all OS's) will consist of at least: |
20798 | 4519 |
modified |
4520 |
size |
|
4521 |
type |
|
4522 |
||
4523 |
Don't expect things like uid/gid/mode to be non-nil; write your application |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4524 |
to either handle nil values, |
615 | 4525 |
or (better) use one of isXXXX query methods. (Be prepared for DOS ...) |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4526 |
(i.e. instead of: |
20798 | 4527 |
someFilename type == #directory |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4528 |
use |
20798 | 4529 |
someFilename isDirectory |
615 | 4530 |
" |
4531 |
||
2947 | 4532 |
^ OperatingSystem infoOf:(self osNameForAccess) |
615 | 4533 |
|
4534 |
" |
|
4535 |
Filename currentDirectory info |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4536 |
'/dev/null' asFilename info |
615 | 4537 |
'Make.proto' asFilename info |
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4538 |
'source/Point.st' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4539 |
'source/Point.st' asFilename linkInfo |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4540 |
'../../libbasic/Point.st' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4541 |
'.' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4542 |
'..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4543 |
'..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4544 |
'..\..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4545 |
'..\..\..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4546 |
'c:\' asFilename info |
615 | 4547 |
" |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4548 |
|
16272 | 4549 |
"Modified: / 17-08-1998 / 10:24:10 / cg" |
4550 |
"Modified (comment): / 21-03-2014 / 00:35:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
23152 | 4551 |
"Modified (comment): / 29-06-2018 / 09:54:46 / Claus Gittinger" |
615 | 4552 |
! |
4553 |
||
4554 |
linkInfo |
|
16578 | 4555 |
"return the file's info. If it is a symbolic link return the info of the link itself |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4556 |
instead of the link's target. |
615 | 4557 |
The information is the same as returned by #info, except that if the |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4558 |
receiver represents a symbolic link, the links information |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4559 |
is returned |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4560 |
(while in this case, #info returns the info of the target file, |
615 | 4561 |
which is accessed via the symbolic link). |
4562 |
||
4563 |
In addition to the normal entries, Unix returns an additional entry: |
|
24017 | 4564 |
path -> the target files pathname |
615 | 4565 |
|
4566 |
See the comment in #info for more details." |
|
4567 |
||
2947 | 4568 |
^ OperatingSystem linkInfoOf:(self osNameForAccess) |
615 | 4569 |
|
4570 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4571 |
Filename currentDirectory linkInfo |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4572 |
'/dev/null' asFilename linkInfo |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4573 |
'Make.proto' asFilename linkInfo |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4574 |
'Make.proto' asFilename linkInfo path |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4575 |
'source/Point.st' asFilename linkInfo |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4576 |
'../../libbasic/Point.st' asFilename linkInfo |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4577 |
'/usr/tmp' asFilename linkInfo |
615 | 4578 |
" |
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
4579 |
|
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
4580 |
"Modified: 1.11.1996 / 20:49:09 / cg" |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4581 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4582 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4583 |
modificationTime |
16578 | 4584 |
"return a timeStamp containing the file's modification time." |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4585 |
|
3763
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
4586 |
|i| |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
4587 |
|
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
4588 |
(i := self info) isNil ifTrue:[^ nil]. "/ non-existing |
6793
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
4589 |
^ i modificationTime |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4590 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4591 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4592 |
Filename currentDirectory modificationTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4593 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4594 |
|
3763
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
4595 |
"Created: / 9.7.1996 / 10:18:59 / cg" |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
4596 |
"Modified: / 26.9.1997 / 13:05:39 / stefan" |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
4597 |
"Modified: / 14.8.1998 / 17:42:50 / cg" |
2836 | 4598 |
! |
4599 |
||
4600 |
type |
|
23420 | 4601 |
"return the symbolic type of the file. |
4602 |
For symbolic links it is the type of the linked-to file." |
|
2836 | 4603 |
|
2947 | 4604 |
^ OperatingSystem typeOf:(self osNameForAccess) |
2836 | 4605 |
|
4606 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4607 |
Filename currentDirectory type |
2836 | 4608 |
" |
4609 |
||
4610 |
"Modified: 9.7.1996 / 10:19:27 / cg" |
|
4611 |
"Created: 5.8.1997 / 19:31:26 / cg" |
|
615 | 4612 |
! ! |
4613 |
||
4614 |
!Filename methodsFor:'file utilities'! |
|
4615 |
||
4616 |
edit |
|
4617 |
"start an editView on the file represented by the receiver" |
|
4618 |
||
4619 |
EditTextView openOn:self asString |
|
4620 |
||
4621 |
" |
|
4622 |
'smalltalk.rc' asFilename edit |
|
4623 |
" |
|
4624 |
! |
|
4625 |
||
4626 |
fileIn |
|
13424 | 4627 |
"load source code from the file" |
4628 |
||
4629 |
^ (ProgrammingLanguage forFile: self) fileIn: self |
|
4630 |
||
4631 |
"Modified: / 16-08-2009 / 13:27:36 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
542 | 4632 |
! ! |
4633 |
||
23506 | 4634 |
|
2 | 4635 |
!Filename methodsFor:'instance creation'! |
4636 |
||
10969
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4637 |
/ subname |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4638 |
"Same as construct: Taking the receiver as a directory name, construct a new |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4639 |
filename for an entry within this directory |
10969
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4640 |
(i.e. for a file or a subdirectory in that directory). |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4641 |
The argument may not specify an absolute path name. |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4642 |
Please do not use this to create filenames with suffixes, |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4643 |
since some systems require special naming conventions. |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4644 |
See also: #withSuffix: (which is different, but often needed). |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4645 |
Thanks to Jan Vrany for this idea." |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4646 |
|
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4647 |
^ self construct:subname |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4648 |
|
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4649 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4650 |
'/tmp' asFilename / 'foo' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4651 |
'/' asFilename / 'foo' / 'bar' / 'baz' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4652 |
'/foo/bar' asFilename / ('baz' asFilename) |
10969
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4653 |
|
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4654 |
Bad example; works on UNIX, but may not on others: |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4655 |
'foo/bar.baz' / '.suff' |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4656 |
" |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4657 |
! |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4658 |
|
615 | 4659 |
construct:subname |
4660 |
"taking the receiver as a directory name, construct a new |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4661 |
filename for an entry within this directory |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4662 |
(i.e. for a file or a subdirectory in that directory). |
2922 | 4663 |
The argument may not specify an absolute path name. |
4664 |
Please do not use this to create filenames with suffixes, |
|
4665 |
since some systems require special naming conventions. |
|
4666 |
See also: #withSuffix: (which is different, but often needed)." |
|
615 | 4667 |
|
11784 | 4668 |
|constructedName| |
4669 |
||
4670 |
constructedName := self constructString:subname. |
|
15811 | 4671 |
^ self species named:constructedName. |
615 | 4672 |
|
4673 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4674 |
'/tmp' asFilename construct:'foo' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4675 |
'/' asFilename construct:'foo' |
615 | 4676 |
'/usr/tmp' asFilename construct:'foo' |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4677 |
'/foo/bar' asFilename construct:'baz' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4678 |
'/foo/bar' asFilename construct:'baz' asFilename |
2922 | 4679 |
|
4680 |
Bad example; works on UNIX, but may not on others: |
|
11784 | 4681 |
'foo/bar.baz' asFilename construct:'.suff' |
615 | 4682 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4683 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4684 |
"Modified: 29.2.1996 / 20:55:06 / cg" |
2911 | 4685 |
! |
4686 |
||
2922 | 4687 |
constructDirectory:subname |
4688 |
"same as #construct: on most systems. |
|
4689 |
(may allow different/relaxed name syntax of the argument on some systems)" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4690 |
|
15811 | 4691 |
^ self species named:(self constructDirectoryString:subname) |
2922 | 4692 |
! |
4693 |
||
4694 |
constructDirectoryString:subName |
|
4695 |
"same as #constructString: on most systems. |
|
4696 |
(may allow different/relaxed name syntax of the argument on some systems)" |
|
4697 |
||
4698 |
^ self constructString:subName |
|
4699 |
! |
|
4700 |
||
4701 |
constructString:subName |
|
2911 | 4702 |
"taking the receiver as a directory name, construct a new |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4703 |
filename-string for an entry within this directory |
2922 | 4704 |
(i.e. for a file or a subdirectory in that directory). |
2960 | 4705 |
The argument may not specify an absolute path name. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4706 |
The code below works for UNIX & MSDOS; |
2960 | 4707 |
other filename classes (i.e. VMS) may want to redefine this method." |
4708 |
||
4709 |
|sepString sub| |
|
4710 |
||
4711 |
sub := subName asString. |
|
20069 | 4712 |
nameString size == 0 ifTrue:[ |
4713 |
^ sub |
|
4714 |
]. |
|
15811 | 4715 |
sepString := self species separatorString. |
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
4716 |
(nameString endsWith:sepString) ifTrue:[ |
20069 | 4717 |
^ nameString , sub |
6247 | 4718 |
]. |
2960 | 4719 |
^ nameString , sepString , sub |
2911 | 4720 |
|
4721 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4722 |
'/tmp' asFilename constructString:'foo' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4723 |
'/' asFilename constructString:'foo' |
2911 | 4724 |
'/usr/tmp' asFilename constructString:'foo' |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4725 |
'/foo/bar' asFilename constructString:'baz' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4726 |
'' asFilename constructString:'baz' |
2911 | 4727 |
" |
4728 |
||
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
4729 |
"Modified: / 7.9.1995 / 10:15:22 / claus" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
4730 |
"Created: / 9.9.1997 / 08:57:08 / cg" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
4731 |
"Modified: / 20.1.1998 / 15:58:23 / md" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
4732 |
"Modified: / 27.7.1998 / 19:47:51 / cg" |
2944
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4733 |
! |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4734 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4735 |
filenameFor:fileName |
6973 | 4736 |
"return a filename representing the argument, fileName |
4737 |
either in myself (if the arg is a releative path) or absolute otherwise." |
|
2944
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4738 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4739 |
|f| |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4740 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4741 |
f := fileName asFilename. |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4742 |
f isAbsolute ifTrue:[^ f]. |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4743 |
^ (self construct:fileName) |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4744 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4745 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4746 |
'/tmp' asFilename filenameFor:'foo' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4747 |
'/tmp' asFilename filenameFor:'/foo' |
2944
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4748 |
" |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4749 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4750 |
"Created: 18.9.1997 / 14:34:14 / stefan" |
9263 | 4751 |
! |
4752 |
||
4753 |
secureConstruct:subname |
|
4754 |
"taking the receiver as a directory name, construct a new |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4755 |
filename for an entry within this directory |
9263 | 4756 |
(i.e. for a file or a subdirectory in that directory). |
4757 |
The argument may not specify an absolute path name. |
|
4758 |
Please do not use this to create filenames with suffixes, |
|
4759 |
since some systems require special naming conventions. |
|
4760 |
See also: #withSuffix: (which is different, but often needed). |
|
4761 |
||
4762 |
This method differs from #construct:, by not permitting subName |
|
22927 | 4763 |
to navigate above the current filename (via '..') and is used eg. |
4764 |
by the documentation viewer and other services to prevent remote |
|
4765 |
access outside some predefined root folder." |
|
9263 | 4766 |
|
15811 | 4767 |
^ self species named:(self secureConstructString:subname) |
9263 | 4768 |
|
4769 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4770 |
'/tmp' asFilename secureConstruct:'foo' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4771 |
'/tmp' asFilename secureConstruct:'../foo' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4772 |
'/tmp' asFilename secureConstruct:'/./foo' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4773 |
'/tmp' asFilename secureConstruct:'foo/../bar' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4774 |
'/' asFilename secureConstruct:'foo' |
9263 | 4775 |
'/usr/tmp' asFilename secureConstruct:'foo' |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4776 |
'/foo/bar' asFilename secureConstruct:'baz' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4777 |
'/foo/bar' asFilename secureConstruct:'baz' asFilename |
9263 | 4778 |
|
4779 |
Bad example; works on UNIX, but may not on others: |
|
4780 |
'foo/bar.baz' secureConstruct:'.suff' |
|
4781 |
" |
|
4782 |
||
4783 |
"Modified: 29.2.1996 / 20:55:06 / cg" |
|
4784 |
! |
|
4785 |
||
4786 |
secureConstructString:subName |
|
4787 |
"taking the receiver as a directory name, construct a new |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4788 |
filename-string for an entry within this directory |
9263 | 4789 |
(i.e. for a file or a subdirectory in that directory). |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4790 |
|
22927 | 4791 |
This method differs from #constructString:, by not permitting subName |
4792 |
to navigate above the current filename (via '..') and is used eg. |
|
4793 |
by the documentation viewer and other services to prevent remote |
|
4794 |
access outside some predefined root folder. |
|
9263 | 4795 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4796 |
The code below works for UNIX & MSDOS; |
22927 | 4797 |
other filename classes (i.e. VMS) have to redefine this method." |
9263 | 4798 |
|
4799 |
|sepString sub normalizedPath pathStream| |
|
4800 |
||
15811 | 4801 |
sepString := self species separatorString. |
9263 | 4802 |
sub := subName asString. |
4803 |
||
4804 |
sub := sub asCollectionOfSubstringsSeparatedByAll:sepString. |
|
4805 |
normalizedPath := OrderedCollection new:sub size. |
|
4806 |
sub do:[:eachPathComponent| |
|
22927 | 4807 |
eachPathComponent = '..' ifTrue:[ |
4808 |
normalizedPath isEmpty ifTrue:[ |
|
4809 |
self error:'secureConstruct: - trying to escape from: ', nameString. |
|
4810 |
]. |
|
4811 |
normalizedPath removeLast. |
|
4812 |
] ifFalse:[(eachPathComponent notEmpty and:[eachPathComponent ~= '.']) ifTrue:[ |
|
4813 |
normalizedPath add:eachPathComponent. |
|
4814 |
]] |
|
9263 | 4815 |
]. |
18272 | 4816 |
pathStream := CharacterWriteStream with:nameString. |
9263 | 4817 |
(nameString notEmpty and:[(nameString endsWith:sepString) not]) ifTrue:[ |
22927 | 4818 |
pathStream nextPutAll:sepString. |
9263 | 4819 |
]. |
4820 |
normalizedPath do:[:eachPathComponent| |
|
22927 | 4821 |
pathStream nextPutAll:eachPathComponent. |
9263 | 4822 |
] separatedBy:[ |
22927 | 4823 |
pathStream nextPutAll:sepString. |
9263 | 4824 |
]. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4825 |
|
9263 | 4826 |
^ pathStream contents. |
4827 |
||
4828 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4829 |
'/tmp' asFilename secureConstructString:'fooÅ ' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4830 |
'/tmp' asFilename secureConstructString:'../foo' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4831 |
'/tmp' asFilename secureConstructString:'foo/../bla' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4832 |
'/tmp' asFilename secureConstructString:'foo/./bla' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4833 |
'/tmp' asFilename secureConstructString:'/bla/foo/../../foo' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4834 |
'/' asFilename secureConstructString:'foo' |
9263 | 4835 |
'/usr/tmp' asFilename secureConstructString:'foo' |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4836 |
'/foo/bar' asFilename secureConstructString:'baz' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4837 |
'' asFilename secureConstructString:'baz' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4838 |
'' asFilename secureConstructString:'/baz' |
9263 | 4839 |
" |
2 | 4840 |
! ! |
4841 |
||
195 | 4842 |
!Filename methodsFor:'misc'! |
4843 |
||
4844 |
, aString |
|
4845 |
"this allows filenames to understand how names are concatenated. |
|
14072 | 4846 |
Returns a string consisting of the receiver's name, concatenated |
195 | 4847 |
by aString. Notice this is NOT the same as construct:, which inserts |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4848 |
a directory delimiter and returns a new fileName instance. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4849 |
See also: #withSuffix: which is new and better." |
195 | 4850 |
|
5866 | 4851 |
<resource:#obsolete> |
4852 |
||
2906 | 4853 |
self obsoleteMethodWarning:'use #construct:'. |
308 | 4854 |
^ (nameString , aString asString) |
195 | 4855 |
|
4856 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4857 |
'Makefile' asFilename , '.bak' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4858 |
('Makefile' asFilename , '.bak') asFilename |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4859 |
'Makefile' asFilename withSuffix:'bak' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4860 |
'Makefile' asFilename construct:'.bak' |
195 | 4861 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4862 |
|
14072 | 4863 |
"Modified: / 07-09-1997 / 23:45:36 / cg" |
4864 |
"Modified (comment): / 01-04-2012 / 13:18:21 / cg" |
|
9263 | 4865 |
! |
4866 |
||
4867 |
canonicalize |
|
4868 |
"normalize a filename by removing all empty path components or dots, |
|
4869 |
and by resolving parent directory '..' references. |
|
4870 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4871 |
The code below works for UNIX & MSDOS; |
9263 | 4872 |
other filename classes (i.e. VMS) may want to redefine this method." |
4873 |
||
15811 | 4874 |
nameString := self species canonicalize:nameString. |
9263 | 4875 |
|
4876 |
" |
|
24017 | 4877 |
'/tmp/bla' asFilename canonicalize. |
4878 |
'/tmp/bla/../fasel' asFilename canonicalize. |
|
4879 |
'/tmp/bla/.././/fasel' asFilename canonicalize. |
|
4880 |
'..' asFilename canonicalize. |
|
4881 |
'bla/../fasel' asFilename canonicalize. |
|
4882 |
'//bla/../fasel' asFilename canonicalize. |
|
9263 | 4883 |
" |
195 | 4884 |
! ! |
4885 |
||
14232 | 4886 |
!Filename methodsFor:'os shell'! |
4887 |
||
4888 |
openExplorer |
|
4889 |
"open a file-explorer on the directory represented by the receiver. |
|
22656 | 4890 |
On osx systems, a finder is opened. |
4891 |
On other systems, a filebrowser is opened" |
|
14232 | 4892 |
|
4893 |
OperatingSystem |
|
22396 | 4894 |
openApplicationForDocument:self pathName |
4895 |
operation:#explore. |
|
4896 |
||
4897 |
" |
|
22656 | 4898 |
Filename currentDirectory openExplorer |
22396 | 4899 |
" |
14232 | 4900 |
|
4901 |
"Created: / 21-07-2012 / 12:28:18 / cg" |
|
22396 | 4902 |
"Modified: / 20-12-2017 / 21:34:41 / stefan" |
14804 | 4903 |
! |
4904 |
||
4905 |
openFinder |
|
4906 |
"open a finder on the directory represented by the receiver. |
|
4907 |
On non-osx systems, an error is raised" |
|
4908 |
||
4909 |
OperatingSystem isOSXlike ifFalse:[ |
|
24017 | 4910 |
self warn:'sorry - this operation is only available under osx'. |
14804 | 4911 |
]. |
4912 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4913 |
OperatingSystem executeCommand:'open "',self pathName,'"' |
14804 | 4914 |
! |
4915 |
||
4916 |
openTerminal |
|
16545 | 4917 |
"open a terminal window on the directory represented by the receiver; |
4918 |
on osx, a terminal app is opened, |
|
4919 |
on windows a cmd.exe window, |
|
4920 |
on unix, an xterm is opened." |
|
4921 |
||
4922 |
OperatingSystem isOSXlike ifTrue:[ |
|
20798 | 4923 |
"/ I don't know yet how to tell the terminal to |
20678 | 4924 |
"/ go to a particular directory. |
4925 |
"/ therefore, use the built in terminal |
|
4926 |
VT100TerminalView openShellIn:self pathName. |
|
4927 |
^ self. |
|
4928 |
]. |
|
4929 |
"/ using the code below seems to close the window immediately |
|
4930 |
"/ at least on win7. |
|
4931 |
"/ use out own terminal, to make sure. |
|
4932 |
(OperatingSystem isMSWINDOWSlike |
|
4933 |
and:[OperatingSystem isWin7Like]) ifTrue:[ |
|
20798 | 4934 |
"/ I don't know yet how to tell the terminal to |
20678 | 4935 |
"/ go to a particular directory. |
4936 |
"/ therefore, use the built in terminal |
|
4937 |
VT100TerminalView openShellIn:self pathName. |
|
4938 |
^ self. |
|
16545 | 4939 |
]. |
14804 | 4940 |
|
14941 | 4941 |
[ |
20678 | 4942 |
|cmd| |
4943 |
||
4944 |
OperatingSystem isOSXlike ifTrue:[ |
|
4945 |
cmd := '/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal ' |
|
4946 |
] ifFalse:[ |
|
4947 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
|
4948 |
cmd := #('c:\windows\System32\cmd.exe') |
|
4949 |
] ifFalse:[ |
|
4950 |
"/ VT100TerminalView openShellIn:self pathName |
|
4951 |
cmd := 'xterm' |
|
4952 |
] |
|
4953 |
]. |
|
4954 |
OperatingSystem |
|
4955 |
executeCommand:cmd |
|
4956 |
inDirectory:self pathName |
|
4957 |
showWindow:#default. |
|
14941 | 4958 |
] fork |
20678 | 4959 |
|
4960 |
"Modified: / 18-10-2016 / 16:08:15 / cg" |
|
14232 | 4961 |
! ! |
4962 |
||
615 | 4963 |
!Filename methodsFor:'printing & storing'! |
174 | 4964 |
|
21496 | 4965 |
displayOn:aStream |
4392 | 4966 |
"append a user printed representation of the receiver to aStream. |
4967 |
The format is suitable for a human - not meant to be read back." |
|
174 | 4968 |
|
2906 | 4969 |
aStream nextPutAll:(self class name). |
4970 |
aStream nextPutAll:'('''. |
|
615 | 4971 |
nameString printOn:aStream. |
4972 |
aStream nextPutAll:''')' |
|
2906 | 4973 |
|
21496 | 4974 |
"Created: / 21-02-2017 / 09:02:34 / cg" |
4975 |
! |
|
4976 |
||
4977 |
printOn:aStream |
|
4978 |
"append a user printed representation of the receiver to aStream. |
|
4979 |
The format is suitable for a human - not meant to be read back. |
|
4980 |
Here, I print myself as a string, so I can be easily embedded in bind-with strings." |
|
4981 |
||
4982 |
"/ aStream nextPutAll:(self class name). |
|
4983 |
"/ aStream nextPutAll:'('''. |
|
4984 |
nameString printOn:aStream. |
|
4985 |
"/ aStream nextPutAll:''')' |
|
4986 |
||
4987 |
"Modified (comment): / 21-02-2017 / 09:03:57 / cg" |
|
1 | 4988 |
! |
4989 |
||
615 | 4990 |
storeOn:aStream |
4991 |
"append a printed representation of the receiver to aStream, |
|
4992 |
which allows reconstructing it via readFrom:" |
|
328 | 4993 |
|
615 | 4994 |
aStream nextPut:$(. |
4995 |
nameString storeOn:aStream. |
|
4996 |
aStream nextPutAll:' asFilename)' |
|
1 | 4997 |
! ! |
4998 |
||
7258 | 4999 |
!Filename methodsFor:'private-accessing'! |
1 | 5000 |
|
6227 | 5001 |
getName |
21263 | 5002 |
<resource: #obsolete> |
6227 | 5003 |
"get the raw filename" |
5004 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5005 |
^ nameString |
6227 | 5006 |
! |
5007 |
||
21263 | 5008 |
nameString |
5009 |
"raw access to nameString - req'd for xml-store/reload" |
|
5010 |
||
5011 |
^ nameString |
|
5012 |
! |
|
5013 |
||
5014 |
nameString:aString |
|
5015 |
"raw access to nameString - req'd for xml-store/reload" |
|
5016 |
||
5017 |
nameString := aString |
|
5018 |
! |
|
5019 |
||
68 | 5020 |
setName:aString |
38 | 5021 |
"set the filename" |
5022 |
||
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
5023 |
nameString := aString. |
3666 | 5024 |
|
5025 |
"Modified: / 21.7.1998 / 10:44:18 / cg" |
|
1 | 5026 |
! ! |
5027 |
||
2 | 5028 |
!Filename methodsFor:'queries'! |
5029 |
||
23393 | 5030 |
directories |
5031 |
"return a collection of directories contained in the directory represented by the receiver." |
|
5032 |
||
5033 |
^ OrderedCollection withCollectedContents:[:coll | |
|
5034 |
self directoriesDo:[:eachDirectory | coll add:eachDirectory]] |
|
5035 |
||
5036 |
" |
|
5037 |
'.' asFilename directories. |
|
5038 |
" |
|
5039 |
||
5040 |
"Modified: / 29-05-2007 / 12:02:56 / cg" |
|
5041 |
! |
|
5042 |
||
68 | 5043 |
exists |
92 | 5044 |
"return true, if such a file exists." |
68 | 5045 |
|
2947 | 5046 |
^ OperatingSystem isValidPath:(self osNameForAccess) |
68 | 5047 |
|
85 | 5048 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5049 |
'/foo/bar' asFilename exists |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5050 |
'/tmp' asFilename exists |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5051 |
'Makefile' asFilename exists |
85 | 5052 |
" |
77 | 5053 |
! |
5054 |
||
5928 | 5055 |
filenamesMatching:aPattern |
5056 |
"VW compatibility" |
|
5057 |
||
15811 | 5058 |
^ (self filesMatching:aPattern) |
24017 | 5059 |
collect:[:eachName | self construct:eachName]. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5060 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5061 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5062 |
'/etc' asFilename filenamesMatching:'a*;c*' |
5928 | 5063 |
" |
5064 |
||
5065 |
"Created: / 15.4.1997 / 15:40:02 / cg" |
|
5066 |
"Modified: / 3.8.1998 / 21:22:15 / cg" |
|
5067 |
! |
|
5068 |
||
23393 | 5069 |
files |
5070 |
"return a collection of regular files |
|
5071 |
contained in the directory represented by the receiver." |
|
5072 |
||
5073 |
^ OrderedCollection withCollectedContents:[:coll | |
|
5074 |
self filesDo:[:eachFileName | coll add:eachFileName]]. |
|
5075 |
||
5076 |
" |
|
5077 |
'.' asFilename files. |
|
5078 |
" |
|
5079 |
||
5080 |
"Modified: / 29-05-2007 / 12:02:15 / cg" |
|
5081 |
! |
|
5082 |
||
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
5083 |
filesMatching:aPattern |
2550 | 5084 |
"given the receiver, representing a directory; |
5085 |
return a collection of files matching a pattern. |
|
5086 |
The pattern may be a simple matchPattern, or a set of |
|
5087 |
multiple patterns separated by semicolons." |
|
5088 |
||
19821 | 5089 |
^ OrderedCollection withCollectedContents:[:coll | |
5090 |
self filesMatching:aPattern do:[:fn | coll add:fn]] |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5091 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5092 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5093 |
'/etc' asFilename filesMatching:'a*;c*' |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
5094 |
" |
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
5095 |
|
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
5096 |
"Created: / 15.4.1997 / 15:40:02 / cg" |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
5097 |
"Modified: / 3.8.1998 / 21:22:15 / cg" |
2550 | 5098 |
! |
5099 |
||
19821 | 5100 |
filesMatching:aPattern caseSensitive:caseSensitive do:aBlock |
5101 |
"given the receiver, representing a directory; |
|
5102 |
evaluate aBlock for files which match a pattern. |
|
5103 |
The pattern may be a simple matchPattern, or a set of |
|
5104 |
multiple patterns separated by semicolons." |
|
5105 |
||
5106 |
|matchers| |
|
5107 |
||
5108 |
matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;. |
|
5109 |
self directoryContentsDo:[:name | |
|
5110 |
(matchers contains:[:p | p match:name caseSensitive:caseSensitive]) ifTrue:[ |
|
5111 |
aBlock value:name |
|
5112 |
] |
|
5113 |
]. |
|
5114 |
||
5115 |
" |
|
5116 |
'/etc' asFilename filesMatching:'a*;c*' do:[:f | Transcript showCR:f] |
|
5117 |
" |
|
5118 |
||
5119 |
"Created: / 15.4.1997 / 15:40:02 / cg" |
|
5120 |
"Modified: / 3.8.1998 / 21:22:15 / cg" |
|
5121 |
! |
|
5122 |
||
5123 |
filesMatching:aPattern do:aBlock |
|
5124 |
"given the receiver, representing a directory; |
|
5125 |
evaluate aBlock for files which match a pattern. |
|
5126 |
The pattern may be a simple matchPattern, or a set of |
|
5127 |
multiple patterns separated by semicolons." |
|
5128 |
||
23393 | 5129 |
self filesMatching:aPattern caseSensitive:(self species isCaseSensitive) do:aBlock |
19821 | 5130 |
|
5131 |
" |
|
5132 |
'/etc' asFilename filesMatching:'a*;c*' do:[:f | Transcript showCR:f] |
|
23393 | 5133 |
'/etc' asFilename filesMatching:'a*;c*' |
5134 |
" |
|
5135 |
||
5136 |
"Created: / 15-04-1997 / 15:40:02 / cg" |
|
5137 |
"Modified: / 03-08-1998 / 21:22:15 / cg" |
|
5138 |
"Modified (comment): / 30-09-2018 / 11:01:40 / Claus Gittinger" |
|
5139 |
! |
|
5140 |
||
5141 |
filesMatchingGLOB |
|
5142 |
"Interpreting myself as a GLOB pattern, |
|
5143 |
Return filenames matching me" |
|
5144 |
||
5145 |
^ Array streamContents:[:s | self filesMatchingGLOBDo:[:each | s nextPut:each]]. |
|
5146 |
||
5147 |
" |
|
5148 |
'../../*/A*' asFilename filesMatchingGLOB. |
|
5149 |
" |
|
5150 |
||
5151 |
"Created: / 30-09-2018 / 10:56:42 / Claus Gittinger" |
|
19821 | 5152 |
! |
5153 |
||
2550 | 5154 |
filesMatchingWithoutDotDirs:aPattern |
5155 |
"given the receiver, representing a directory; |
|
5156 |
return a collection of files matching a pattern. |
|
5157 |
Exclude '.' and '..' from the returned list. |
|
5158 |
The pattern may be a simple matchPattern, or a set of |
|
5159 |
multiple patterns separated by semicolons." |
|
5160 |
||
19821 | 5161 |
^ OrderedCollection withCollectedContents:[:coll | |
5162 |
self filesMatchingWithoutDotDirs:aPattern do:[:fn | coll add:fn]] |
|
5163 |
||
5164 |
" |
|
5165 |
Filename currentDirectory filesMatching:'.*' |
|
5166 |
Filename currentDirectory filesMatchingWithoutDotDirs:'*.*' |
|
5167 |
'/etc' asFilename filesMatchingWithoutDotDirs:'*' |
|
5168 |
" |
|
5169 |
||
5170 |
"Created: / 15.4.1997 / 12:52:10 / cg" |
|
5171 |
"Modified: / 3.8.1998 / 21:22:30 / cg" |
|
5172 |
! |
|
5173 |
||
5174 |
filesMatchingWithoutDotDirs:aPattern caseSensitive:caseSensitive do:aBlock |
|
5175 |
"given the receiver, representing a directory; |
|
5176 |
evaluate aBlock for files matching a pattern. |
|
5177 |
Exclude '.' and '..'. |
|
5178 |
The pattern may be a simple matchPattern, or a set of |
|
5179 |
multiple patterns separated by semicolons." |
|
5180 |
||
5181 |
|matchers| |
|
2550 | 5182 |
|
5183 |
matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;. |
|
19821 | 5184 |
|
5185 |
self directoryContentsDo:[:name | |
|
5186 |
(name ~= '.' |
|
5187 |
and:[ name ~= '..' |
|
5188 |
and:[ (matchers contains:[:p | p match:name caseSensitive:caseSensitive]) ]]) |
|
5189 |
ifTrue:[ |
|
5190 |
aBlock value:name |
|
5191 |
] |
|
5192 |
]. |
|
5193 |
||
5194 |
" |
|
5195 |
Filename currentDirectory filesMatching:'M*' |
|
5196 |
'/etc' asFilename filesMatching:'[a-z]*' |
|
5197 |
'../../libbasic' asFilename filesMatching:'[A-D]*.st' |
|
5198 |
" |
|
5199 |
||
5200 |
"Created: / 15.4.1997 / 12:52:10 / cg" |
|
5201 |
"Modified: / 3.8.1998 / 21:22:30 / cg" |
|
5202 |
! |
|
5203 |
||
5204 |
filesMatchingWithoutDotDirs:aPattern do:aBlock |
|
5205 |
"given the receiver, representing a directory; |
|
5206 |
evaluate aBlock for files matching a pattern. |
|
5207 |
Exclude '.' and '..'. |
|
5208 |
The pattern may be a simple matchPattern, or a set of |
|
5209 |
multiple patterns separated by semicolons." |
|
5210 |
||
5211 |
self filesMatchingWithoutDotDirs:aPattern caseSensitive:self species isCaseSensitive do:aBlock |
|
2550 | 5212 |
|
5213 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5214 |
Filename currentDirectory filesMatching:'M*' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5215 |
'/etc' asFilename filesMatching:'[a-z]*' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5216 |
'../../libbasic' asFilename filesMatching:'[A-D]*.st' |
2550 | 5217 |
" |
5218 |
||
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
5219 |
"Created: / 15.4.1997 / 12:52:10 / cg" |
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
5220 |
"Modified: / 3.8.1998 / 21:22:30 / cg" |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
5221 |
! |
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
5222 |
|
23393 | 5223 |
filesWithSuffix:suffix |
5224 |
"return a collection of regular files (i.e. not subdirectories) |
|
5225 |
with a given suffix which are contained in the directory |
|
5226 |
represented by the receiver." |
|
5227 |
||
5228 |
^ OrderedCollection withCollectedContents:[:coll | |
|
5229 |
self filesWithSuffix:suffix do:[:eachFileName | coll add:eachFileName]]. |
|
5230 |
||
5231 |
" |
|
5232 |
'.' asFilename filesWithSuffix:'so'. |
|
5233 |
'packages' asFilename filesWithSuffix:'so'. |
|
5234 |
" |
|
5235 |
! |
|
5236 |
||
9206 | 5237 |
fullAlternativePathName |
19821 | 5238 |
"some filesystems (aka: windows) have alternative (short) filenames. |
5239 |
Those systems redefine this method to return it. |
|
5240 |
Otherwise, the same as the regular name is returned here" |
|
5241 |
||
9206 | 5242 |
^ nameString |
5243 |
! |
|
5244 |
||
615 | 5245 |
isExecutable |
5246 |
"return true, if such a file exists and is executable (by Unix's definition). |
|
5247 |
For directories, true is returned if the directory can be entered. |
|
5248 |
See isExecutableProgram for a related check." |
|
5249 |
||
2947 | 5250 |
^ OperatingSystem isExecutable:(self osNameForAccess) |
615 | 5251 |
|
5252 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5253 |
'/foo/bar' asFilename isExecutable |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5254 |
'/tmp' asFilename isExecutable |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5255 |
'Makefile' asFilename isExecutable |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5256 |
'/bin/ls' asFilename isExecutable |
356 | 5257 |
" |
5258 |
! |
|
5259 |
||
615 | 5260 |
isExecutableProgram |
5261 |
"return true, if such a file exists and is an executable program. |
|
5262 |
(i.e. for directories, false is returned.)" |
|
356 | 5263 |
|
2922 | 5264 |
|osName| |
5265 |
||
2947 | 5266 |
osName := self osNameForAccess. |
2922 | 5267 |
^ (OperatingSystem isExecutable:osName) |
5268 |
and:[(OperatingSystem isDirectory:osName) not] |
|
356 | 5269 |
|
5270 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5271 |
'/tmp' asFilename isExecutable |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5272 |
'/bin/ls' asFilename isExecutable |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5273 |
'/tmp' asFilename isExecutableProgram |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5274 |
'/bin/ls' asFilename isExecutableProgram |
20457 | 5275 |
|
5276 |
'ls' asFilename isExecutableProgram |
|
5277 |
OperatingSystem canExecuteCommand:'ls' |
|
615 | 5278 |
" |
5279 |
! |
|
5280 |
||
2922 | 5281 |
isHidden |
5282 |
"return true, if the receiver represents a hidden file. |
|
5283 |
The definitions of hidden files depends on the OS used; |
|
5284 |
on UNIX, a name starting with a period is considered hidden; |
|
16578 | 5285 |
on MSDOS, the file's hidden attribute is also used. |
2922 | 5286 |
VMS has no concept of hidden files." |
5287 |
||
5288 |
^ false |
|
5289 |
! |
|
5290 |
||
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5291 |
isMountPoint:aPathName |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5292 |
"return true, if I represent a mount-point. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5293 |
Warning: |
24017 | 5294 |
the receiver must be an absolute pathname, |
5295 |
because a realPath is not used/generated for the query (to avoid automounting). |
|
5296 |
Aka: do not ask: '../../' asFilename isMountPoint; |
|
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5297 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5298 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5299 |
self isAbsolute ifFalse:[ |
24017 | 5300 |
self error:'this query must be done on an absolute pathname'. |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5301 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5302 |
^ OperatingSystem isMountPoint:(self name) |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5303 |
! |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5304 |
|
615 | 5305 |
isReadable |
5306 |
"return true, if such a file exists and is readable." |
|
5307 |
||
2947 | 5308 |
^ OperatingSystem isReadable:(self osNameForFile) |
615 | 5309 |
|
5310 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5311 |
'/foo/bar' asFilename isReadable |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5312 |
'/tmp' asFilename isReadable |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5313 |
'Makefile' asFilename isReadable |
328 | 5314 |
" |
5315 |
! |
|
5316 |
||
11529 | 5317 |
isSharedLibrary |
5318 |
"return true, if such a file exists and is a shared library." |
|
5319 |
||
5320 |
ObjectFileLoader isNil ifTrue:[ |
|
24017 | 5321 |
"we cannot handle shared libraries, so there are no shared libraries" |
5322 |
^ false. |
|
11529 | 5323 |
]. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5324 |
^ (ObjectFileLoader validBinaryExtensions includes:self suffix) |
24017 | 5325 |
and:[self isRegularFile]. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5326 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5327 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5328 |
'libstx_libbasic.so' asFilename isSharedLibrary |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5329 |
'libstx_libbasic.dll' asFilename isSharedLibrary |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5330 |
'/tmp' asFilename isSharedLibrary |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5331 |
'/tmp.dll' asFilename isSharedLibrary |
11529 | 5332 |
" |
5333 |
! |
|
5334 |
||
22127 | 5335 |
isValidFilename |
5336 |
"return true, if the name is a valid filename" |
|
5337 |
||
5338 |
|separator| |
|
5339 |
||
5340 |
separator := self separator. |
|
5341 |
||
5342 |
^ nameString notEmptyOrNil |
|
5343 |
and:[(nameString contains:[:eachChar| |
|
5344 |
eachChar ~~ separator |
|
5345 |
and:[self class isBadCharacter:eachChar]]) not]. |
|
5346 |
||
5347 |
" |
|
5348 |
'abc' asFilename isValidFilename |
|
5349 |
'abc/' asFilename isValidFilename |
|
5350 |
('abc' copyWith:Character return) asFilename isValidFilename |
|
5351 |
" |
|
5352 |
||
5353 |
"Created: / 27-07-2017 / 14:23:56 / stefan" |
|
5354 |
! |
|
5355 |
||
615 | 5356 |
isWritable |
5357 |
"return true, if such a file exists and is writable." |
|
5358 |
||
2947 | 5359 |
^ OperatingSystem isWritable:(self osNameForFile) |
615 | 5360 |
|
5361 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5362 |
'/foo/bar' asFilename isWritable |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5363 |
'/tmp' asFilename isWritable |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5364 |
'Makefile' asFilename isWritable |
328 | 5365 |
" |
174 | 5366 |
! |
5367 |
||
15574 | 5368 |
isWritableDirectory |
5369 |
"return true, if such a directory exists and is writable. |
|
5370 |
Don't believe #isWritable, since on an NFS mounted filesystem |
|
5371 |
with UID mapping and attribute cache enabled, there may be false negatives." |
|
5372 |
||
5373 |
self isDirectory ifFalse:[ |
|
24017 | 5374 |
^ false. |
15574 | 5375 |
]. |
5376 |
||
5377 |
self isWritable ifFalse:[ |
|
24017 | 5378 |
"/ on an NFS mounted filesystem with UID mapping and |
5379 |
"/ attribute cache enabled, |
|
5380 |
"/ this query may fail, but creation may work actually. |
|
5381 |
"/ check again... |
|
5382 |
[ |
|
5383 |
|tempFile| |
|
5384 |
||
5385 |
tempFile := FileStream newTemporaryIn:self. |
|
5386 |
tempFile close. |
|
5387 |
tempFile fileName remove. |
|
5388 |
] on:OpenError do:[:ex| |
|
5389 |
^ false. |
|
5390 |
]. |
|
15574 | 5391 |
]. |
5392 |
^ true. |
|
5393 |
||
5394 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5395 |
'/foo/bar' asFilename isWritableDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5396 |
'/tmp' asFilename isWritableDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5397 |
'/etc' asFilename isWritableDirectory |
15574 | 5398 |
'Makefile' asFilename isWritableDirectory |
5399 |
'/net/exeptn/home2/office' asFilename isWritable |
|
5400 |
'/net/exeptn/home2/office' asFilename isWritableDirectory |
|
5401 |
" |
|
5402 |
! |
|
5403 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5404 |
separator |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5405 |
"return the directory-separator character" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5406 |
|
15811 | 5407 |
^ self species separator |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5408 |
|
22403 | 5409 |
" |
5410 |
UnixFilename separator |
|
5411 |
PCFilename separator |
|
5412 |
" |
|
5413 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5414 |
"Modified: 29.2.1996 / 20:52:01 / cg" |
8947 | 5415 |
! |
5416 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
5417 |
species |
15811 | 5418 |
"create only new instances of the concrete OS specific class. |
5419 |
Redefined in AutoDeletedFilename, to not create AutoDeleted instances |
|
5420 |
per default (from directories etc.)" |
|
5421 |
||
5422 |
self == Filename ifTrue:[ |
|
24017 | 5423 |
^ ConcreteClass. |
15811 | 5424 |
] ifFalse:[ |
24017 | 5425 |
^ self class. |
15811 | 5426 |
]. |
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
5427 |
! |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
5428 |
|
8947 | 5429 |
withSpecialExpansions |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5430 |
"return a new filename, expanding any OS specific macros. |
15811 | 5431 |
Here, a ~/ prefix is expanded to the users home dir (as in bash)" |
8947 | 5432 |
|
5433 |
|newName| |
|
5434 |
||
15811 | 5435 |
newName := self species nameWithSpecialExpansions:nameString. |
5436 |
newName = nameString ifTrue:[ |
|
24017 | 5437 |
^ self. |
8947 | 5438 |
]. |
15811 | 5439 |
^ self species named:newName. |
8947 | 5440 |
|
5441 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5442 |
'~' asFilename withSpecialExpansions |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5443 |
'~/Desktop' asFilename withSpecialExpansions |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5444 |
'~stefan' asFilename withSpecialExpansions |
15811 | 5445 |
'~stefan/Desktop' asFilename withSpecialExpansions |
8947 | 5446 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5447 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5448 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5449 |
!Filename methodsFor:'queries-contents'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5450 |
|
7291 | 5451 |
mimeTypeFromName |
16578 | 5452 |
"return the mimeType as guessed from the file's name/and or extension. |
7291 | 5453 |
This could be less accurate than mimeTypeOfContents, but avoids |
5454 |
reading the file (is therefore much faster). |
|
5455 |
Also it works with non-existing files. |
|
5456 |
Returns nil for directories and other non-regular files." |
|
5457 |
||
17112 | 5458 |
|mimeTypes| |
5459 |
||
16755 | 5460 |
"/ kludge to avoid making libview a prereq. of libbasic |
17112 | 5461 |
(mimeTypes := Smalltalk at:#MIMETypes) notNil ifTrue:[ |
21693 | 5462 |
^ mimeTypes mimeTypeForFilename:self |
16755 | 5463 |
]. |
5464 |
^ nil |
|
7291 | 5465 |
|
5466 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5467 |
'Makefile' asFilename mimeTypeFromName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5468 |
'.' asFilename mimeTypeFromName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5469 |
'/dev/null' asFilename mimeTypeFromName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5470 |
'/tmp/.X11-unix/X0' asFilename mimeTypeFromName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5471 |
'smalltalk.rc' asFilename mimeTypeFromName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5472 |
'bitmaps/SBrowser.xbm' asFilename mimeTypeFromName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5473 |
'../../rules/stmkmf' asFilename mimeTypeFromName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5474 |
'/bläh' asFilename mimeTypeFromName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5475 |
'/x.zip' asFilename mimeTypeFromName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5476 |
'/x.gz' asFilename mimeTypeFromName |
7291 | 5477 |
" |
21693 | 5478 |
|
5479 |
"Modified: / 11-04-2017 / 09:36:30 / cg" |
|
7291 | 5480 |
! |
5481 |
||
5011 | 5482 |
mimeTypeOfContents |
5483 |
"this tries to guess the mime type of contents of |
|
5484 |
the file. Returns nil, if the file is unreadable, not a plain file |
|
5485 |
or the contents is unknown. |
|
5486 |
This is done using some heuristics, and may need some improvement" |
|
5487 |
||
23667 | 5488 |
|type buffer s mimeTypes| |
5011 | 5489 |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
5490 |
type := self type. |
11406
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
5491 |
type isNil ifTrue:[ ^ nil ]. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5492 |
type == #directory ifTrue:[ ^ nil ]. |
11406
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
5493 |
type == #characterSpecial ifTrue:[ ^ nil ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
5494 |
type == #blockSpecial ifTrue:[ ^ nil ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
5495 |
type == #socket ifTrue:[ ^ nil ]. |
5011 | 5496 |
self fileSize == 0 ifTrue:[^ nil]. |
5497 |
||
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
5498 |
s := self readStreamOrNil. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
5499 |
s isNil ifTrue:[^ nil]. |
23867 | 5500 |
[ |
5501 |
"/ read some data from the file ... |
|
5502 |
buffer := String new:2048. |
|
5503 |
||
5504 |
s errorSignal catch:[ |
|
5505 |
s nextBytes:(buffer size min:self fileSize) into:buffer. |
|
5506 |
]. |
|
5507 |
] ensure:[ |
|
5508 |
s close. |
|
5509 |
]. |
|
5510 |
||
16755 | 5511 |
"/ kludge to avoid making libview a prereq. of libbasic |
17111 | 5512 |
(mimeTypes := Smalltalk at:#MIMETypes) notNil ifTrue:[ |
23667 | 5513 |
^ mimeTypes mimeTypeOfData:buffer suffix:self suffix. |
16755 | 5514 |
]. |
5515 |
^ nil |
|
5011 | 5516 |
|
5517 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5518 |
'Makefile' asFilename mimeTypeOfContents |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5519 |
'.' asFilename mimeTypeOfContents |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5520 |
'/dev/null' asFilename mimeTypeOfContents |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5521 |
'/tmp/.X11-unix/X0' asFilename mimeTypeOfContents |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5522 |
'smalltalk.rc' asFilename mimeTypeOfContents |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5523 |
'bitmaps/SBrowser.xbm' asFilename mimeTypeOfContents |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5524 |
'../../rules/stmkmf' asFilename mimeTypeOfContents |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5525 |
'/bläh' asFilename mimeTypeOfContents |
10153 | 5526 |
'C:\Dokumente und Einstellungen\cg\Favoriten\languages.lnk' asFilename mimeTypeOfContents |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5527 |
'G:\A\A01.TOP' asFilename mimeTypeOfContents |
10153 | 5528 |
" |
5529 |
||
5530 |
"Modified: / 06-11-2006 / 11:44:58 / cg" |
|
23667 | 5531 |
"Modified: / 06-02-2019 / 11:52:46 / Stefan Vogel" |
23867 | 5532 |
"Modified (format): / 12-03-2019 / 16:07:33 / Claus Gittinger" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5533 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5534 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5535 |
!Filename methodsFor:'queries-path & name'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5536 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5537 |
baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5538 |
"return my baseName as a string. |
20413 | 5539 |
- that's the file/directory name without leading parent-dirs. |
2922 | 5540 |
(i.e. '/usr/lib/st/file' asFilename baseName -> 'file' |
5541 |
and '/usr/lib' asFilename baseName -> lib). |
|
7075 | 5542 |
This method does not check if the path is valid. |
5543 |
The code here should work for Unix and MSDOS, but needs to be redefined |
|
5544 |
for VMS (and maybe others as well). |
|
2911 | 5545 |
See also: #pathName, #directoryName and #directoryPathName. |
5546 |
Compatibility note: use #tail for ST-80 compatibility." |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5547 |
|
2922 | 5548 |
|len index sep endIdx| |
5549 |
||
5550 |
sep := self separator. |
|
5551 |
len := nameString size. |
|
5552 |
((len == 1) and:[(nameString at:1) == sep]) ifTrue:[ |
|
20413 | 5553 |
^ nameString |
2922 | 5554 |
]. |
5555 |
||
5556 |
endIdx := len. |
|
5557 |
len > 1 ifTrue:[ |
|
20413 | 5558 |
(nameString at:len) == sep ifTrue:[endIdx := endIdx - 1]. |
2922 | 5559 |
]. |
5560 |
index := nameString lastIndexOf:sep startingAt:len-1. |
|
5561 |
^ nameString copyFrom:(index+1) to:endIdx |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5562 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5563 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5564 |
'/foo/bar' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5565 |
'/foo/bar.cc' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5566 |
'.' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5567 |
'..' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5568 |
'../..' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5569 |
'../../libbasic' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5570 |
'../../libpr' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5571 |
'../../libbasic/Object.st' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5572 |
'/' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5573 |
'\' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5574 |
'c:\' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5575 |
'\\idefix' asFilename baseName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5576 |
" |
2012 | 5577 |
|
3851 | 5578 |
"Modified: / 24.9.1998 / 13:06:23 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5579 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5580 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5581 |
directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5582 |
"return the directory name part of the file/directory as a new filename. |
20413 | 5583 |
- that's a filename for the directory where the file/dir represented by |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5584 |
the receiver is contained in. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5585 |
(this is almost equivalent to #directoryName or #head, but returns |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5586 |
a Filename instance instead of a string )." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5587 |
|
15811 | 5588 |
^ self species named:(self directoryName) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5589 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5590 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5591 |
'/foo/bar' asFilename directory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5592 |
'/foo/bar' asFilename directoryName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5593 |
'/foo/bar' asFilename head |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5594 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5595 |
'.' asFilename directory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5596 |
'..' asFilename directory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5597 |
'../..' asFilename directory |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5598 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5599 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5600 |
"Modified: 29.2.1996 / 20:50:14 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5601 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5602 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5603 |
directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5604 |
"return the directory name part of the file/directory as a string. |
20413 | 5605 |
- that's the name of the directory where the file/dir represented by |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5606 |
the receiver is contained in. |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
5607 |
This method does not check if the path is valid. |
2922 | 5608 |
|
5609 |
(i.e. '/usr/lib/st/file' asFilename directoryName -> '/usr/lib/st' |
|
5610 |
and '/usr/lib' asFilename directoryName -> /usr'). |
|
5611 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5612 |
(this is almost equivalent to #directory, but returns |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5613 |
a string instead of a Filename instance). |
2922 | 5614 |
|
2012 | 5615 |
See also: #pathName, #directoryPathName and #baseName. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5616 |
Compatibility note: use #head for ST-80 compatibility." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5617 |
|
16389 | 5618 |
|index sep sepString p rest parentDirectoryString| |
2922 | 5619 |
|
5620 |
sep := self separator. |
|
5621 |
sepString := sep asString. |
|
5622 |
(nameString = sepString) ifTrue:[ |
|
20413 | 5623 |
"/ |
5624 |
"/ the trivial '/' case |
|
5625 |
"/ |
|
5626 |
^ sepString |
|
2922 | 5627 |
]. |
5628 |
||
5629 |
"/ |
|
3893 | 5630 |
"/ strip off multiple trailing slashes |
2922 | 5631 |
"/ |
5632 |
p := nameString. |
|
16389 | 5633 |
[p endsWith:sep] whileTrue:[ |
20413 | 5634 |
(p = sepString) ifTrue:[ |
5635 |
^ sepString |
|
5636 |
]. |
|
5637 |
p := p copyButLast:1 |
|
2922 | 5638 |
]. |
5639 |
||
16389 | 5640 |
parentDirectoryString := self class parentDirectoryName. |
5641 |
||
22850 | 5642 |
(p startsWith:(parentDirectoryString,sepString)) ifTrue:[ |
5643 |
^ parentDirectoryString, sepString, p |
|
5644 |
]. |
|
5645 |
||
3886
e6efeb877eda
fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents:
3876
diff
changeset
|
5646 |
"/ strip off trailing components |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
5647 |
index := p lastIndexOf:sep startingAt:p size. |
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
5648 |
index == 0 ifTrue:[ |
20413 | 5649 |
"/ no separator found |
5650 |
p = '.' ifTrue:[ |
|
5651 |
^ parentDirectoryString |
|
5652 |
]. |
|
5653 |
p = '..' ifTrue:[ |
|
5654 |
^ parentDirectoryString, sepString, parentDirectoryString |
|
5655 |
]. |
|
5656 |
^ '.' |
|
2922 | 5657 |
]. |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
5658 |
rest := p copyFrom:(index+1). |
7342
4e9ff418113f
fixed for directory name ending with '/..'
Claus Gittinger <cg@exept.de>
parents:
7332
diff
changeset
|
5659 |
(rest = '.') ifTrue:[ |
20413 | 5660 |
^ p copyTo:index-1. |
7342
4e9ff418113f
fixed for directory name ending with '/..'
Claus Gittinger <cg@exept.de>
parents:
7332
diff
changeset
|
5661 |
]. |
16389 | 5662 |
(rest = parentDirectoryString) ifTrue:[ |
20413 | 5663 |
^ (self species named:(p copyTo:(index-1))) directoryName |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
5664 |
]. |
3893 | 5665 |
index == 1 ifTrue:[ |
20413 | 5666 |
^ sepString |
3893 | 5667 |
]. |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
5668 |
^ p copyTo:(index - 1) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5669 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5670 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5671 |
'/home' asFilename directoryName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5672 |
'/foo/bar/' asFilename directoryName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5673 |
'/foo/bar/' asFilename directory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5674 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5675 |
'/foo/bar' asFilename directoryName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5676 |
'bitmaps' asFilename directoryName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5677 |
'bitmaps' asFilename directoryPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5678 |
'.' asFilename directoryName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5679 |
'.' asFilename directoryPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5680 |
'..' asFilename directoryName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5681 |
'..' asFilename directoryPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5682 |
'../..' asFilename directoryName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5683 |
'../..' asFilename directoryPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5684 |
'/foo/bar/baz/..' asFilename directoryName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5685 |
'/foo/bar/baz/.' asFilename directoryName |
21064 | 5686 |
'c:\' asFilename directoryName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5687 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5688 |
|
3886
e6efeb877eda
fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents:
3876
diff
changeset
|
5689 |
"Modified: / 7.9.1995 / 10:42:03 / claus" |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
5690 |
"Modified: / 21.10.1998 / 22:52:25 / cg" |
3893 | 5691 |
"Modified: / 27.10.1998 / 13:19:26 / ps" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5692 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5693 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5694 |
directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5695 |
"return the full directory pathname part of the file/directory as a string. |
20413 | 5696 |
- that's the full pathname of the directory where the file/dir represented by |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5697 |
the receiver is contained in. |
2012 | 5698 |
See also: #pathName, #directoryName, #directory and #baseName" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5699 |
|
15811 | 5700 |
^ (self species named:self pathName) directoryName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5701 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5702 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5703 |
'/foo/bar/' asFilename directoryPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5704 |
'/foo/bar' asFilename directoryPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5705 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5706 |
'.' asFilename directoryPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5707 |
'.' asFilename directoryName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5708 |
'.' asFilename directory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5709 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5710 |
'..' asFilename directoryPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5711 |
'..' asFilename directoryName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5712 |
'..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5713 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5714 |
'../..' asFilename directoryPathName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5715 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5716 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5717 |
"Modified: 7.9.1995 / 10:42:13 / claus" |
2012 | 5718 |
"Modified: 21.12.1996 / 15:21:57 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5719 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5720 |
|
14567 | 5721 |
encodedNameString |
5722 |
"answer the name as passed to OS system calls" |
|
5723 |
||
5724 |
^ OperatingSystem encodePath:nameString |
|
5725 |
! |
|
5726 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5727 |
filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5728 |
"try to complete the receiver filename. |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
5729 |
BAD DESIGN: has side effect on the receiver. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5730 |
This method has both a return value and a side effect on the receiver: |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5731 |
it returns a collection of matching filename objects, |
19440 | 5732 |
and changes the receiver's filename-string to the longest common |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5733 |
match. |
19440 | 5734 |
If none matches, the returned collection is empty and the receiver is unchanged. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5735 |
If there is only one match, the size of the returned collection is exactly 1, |
19752 | 5736 |
containing the fully expanded filename and the receiver's name is changed to it." |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5737 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5738 |
^ self filenameCompletionIn:nil |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5739 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5740 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5741 |
'mak' asFilename filenameCompletion |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5742 |
'Make' asFilename filenameCompletion |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5743 |
'Makef' asFilename filenameCompletion;yourself |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5744 |
'/u' asFilename filenameCompletion |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5745 |
'../../libpr' asFilename inspect filenameCompletion |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5746 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5747 |
|
1517 | 5748 |
"Modified: 3.7.1996 / 10:53:51 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5749 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5750 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5751 |
filenameCompletionIn:aDirectory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5752 |
"try to complete the receiver filename. |
11341
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5753 |
|
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
5754 |
BAD DESIGN: has side effect on the receiver. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5755 |
This method has both a return value and a side effect on the receiver: |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5756 |
it returns a collection of matching filename objects, |
11341
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5757 |
and changes the receiver's filename-string to the longest common match. |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5758 |
If none matches, the returned collection is empty and the receiver is unchanged. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5759 |
If there is only one match, the size of the returned collection is exactly 1, |
11341
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5760 |
containing the fully expanded filename and the receiver's name is changed to it. |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5761 |
An empty baseName pattern (i.e. giving the name of a directory) will also return an empty matchset." |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5762 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5763 |
|mySpecies dir baseName matching matchLen try allMatching |
3774
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
5764 |
sepString parentString prefix nMatch nm caseless lcBaseName| |
3666 | 5765 |
|
15811 | 5766 |
mySpecies := self species. |
5767 |
||
5768 |
caseless := mySpecies isCaseSensitive not. |
|
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
5769 |
matching := OrderedCollection new. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
5770 |
|
15811 | 5771 |
nm := mySpecies nameWithSpecialExpansions:nameString. |
5772 |
nm := mySpecies canonicalize:nm. |
|
5773 |
||
5774 |
sepString := mySpecies separatorString. |
|
3666 | 5775 |
(nm endsWith:sepString) ifTrue:[ |
24017 | 5776 |
"/ two exceptions here: |
5777 |
"/ if there is only one file in the directory, that one must be it. |
|
5778 |
"/ otherwise, return the longest common prefix of all files. |
|
5779 |
self isDirectory ifTrue:[ |
|
5780 |
|first longest| |
|
5781 |
||
5782 |
first := nil. |
|
5783 |
OpenError catch:[ |
|
5784 |
self directoryContentsDo:[:fileName | |
|
5785 |
((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[ |
|
5786 |
matching add:fileName. |
|
5787 |
first isNil ifTrue:[ |
|
5788 |
first := longest := fileName. |
|
5789 |
] ifFalse:[ |
|
5790 |
"/ more than one file |
|
5791 |
longest := longest commonPrefixWith:fileName ignoreCase:caseless. |
|
5792 |
longest isEmpty ifTrue:[ |
|
5793 |
^ #() |
|
5794 |
]. |
|
5795 |
] |
|
5796 |
] |
|
5797 |
]. |
|
5798 |
]. |
|
5799 |
longest notNil ifTrue:[ |
|
5800 |
nameString := (self constructString:longest). |
|
5801 |
^ matching |
|
5802 |
]. |
|
5803 |
]. |
|
5804 |
^ #() |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5805 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5806 |
|
15811 | 5807 |
parentString := mySpecies parentDirectoryName. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5808 |
baseName := self baseName. |
3666 | 5809 |
baseName ~= nm ifTrue:[ |
24017 | 5810 |
prefix := self directoryName. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5811 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5812 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5813 |
self isAbsolute ifTrue:[ |
24017 | 5814 |
dir := self directory |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5815 |
] ifFalse:[ |
24017 | 5816 |
aDirectory isNil ifTrue:[ |
5817 |
dir := self directory |
|
5818 |
] ifFalse:[ |
|
5819 |
dir := (aDirectory asFilename construct:nm) directory |
|
5820 |
] |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5821 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5822 |
|
3774
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
5823 |
caseless ifTrue:[ |
24017 | 5824 |
lcBaseName := baseName asLowercase |
3774
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
5825 |
]. |
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
5826 |
|
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
5827 |
dir class errorReporter openErrorSignal handle:[:ex| |
24017 | 5828 |
^ #(). |
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
5829 |
] do:[ |
24017 | 5830 |
dir directoryContents do:[:fileName | |
5831 |
((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[ |
|
5832 |
((caseless and:[fileName asLowercase startsWith:lcBaseName]) |
|
5833 |
or:[caseless not and:[fileName startsWith:baseName]]) ifTrue:[ |
|
5834 |
matching add:fileName |
|
5835 |
] |
|
5836 |
] |
|
5837 |
]. |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5838 |
]. |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
5839 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5840 |
(nMatch := matching size) > 1 ifTrue:[ |
24017 | 5841 |
" |
5842 |
find the longest common prefix |
|
5843 |
" |
|
5844 |
matchLen := baseName size. |
|
5845 |
matchLen > matching first size ifTrue:[ |
|
5846 |
try := baseName. |
|
5847 |
allMatching := false |
|
5848 |
] ifFalse:[ |
|
5849 |
try := matching first copyTo:matchLen. |
|
5850 |
allMatching := true. |
|
5851 |
]. |
|
5852 |
||
5853 |
[allMatching] whileTrue:[ |
|
5854 |
matching do:[:aName | |
|
5855 |
((caseless and:[aName asLowercase startsWith:try asLowercase]) |
|
5856 |
or:[caseless not and:[aName startsWith:try]]) ifFalse:[ |
|
5857 |
allMatching := false |
|
5858 |
] |
|
5859 |
]. |
|
5860 |
allMatching ifTrue:[ |
|
5861 |
matchLen < matching first size ifTrue:[ |
|
5862 |
matchLen := matchLen + 1. |
|
5863 |
try := matching first copyTo:matchLen. |
|
5864 |
] ifFalse:[ |
|
5865 |
allMatching := false |
|
5866 |
] |
|
5867 |
] ifFalse:[ |
|
5868 |
try := matching first copyTo:matchLen - 1. |
|
5869 |
] |
|
5870 |
]. |
|
5871 |
" |
|
5872 |
and set my name to the last full match |
|
5873 |
" |
|
5874 |
nameString := nm := try |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5875 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5876 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5877 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5878 |
if I had a directory-prefix, change names in collection ... |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5879 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5880 |
prefix notNil ifTrue:[ |
24017 | 5881 |
(prefix endsWith:sepString) ifTrue:[ |
5882 |
"/ avoid introducing double slashes |
|
5883 |
prefix := prefix copyButLast:(sepString size). |
|
5884 |
]. |
|
5885 |
matching := matching collect:[:n | prefix , sepString , n]. |
|
5886 |
nMatch == 1 ifTrue:[ |
|
5887 |
nameString := nm := matching first |
|
5888 |
] ifFalse:[ |
|
5889 |
nMatch > 1 ifTrue:[ |
|
5890 |
nameString := nm := prefix , sepString , nm |
|
5891 |
] |
|
5892 |
] |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5893 |
] ifFalse:[ |
24017 | 5894 |
nMatch == 1 ifTrue:[ |
5895 |
nameString := nm := matching first |
|
5896 |
] |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5897 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5898 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5899 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5900 |
return the match-set, so caller can decide what to do |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5901 |
(i.e. show the matches, output a warning etc ...) |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5902 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5903 |
^ matching |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5904 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5905 |
" trivial cases: |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5906 |
|
11341
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5907 |
'../' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5908 |
'/' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5909 |
'/usr/' asFilename filenameCompletion -> empty |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5910 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5911 |
'mak' asFilename filenameCompletion |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5912 |
'Make' asFilename filenameCompletion |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5913 |
'Makef' asFilename filenameCompletion |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5914 |
'/u' asFilename filenameCompletion |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
5915 |
'../../libpr' asFilename filenameCompletion |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
5916 |
'/etc/mail/auth/xx' asFilename filenameCompletion |
11341
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5917 |
|
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5918 |
'c:\pr' asFilename filenameCompletion -> matching names |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5919 |
'c:\pr' asFilename filenameCompletion; yourself -> side effect: name changed to longest match |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5920 |
'c:\p' asFilename filenameCompletion |
11341
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5921 |
'c:\' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5922 |
'c:' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5923 |
'\' asFilename filenameCompletion -> empty |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5924 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5925 |
|
10793
0475c364e80a
care for bad (non-filename) arg in fileNameCompletion:
Claus Gittinger <cg@exept.de>
parents:
10780
diff
changeset
|
5926 |
"Modified: / 22-09-1997 / 18:03:33 / stefan" |
0475c364e80a
care for bad (non-filename) arg in fileNameCompletion:
Claus Gittinger <cg@exept.de>
parents:
10780
diff
changeset
|
5927 |
"Modified: / 17-11-2007 / 14:31:08 / cg" |
2903 | 5928 |
! |
5929 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5930 |
head |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5931 |
"return the directory name as a string. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5932 |
An alias for directoryName, for ST-80 compatiblity. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5933 |
(this is almost equivalent to #directory, but returns |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5934 |
a string instead of a Filename instance)" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5935 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5936 |
^ self directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5937 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5938 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5939 |
Filename currentDirectory head |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5940 |
'Makefile' asFilename head |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5941 |
'/foo/bar/baz.st' asFilename head |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5942 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5943 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5944 |
"Modified: 29.2.1996 / 20:21:25 / cg" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5945 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5946 |
|
7120 | 5947 |
isAbsolute |
5948 |
"return true, if the receiver represents an absolute pathname |
|
5949 |
(in contrast to one relative to the current directory)." |
|
5950 |
||
23506 | 5951 |
^ ((self osNameForAccess startsWith:self species separator) |
5952 |
or:[self isVolumeAbsolute]) |
|
7120 | 5953 |
|
5954 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5955 |
'/foo/bar' asFilename isAbsolute |
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
5956 |
'~/bla' asFilename isAbsolute |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5957 |
'..' asFilename isAbsolute |
20459 | 5958 |
'..' asFilename asAbsoluteFilename isAbsolute |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5959 |
'source/SBrowser.st' asFilename isAbsolute |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5960 |
'source/SBrowser.st' asFilename isRelative |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5961 |
'SBrowser.st' asFilename isRelative |
7120 | 5962 |
" |
23506 | 5963 |
|
5964 |
"Modified: / 05-11-2018 / 11:08:34 / Stefan Vogel" |
|
7120 | 5965 |
! |
5966 |
||
21390 | 5967 |
isBackupFilename |
5968 |
"return true, if this name is an for a backup file" |
|
5969 |
||
5970 |
^ nameString last == $~ or:[self hasSuffix:'bak']. |
|
5971 |
||
5972 |
"Created: / 09-02-2017 / 13:57:03 / stefan" |
|
5973 |
! |
|
5974 |
||
7120 | 5975 |
isExplicitRelative |
5976 |
"return true, if this name is an explicit relative name |
|
5977 |
(i.e. starts with './' or '../', to avoid path-prepending)" |
|
5978 |
||
5979 |
^ false |
|
5980 |
! |
|
5981 |
||
5982 |
isImplicit |
|
5983 |
"return true, if the receiver represents a builtin file. |
|
5984 |
The definitions of builtin files depends on the OS used; |
|
5985 |
on UNIX, '.' and '..' are builtin names." |
|
5986 |
||
5987 |
^ false |
|
5988 |
||
5989 |
"Created: 18.9.1997 / 18:04:51 / stefan" |
|
5990 |
! |
|
5991 |
||
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5992 |
isParentDirectoryOf:aFilenameOrString |
16389 | 5993 |
"Answer true, if myself is a parent directory of aFilenameOrString. |
5994 |
Unexpected results may be returned, if one of myself or aFilenameOrString does |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5995 |
not exist and relative and absolute path names are mixed |
18686 | 5996 |
('/' asFilename isParentDirectoryOf:'../noExistent' -> false) |
16389 | 5997 |
|
5998 |
Warning: maybe symbolic links must be resolved which could lead to automounting" |
|
5999 |
||
6000 |
|filenameArg otherNames myNames myName| |
|
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
6001 |
|
7236
2b8b8680f5b9
isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents:
7134
diff
changeset
|
6002 |
filenameArg := aFilenameOrString asFilename. |
16389 | 6003 |
|
6004 |
"first do a simple comparison" |
|
6005 |
otherNames := self class canonicalizedNameComponents:filenameArg name. |
|
6006 |
myNames := self class canonicalizedNameComponents:self name. |
|
6007 |
((otherNames startsWith:myNames) and:[myNames first ~= self class parentDirectoryName]) ifTrue:[ |
|
24017 | 6008 |
^ otherNames ~= myNames |
7236
2b8b8680f5b9
isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents:
7134
diff
changeset
|
6009 |
]. |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
6010 |
|
16389 | 6011 |
"fall back - try it again with ~ substitution and symbolic links resolved" |
6012 |
otherNames := self class canonicalizedNameComponents:filenameArg pathName. |
|
6013 |
myNames := self class canonicalizedNameComponents:self pathName. |
|
6014 |
(otherNames startsWith:myNames) ifTrue:[ |
|
24017 | 6015 |
^ otherNames ~= myNames |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
6016 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
6017 |
|
16389 | 6018 |
myName := self class nameFromComponents:myNames. |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
6019 |
filenameArg allParentDirectoriesDo:[:parent | |
24017 | 6020 |
parent pathName = myName ifTrue:[^ true]. |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
6021 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
6022 |
^ false. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
6023 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
6024 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6025 |
'/etc' asFilename isParentDirectoryOf:'/etc/passwd' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6026 |
'etc' asFilename isParentDirectoryOf:'etc/passwd' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6027 |
'/etc' asFilename isParentDirectoryOf:'/etc/' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6028 |
'/etc' asFilename isParentDirectoryOf:'/etc' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6029 |
'/et' asFilename isParentDirectoryOf:'/etc' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6030 |
'/home' asFilename isParentDirectoryOf:Filename currentDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6031 |
'~' asFilename isParentDirectoryOf:Filename currentDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6032 |
'~' asFilename isParentDirectoryOf:'.' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6033 |
'~' asFilename isParentDirectoryOf:'..' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6034 |
'~' asFilename isParentDirectoryOf:'../smalltalk' |
18686 | 6035 |
'../..' asFilename isParentDirectoryOf:'../nonExistent' |
6036 |
'..' asFilename isParentDirectoryOf:'../../nonExistent' |
|
6037 |
'/' asFilename isParentDirectoryOf:'../nonExistent' |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6038 |
'/' asFilename isParentDirectoryOf:'/phys/qnx' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6039 |
" |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
6040 |
! |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
6041 |
|
7120 | 6042 |
isRelative |
6043 |
"return true, if this name is interpreted relative to some |
|
6044 |
directory (opposite of absolute)" |
|
6045 |
||
6046 |
^ self isAbsolute not |
|
6047 |
||
6048 |
" |
|
6049 |
'./foo/bar' asFilename isRelative |
|
6050 |
'../../foo/bar' asFilename isRelative |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6051 |
'/foo/bar' asFilename isRelative |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6052 |
'bar' asFilename isRelative |
7120 | 6053 |
" |
6054 |
||
6055 |
"Modified: 16.1.1997 / 01:19:14 / cg" |
|
6056 |
! |
|
6057 |
||
6058 |
isRootDirectory |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6059 |
"return true, if I represent the root directory |
7120 | 6060 |
(i.e. I have no parentDir)" |
6061 |
||
6062 |
"/ mhmh - should we use: |
|
6063 |
"/ |
|
6064 |
"/ parentDir := self construct:'..'. |
|
6065 |
"/ (parentDir exists |
|
6066 |
"/ and:[parentDir isDirectory |
|
6067 |
"/ and:[parentDir id ~= self id]]) ifTrue:[ |
|
6068 |
"/ ^ false |
|
6069 |
"/ ]. |
|
6070 |
"/ ^ true |
|
6071 |
"/ |
|
6072 |
||
23667 | 6073 |
^ self pathName = self class rootDirectory pathName |
6074 |
||
6075 |
"Modified: / 23-10-1997 / 00:38:35 / cg" |
|
6076 |
"Modified: / 06-02-2019 / 11:56:36 / Stefan Vogel" |
|
7120 | 6077 |
! |
6078 |
||
6079 |
isVolumeAbsolute |
|
6080 |
"return true, if the receiver represents an absolute pathname |
|
6081 |
on some disk volume (MSDOS only)" |
|
6082 |
||
6083 |
^ false |
|
6084 |
||
6085 |
"Modified: 7.9.1997 / 23:54:33 / cg" |
|
6086 |
! |
|
6087 |
||
2987
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
6088 |
localPathName |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
6089 |
"return the full pathname of the file represented by the receiver, |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
6090 |
but without any volume information. |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
6091 |
Only makes a difference on MSDOS & VMS systems." |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
6092 |
|
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
6093 |
^ self pathName |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
6094 |
! |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
6095 |
|
615 | 6096 |
name |
6097 |
"return the name of the file represented by the receiver as a string. |
|
883 | 6098 |
This may or may not be a relative name (i.e. include ..'s). |
615 | 6099 |
See also: pathName" |
174 | 6100 |
|
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
6101 |
"/ self isAbsolute ifTrue:[^ self pathName]. |
615 | 6102 |
^ nameString |
174 | 6103 |
|
6104 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6105 |
'/foo/bar' asFilename name |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6106 |
'/foo/bar' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6107 |
'.' asFilename name |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6108 |
'.' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6109 |
'../..' asFilename name |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6110 |
'../..' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6111 |
'bitmaps' asFilename name |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6112 |
'bitmaps' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6113 |
'/tmp/../usr' asFilename name |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6114 |
'/tmp/../usr' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6115 |
'source/..' asFilename name |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6116 |
'source/..' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6117 |
'/tmp/..' asFilename name |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6118 |
'/tmp/..' asFilename pathName |
92 | 6119 |
" |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
6120 |
|
883 | 6121 |
"Modified: 18.1.1996 / 21:36:27 / cg" |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
6122 |
! |
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
6123 |
|
615 | 6124 |
pathName |
6125 |
"return the full pathname of the file represented by the receiver, |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6126 |
as a string. This will not include ..'s. |
1317 | 6127 |
If the path represented by the receiver does NOT represent a valid path, |
6128 |
no compression will be done (for now; this may change). |
|
6129 |
See also: name" |
|
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
6130 |
|
23630 | 6131 |
^ OperatingSystem pathNameOf:(self osNameForFile). |
2 | 6132 |
|
92 | 6133 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6134 |
'/foo/bar' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6135 |
'.' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6136 |
'../..' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6137 |
'../..' asFilename name |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6138 |
'/tmp/../usr' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6139 |
'/././usr' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6140 |
'~/..' asFilename pathName |
23601 | 6141 |
'$JAVA_HOME/bin/java' asFilename pathName |
6142 |
" |
|
6143 |
||
6144 |
"Modified: / 27-04-1996 / 18:19:52 / cg" |
|
23630 | 6145 |
"Modified: / 22-01-2019 / 14:49:43 / Stefan Vogel" |
174 | 6146 |
! |
6147 |
||
22403 | 6148 |
pathNameRelativeFrom:anotherDirectoriesFilename |
6149 |
"return the pathname of the receiver, |
|
6150 |
but relative from another directory. |
|
6151 |
I.e. if the receiver is /a/b/c |
|
6152 |
and the argument is /a/x/y, |
|
6153 |
then the relative path to the receiver as seen from the argument is ../../b/c" |
|
6154 |
||
6155 |
|myPath otherDir otherPath rest prefix| |
|
6156 |
||
6157 |
myPath := self pathName. |
|
6158 |
otherDir := anotherDirectoriesFilename asFilename. |
|
6159 |
prefix := ''. |
|
6160 |
[ |
|
6161 |
otherPath := otherDir pathName. |
|
6162 |
"/ if I am below: |
|
23570 | 6163 |
(myPath startsWith:otherPath caseSensitive:self class isCaseSensitive) ifTrue:[ |
22403 | 6164 |
rest := (myPath copyFrom:otherPath size+1). |
6165 |
rest isEmpty ifTrue:[^ prefix,'.' ]. |
|
6166 |
(rest startsWith:self separator) ifTrue:[^ prefix,(rest copyFrom:2) ]. |
|
6167 |
^ prefix,rest |
|
6168 |
]. |
|
6169 |
prefix := prefix,'..',self separator. |
|
6170 |
otherDir := otherDir directory. |
|
6171 |
] loop |
|
6172 |
||
6173 |
" |
|
6174 |
self assert:('/a' asFilename pathNameRelativeFrom:'/') = 'a' |
|
6175 |
self assert:('/a/b' asFilename pathNameRelativeFrom:'/') = 'a/b' |
|
6176 |
||
6177 |
self assert:('/a' asFilename pathNameRelativeFrom:'/a') = '.' |
|
6178 |
self assert:('/a/b' asFilename pathNameRelativeFrom:'/a') = 'b' |
|
6179 |
self assert:('/a/b/c' asFilename pathNameRelativeFrom:'/a') = 'b/c' |
|
6180 |
||
6181 |
self assert:('/a/' asFilename pathNameRelativeFrom:'/a') = '.' |
|
6182 |
self assert:('/a/b/' asFilename pathNameRelativeFrom:'/a') = 'b' |
|
6183 |
self assert:('/a/b/c/' asFilename pathNameRelativeFrom:'/a') = 'b/c' |
|
6184 |
||
6185 |
self assert:('/a' asFilename pathNameRelativeFrom:'/a/') = '.' |
|
6186 |
self assert:('/a/b' asFilename pathNameRelativeFrom:'/a/') = 'b' |
|
6187 |
self assert:('/a/b/c' asFilename pathNameRelativeFrom:'/a/') = ''b/c'' |
|
6188 |
||
6189 |
self assert:('/a/' asFilename pathNameRelativeFrom:'/a/') = '.' |
|
6190 |
self assert:('/a/b/' asFilename pathNameRelativeFrom:'/a/') = 'b' |
|
6191 |
self assert:('/a/b/c/' asFilename pathNameRelativeFrom:'/a/') = 'b/c' |
|
6192 |
||
6193 |
self assert:('/a' asFilename pathNameRelativeFrom:'/b') = '../a' |
|
6194 |
self assert:('/a/b/' asFilename pathNameRelativeFrom:'/b') = '../a/b' |
|
6195 |
self assert:('/a/b/c/' asFilename pathNameRelativeFrom:'/b') = '../a/b/c' |
|
6196 |
||
6197 |
self assert:('/a/b/' asFilename pathNameRelativeFrom:'/a') = 'b' |
|
6198 |
self assert:('/a/b/c/' asFilename pathNameRelativeFrom:'/a') = 'b/c' |
|
6199 |
||
6200 |
self assert:('/a/b/c/d' asFilename pathNameRelativeFrom:'/a/x/y/z') = '../../../b/c/d' |
|
6201 |
" |
|
23570 | 6202 |
|
6203 |
"Modified: / 19-12-2018 / 11:17:07 / sr" |
|
22403 | 6204 |
! |
6205 |
||
11658 | 6206 |
physicalFilename |
6207 |
"return the fileName representing the physical file as represented by the receiver, |
|
20413 | 6208 |
If the receiver represents a symbolic link, that's the fileName of the |
19440 | 6209 |
final target. Otherwise, its the receiver's pathName itself. |
11658 | 6210 |
If any file along the symbolic path does not exist (i.e. is a broken link), |
6211 |
nil is returned." |
|
6212 |
||
6213 |
|pathOrNil| |
|
6214 |
||
6215 |
pathOrNil := self physicalPathName. |
|
6216 |
pathOrNil isNil ifTrue:[ |
|
20413 | 6217 |
^ nil |
11658 | 6218 |
]. |
6219 |
^ pathOrNil asFilename |
|
6220 |
||
6221 |
" |
|
20708 | 6222 |
'/foo/bar' asFilename physicalFilename |
11658 | 6223 |
" |
6224 |
! |
|
6225 |
||
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
6226 |
physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
6227 |
"return the full pathname of the physical file represented by the receiver, |
20413 | 6228 |
If the receiver represents a symbolic link, that's the fileName of the |
19440 | 6229 |
final target. Otherwise, its the receiver's pathName itself. |
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
6230 |
If any file along the symbolic path does not exist (i.e. is a broken link), |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
6231 |
nil is returned." |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
6232 |
|
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
6233 |
|t path info| |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
6234 |
|
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
6235 |
info := self linkInfo. |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
6236 |
info isNil ifTrue:[ |
20413 | 6237 |
" I do not exist" |
6238 |
^ nil. |
|
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
6239 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
6240 |
info isSymbolicLink ifFalse:[ |
20413 | 6241 |
^ self pathName |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
6242 |
]. |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
6243 |
|
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
6244 |
t := self. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
6245 |
[ |
20413 | 6246 |
path := info path. |
6247 |
path isNil ifTrue:[ |
|
6248 |
"/ cannot happen |
|
6249 |
^ nil |
|
6250 |
]. |
|
6251 |
path asFilename isAbsolute ifTrue:[ |
|
6252 |
t := path asFilename |
|
6253 |
] ifFalse:[ |
|
6254 |
t := (self species named:t directoryName) construct:path. |
|
6255 |
]. |
|
6256 |
info := t linkInfo. |
|
6257 |
info isNil ifTrue:[ |
|
6258 |
"t does not exist" |
|
6259 |
^ nil |
|
6260 |
]. |
|
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
6261 |
] doWhile:[info isSymbolicLink]. |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
6262 |
|
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
6263 |
^ t pathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
6264 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
6265 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6266 |
'/foo/bar' asFilename physicalPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6267 |
'.' asFilename physicalPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6268 |
'../..' asFilename physicalPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6269 |
'/usr/tmp' asFilename physicalPathName |
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
6270 |
" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
6271 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
6272 |
"Modified: 21.12.1996 / 15:29:50 / cg" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
6273 |
! |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
6274 |
|
615 | 6275 |
tail |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6276 |
"the file's name without directory prefix as a string. |
615 | 6277 |
An alias for baseName, for ST-80 compatiblity." |
174 | 6278 |
|
615 | 6279 |
^ self baseName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6280 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6281 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6282 |
Filename currentDirectory tail |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6283 |
'Makefile' asFilename tail |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6284 |
'/foo/bar/baz.st' asFilename tail |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6285 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6286 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6287 |
"Modified: 29.2.1996 / 20:19:50 / cg" |
2629 | 6288 |
! |
6289 |
||
7307
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6290 |
tail:nComponents |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6291 |
"return the last n components of myself. |
20413 | 6292 |
- that's the file/directory name without leading parent-dirs. |
7307
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6293 |
(i.e. '/usr/lib/st/file' asFilename tail:2 -> 'st/file' |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6294 |
and '/usr/lib' asFilename tail:1 -> lib). |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6295 |
This method does not check if the path is valid. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6296 |
The code here should work for Unix and MSDOS, but needs to be redefined |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6297 |
for VMS (and maybe others as well). |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6298 |
See also: #pathName, #directoryName and #directoryPathName." |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6299 |
|
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6300 |
|sep components tail start| |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6301 |
|
15811 | 6302 |
sep := self species separator. |
7307
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6303 |
components := self components. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6304 |
start := components size - nComponents + 1. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6305 |
start < 1 ifTrue:[ |
20413 | 6306 |
start := 1. |
7307
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6307 |
]. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6308 |
start = 1 ifTrue:[ |
20413 | 6309 |
tail := '' |
7307
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6310 |
] ifFalse:[ |
20413 | 6311 |
tail := components at:start. |
7307
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6312 |
]. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6313 |
start+1 to:components size do:[:i| |
20413 | 6314 |
tail := tail, sep, (components at:i). |
7307
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6315 |
]. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6316 |
^ tail. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6317 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6318 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6319 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6320 |
'/foo/bar' asFilename tail:1 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6321 |
'/foo/bar' asFilename tail:2 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6322 |
'/foo/bar' asFilename tail:3 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6323 |
'/foo/bar.cc' asFilename tail:2 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6324 |
'.' asFilename tail:3 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6325 |
'..' asFilename tail:3 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6326 |
'../..' asFilename tail:2 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6327 |
'../../libbasic' asFilename tail:2 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6328 |
'../../libbasic' asFilename asCanonicalizedFilename tail:2 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6329 |
'../../libpr' asFilename tail:2 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6330 |
'../../libbasic/Object.st' asFilename asCanonicalizedFilename tail:2 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6331 |
'/' asFilename tail:2 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6332 |
'\' asFilename tail:2 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6333 |
'c:\' asFilename tail:2 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6334 |
'\\idefix' asFilename tail:2 |
7307
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6335 |
" |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6336 |
! |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6337 |
|
2629 | 6338 |
volume |
6339 |
"return the disc volume part of the name or an empty string. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6340 |
This is only used with MSDOS and VMS filenames |
2906 | 6341 |
- by default (and on unix), an empty string is returned" |
6342 |
||
2629 | 6343 |
^ '' |
2906 | 6344 |
|
6345 |
"Modified: 8.9.1997 / 00:37:33 / cg" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6346 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6347 |
|
7120 | 6348 |
!Filename methodsFor:'queries-type'! |
6349 |
||
6350 |
isDirectory |
|
6351 |
"return true, if the receiver represents an existing, |
|
23420 | 6352 |
readable directories pathname. |
6353 |
Symbolic links pointing to a directory answer true." |
|
7120 | 6354 |
|
6355 |
^ OperatingSystem isDirectory:(self osNameForAccess) |
|
6356 |
||
6357 |
" |
|
6358 |
'/foo/bar' asFilename isDirectory |
|
6359 |
'/tmp' asFilename isDirectory |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6360 |
'Makefile' asFilename isDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6361 |
'c:\' asFilename isDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6362 |
'd:\' asFilename isDirectory |
23632 | 6363 |
'\\host\dir' asFilename isDirectory |
6364 |
OperatingSystem isDirectory:'\\host\dir' |
|
6365 |
" |
|
6366 |
||
6367 |
"Modified: / 21-09-1998 / 15:53:10 / cg" |
|
6368 |
"Modified (comment): / 22-01-2019 / 15:14:45 / Stefan Vogel" |
|
7120 | 6369 |
! |
6370 |
||
6371 |
isNonEmptyDirectory |
|
6372 |
"return true, if the receiver represents an existing, |
|
6373 |
readable directories pathname, and the directory is not empty." |
|
6374 |
||
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
6375 |
FileStream openErrorSignal |
24017 | 6376 |
handle:[:ex| ] |
6377 |
do:[ |
|
6378 |
self directoryContentsDo:[:pathString|^ true]. |
|
6379 |
]. |
|
7120 | 6380 |
^ false. |
6381 |
||
6382 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6383 |
'/foo/bar' asFilename isNonEmptyDirectory |
7120 | 6384 |
'/tmp' asFilename isNonEmptyDirectory |
6385 |
'/tmp/empty' asFilename makeDirectory; isNonEmptyDirectory. |
|
6386 |
'/tmp/empty' asFilename removeDirectory. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6387 |
'Makefile' asFilename isNonEmptyDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6388 |
'c:\' asFilename isNonEmptyDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6389 |
'd:\' asFilename isNonEmptyDirectory |
7120 | 6390 |
" |
6391 |
||
6392 |
"Modified: / 21.9.1998 / 15:53:10 / cg" |
|
6393 |
! |
|
6394 |
||
8836 | 6395 |
isRegularFile |
23420 | 6396 |
"return true, if the receiver represents a plain, regular file. |
6397 |
Symbolic links pointing to a regular file answer true." |
|
8836 | 6398 |
|
6399 |
^ self type == #regular |
|
6400 |
||
6401 |
" |
|
6402 |
'/foo/bar' asFilename isRegularFile |
|
6403 |
'/tmp' asFilename isRegularFile |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6404 |
'Makefile' asFilename isRegularFile |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6405 |
'c:\' asFilename isRegularFile |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6406 |
'd:\' asFilename isRegularFile |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6407 |
'/dev/null' asFilename isRegularFile |
8836 | 6408 |
" |
6409 |
! |
|
6410 |
||
7120 | 6411 |
isSpecialFile |
6412 |
"return true, if the receiver represents a socket, named pipe, fifo |
|
23420 | 6413 |
or device special file (i.e. anything non regular and non-directory). |
6414 |
Symbolic links pointing to a special file answer true." |
|
6415 |
||
7120 | 6416 |
|
6417 |
|t| |
|
6418 |
||
6419 |
t := self type. |
|
6420 |
^ (t ~= #directory and:[t ~~ #regular and:[t ~~ #symbolicLink]]) |
|
6421 |
||
6422 |
" |
|
6423 |
'/foo/bar' asFilename isSpecialFile |
|
6424 |
'/tmp' asFilename isSpecialFile |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6425 |
'Makefile' asFilename isSpecialFile |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6426 |
'c:\' asFilename isSpecialFile |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6427 |
'd:\' asFilename isSpecialFile |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6428 |
'/dev/null' asFilename isSpecialFile |
7120 | 6429 |
" |
6430 |
! |
|
6431 |
||
6432 |
isSymbolicLink |
|
6433 |
"return true, if the file represented by the receiver is a symbolic |
|
22127 | 6434 |
link. Notice that not all OS's support symbolic links; |
6435 |
those that do not will always return false." |
|
7120 | 6436 |
|
6437 |
^ OperatingSystem isSymbolicLink:(self osNameForFile) |
|
6438 |
||
6439 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6440 |
'Make.proto' asFilename isSymbolicLink |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6441 |
'Makefile' asFilename isSymbolicLink |
7120 | 6442 |
" |
22127 | 6443 |
|
6444 |
"Modified (comment): / 27-07-2017 / 16:03:43 / stefan" |
|
7120 | 6445 |
! ! |
6446 |
||
6529 | 6447 |
!Filename methodsFor:'reading-directories'! |
6448 |
||
6449 |
directoryContents |
|
6450 |
"return the contents of the directory as a collection of strings. |
|
6451 |
This excludes any entries for '.' or '..'. |
|
6452 |
Returns nil for non-existing directories; however, this behavior |
|
6453 |
may be changed in the near future, to raise an exception instead. |
|
6454 |
So users of this method better test for existing directory before. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6455 |
Notice: |
19821 | 6456 |
this returns the file-names as strings; |
6457 |
see also #directoryContentsAsFilenames, which returns fileName instances." |
|
6458 |
||
6459 |
^ OrderedCollection withCollectedContents:[:coll | |
|
6460 |
self directoryContentsDo:[:each | coll add:each]] |
|
6529 | 6461 |
|
6462 |
" |
|
6463 |
'.' asFilename directoryContents |
|
6464 |
'/XXXdoesNotExist' asFilename directoryContents |
|
6465 |
" |
|
6466 |
||
6467 |
"Modified: / 18.9.1997 / 18:42:23 / stefan" |
|
6468 |
"Modified: / 3.8.1998 / 21:36:21 / cg" |
|
6469 |
! |
|
6470 |
||
6471 |
directoryContentsAsFilenames |
|
6472 |
"return the contents of the directory as a collection of filenames. |
|
6473 |
This excludes any entries for '.' or '..'. |
|
6474 |
Returns nil for non-existing directories; however, this behavior |
|
6475 |
may be changed in the near future, to raise an exception instead. |
|
6476 |
So users of this method better test for existing directory before. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6477 |
Notice: |
19821 | 6478 |
this returns the file-names as fileName instances; |
6479 |
see also #directoryContents, which returns strings." |
|
6480 |
||
6481 |
^ OrderedCollection withCollectedContents:[:coll | |
|
6482 |
self directoryContentsAsFilenamesDo:[:each | coll add:each]] |
|
6529 | 6483 |
|
6484 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6485 |
'.' asFilename directoryContentsAsFilenames |
6529 | 6486 |
'/XXXdoesNotExist' asFilename directoryContentsAsFilenames |
6487 |
" |
|
6488 |
! |
|
6489 |
||
6490 |
fullDirectoryContents |
|
6491 |
"return the full contents of the directory as a collection of strings. |
|
6492 |
This is much like #directoryContents, but includes an entry for the |
|
6493 |
parent directory, if there is one. |
|
6494 |
Returns nil for non-existing directories; however, this behavior |
|
6495 |
may be changed in the near future, to raise an exception instead. |
|
6496 |
So users of this method better test for existing directory before." |
|
6497 |
||
6498 |
|files| |
|
6499 |
||
12910 | 6500 |
"here we get the files without '.' and '..'" |
6529 | 6501 |
files := self directoryContents. |
6502 |
files isNil ifTrue:[ |
|
24017 | 6503 |
"/ mhmh - that one does not exist |
6504 |
^ files |
|
6529 | 6505 |
]. |
6506 |
||
12910 | 6507 |
files addFirst:'..'. |
6529 | 6508 |
^ files |
6509 |
||
6510 |
" |
|
6511 |
'.' asFilename fullDirectoryContents |
|
6512 |
'/XXXdoesNotExist' asFilename fullDirectoryContents |
|
6513 |
'd:\FET' asFilename fullDirectoryContents |
|
6514 |
" |
|
6515 |
||
6516 |
"Modified: / 21.9.1998 / 15:33:07 / cg" |
|
6517 |
! |
|
6518 |
||
23332 | 6519 |
isEmptyDirectory |
6520 |
"answer true, if this is an empty directory. |
|
6521 |
Raise an exception, if this is not a directory." |
|
6522 |
||
6523 |
self directoryContentsDo:[:each | ^ false]. |
|
6524 |
^ true |
|
6525 |
||
6526 |
" |
|
6527 |
'.' asFilename isEmptyDirectory |
|
6528 |
'Make.proto' asFilename isEmptyDirectory |
|
6529 |
'/XXXdoesNotExist' asFilename isEmptyDirectory |
|
6530 |
" |
|
6531 |
||
6532 |
"Created: / 12-09-2018 / 14:29:12 / Stefan Vogel" |
|
6533 |
! |
|
6534 |
||
6529 | 6535 |
recursiveDirectoryContents |
6536 |
"return the contents of the directory and all subdirectories |
|
6537 |
as a collection of strings. |
|
6538 |
This excludes any entries for '.' or '..'. |
|
6539 |
Subdirectory files are included with a relative pathname. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6540 |
Notice: |
24017 | 6541 |
this returns the file-names as strings; |
6542 |
see also #recursiveDirectoryContentsAsFilenames, which returns fileName instances. |
|
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6543 |
|
6529 | 6544 |
Warning: this may take a long time to execute." |
6545 |
||
6546 |
|fileNames dirNames| |
|
6547 |
||
6548 |
fileNames := OrderedCollection new. |
|
6549 |
dirNames := OrderedCollection new. |
|
6550 |
self directoryContents do:[:f | |
|
24017 | 6551 |
(self construct:f) isDirectory ifTrue:[ |
6552 |
dirNames add:f |
|
6553 |
] ifFalse:[ |
|
6554 |
fileNames add:f |
|
6555 |
] |
|
6529 | 6556 |
]. |
6557 |
||
6558 |
dirNames do:[:dN | |
|
24017 | 6559 |
|dd subFiles| |
6560 |
||
6561 |
dd := dN asFilename. |
|
6562 |
subFiles := (self construct:dN) recursiveDirectoryContents. |
|
6563 |
fileNames addAll:(subFiles collect:[:f | dd constructString:f]) |
|
6529 | 6564 |
]. |
6565 |
^ fileNames. |
|
6566 |
||
6567 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6568 |
'.' asFilename recursiveDirectoryContents |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6569 |
'../../clients' asFilename recursiveDirectoryContents |
6529 | 6570 |
" |
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6571 |
! |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6572 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6573 |
recursiveDirectoryContentsAsFilenames |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6574 |
"return the contents of the directory and all subdirectories |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6575 |
as a collection of filenames. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6576 |
This excludes any entries for '.' or '..'. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6577 |
Returns nil for non-existing directories; however, this behavior |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6578 |
may be changed in the near future, to raise an exception instead. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6579 |
So users of this method better test for existing directory before. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6580 |
Notice: |
24017 | 6581 |
this returns the file-names as fileName instances; |
6582 |
see also #recursiveDirectoryContents, which returns strings. |
|
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6583 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6584 |
Warning: this may take a long time to execute." |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6585 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6586 |
|names| |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6587 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6588 |
names := self recursiveDirectoryContents. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6589 |
names isNil ifTrue:[^ nil]. |
12910 | 6590 |
^ names collect:[:entry | self construct:entry]. |
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6591 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6592 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6593 |
'.' asFilename recursiveDirectoryContentsAsFilenames |
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6594 |
'/XXXdoesNotExist' asFilename recursiveDirectoryContentsAsFilenames |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6595 |
" |
6529 | 6596 |
! ! |
6597 |
||
6598 |
!Filename methodsFor:'reading-files'! |
|
6599 |
||
22685 | 6600 |
binaryContents |
6601 |
"an alias. |
|
6602 |
return the binary contents of the file (as a byteArray); |
|
6603 |
Raises an error, if the file is unreadable/non-existing." |
|
6604 |
||
6605 |
^ self binaryContentsOfEntireFile |
|
6606 |
! |
|
6607 |
||
6529 | 6608 |
binaryContentsOfEntireFile |
6609 |
"return the binary contents of the file (as a byteArray); |
|
7680 | 6610 |
Raises an error, if the file is unreadable/non-existing." |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6611 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6612 |
^ self |
24017 | 6613 |
readingFileDo:[:s | |
6614 |
|nBytes bytes n result| |
|
6615 |
||
6616 |
s binary. |
|
6617 |
nBytes := self fileSize. |
|
6618 |
(nBytes notNil and:[ nBytes ~~ 0 ]) ifTrue:[ |
|
6619 |
bytes := ByteArray uninitializedNew:nBytes. |
|
6620 |
n := s nextBytes:nBytes into:bytes startingAt:1. |
|
6621 |
n == nBytes ifTrue:[ |
|
6622 |
result := bytes |
|
6623 |
] ifFalse:[ |
|
6624 |
result := bytes copyTo:n |
|
6625 |
] |
|
6626 |
] ifFalse:[ |
|
6627 |
result := s contentsOfEntireFile |
|
6628 |
]. |
|
6629 |
result |
|
6630 |
] |
|
6529 | 6631 |
|
6632 |
" |
|
6633 |
'Makefile' asFilename binaryContentsOfEntireFile |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6634 |
'foobar' asFilename binaryContentsOfEntireFile |
6529 | 6635 |
" |
14446
479f02b4c705
changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
14306
diff
changeset
|
6636 |
|
479f02b4c705
changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
14306
diff
changeset
|
6637 |
"Modified: / 27-10-2012 / 19:42:07 / cg" |
6529 | 6638 |
! |
6639 |
||
6640 |
contents |
|
20156 | 6641 |
"Return the contents of the file as a collection of lines. |
6642 |
Raise an error if the file is unreadable/non-existing. |
|
6529 | 6643 |
See also #contentsOfEntireFile, which returns a string for textFiles. |
6644 |
CAVEAT: bad naming - but req'd for VW compatibility." |
|
6645 |
||
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
6646 |
^ self readingFileDo:[:s | s contents]. |
6529 | 6647 |
|
6648 |
" |
|
6649 |
'Makefile' asFilename contents |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6650 |
'foobar' asFilename contents |
6529 | 6651 |
" |
6652 |
||
6653 |
"Modified: / 2.7.1996 / 12:49:45 / stefan" |
|
6654 |
"Created: / 11.7.1996 / 14:09:11 / cg" |
|
6655 |
"Modified: / 15.10.1998 / 11:41:45 / cg" |
|
6656 |
! |
|
6657 |
||
10780 | 6658 |
contentsAsString |
6659 |
"to compensate for the bad naming, use this to make things explicit. |
|
6660 |
See also #contents, which returns the lines as stringCollection for textFiles." |
|
6661 |
||
11397
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
6662 |
^ self contentsOfEntireFile |
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
6663 |
|
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
6664 |
" |
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
6665 |
'Makefile' asFilename contentsAsString |
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
6666 |
'foobar' asFilename contentsAsString |
10780 | 6667 |
" |
6668 |
||
6669 |
"Modified: / 02-07-1996 / 12:49:45 / stefan" |
|
6670 |
"Created: / 08-11-2007 / 13:29:59 / cg" |
|
6671 |
! |
|
6672 |
||
6529 | 6673 |
contentsOfEntireFile |
6674 |
"return the contents of the file as a string; |
|
7680 | 6675 |
Raises an error, if the file is unreadable/non-existing. |
6529 | 6676 |
See also #contents, which returns the lines as stringCollection for textFiles. |
6677 |
CAVEAT: bad naming - but req'd for VW compatibility." |
|
6678 |
||
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
6679 |
^ self readingFileDo:[:s | s contentsOfEntireFile]. |
6529 | 6680 |
|
6681 |
" |
|
6682 |
'Makefile' asFilename contentsOfEntireFile |
|
19043 | 6683 |
'smalltalk.rc' asFilename contentsOfEntireFile |
6529 | 6684 |
'foobar' asFilename contentsOfEntireFile |
6685 |
" |
|
6686 |
||
6687 |
"Modified: / 2.7.1996 / 12:49:45 / stefan" |
|
6688 |
"Modified: / 15.10.1998 / 11:42:05 / cg" |
|
6689 |
! |
|
6690 |
||
6691 |
readingFileDo:aBlock |
|
20156 | 6692 |
"Create a read stream on the receiver file, evaluate aBlock, passing that stream as arg, |
6693 |
and return the block's value. |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
6694 |
If the file cannot be opened, an exception is raised or |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
6695 |
(old behavior, will vanish:)the block is evaluated with a nil argument. |
6529 | 6696 |
Ensures that the stream is closed." |
6697 |
||
22497 | 6698 |
|stream| |
6699 |
||
6700 |
stream := self readStream. |
|
6701 |
^ [ |
|
6702 |
aBlock value:stream |
|
6529 | 6703 |
] ensure:[ |
20156 | 6704 |
stream notNil ifTrue:[stream close] |
6529 | 6705 |
]. |
6706 |
||
6707 |
" |
|
6708 |
read the first line from some file: |
|
6709 |
||
6710 |
|rslt| |
|
6711 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6712 |
rslt := |
20156 | 6713 |
'/etc/passwd' asFilename |
6714 |
readingFileDo:[:s | |
|
6715 |
s nextLine |
|
6716 |
]. |
|
6529 | 6717 |
Transcript showCR:rslt. |
6718 |
" |
|
6719 |
||
6720 |
" |
|
6721 |
find all used shells in /etc/passwd and count their usage: |
|
6722 |
||
6723 |
|rslt| |
|
6724 |
||
6725 |
rslt := |
|
20156 | 6726 |
'/etc/passwd' asFilename |
6727 |
readingFileDo: |
|
6728 |
[:s | |
|
6729 |
|shells| |
|
6730 |
||
6731 |
shells := Bag new. |
|
6732 |
s linesDo: |
|
6733 |
[:line | |
|
6734 |
|parts| |
|
6735 |
||
6736 |
parts := line asCollectionOfSubstringsSeparatedBy:$:. |
|
6737 |
shells add:(parts seventh). |
|
6738 |
]. |
|
6739 |
shells contents |
|
6740 |
]. |
|
6529 | 6741 |
Transcript showCR:rslt. |
6742 |
" |
|
22497 | 6743 |
|
6744 |
"Modified: / 12-01-2018 / 18:21:32 / stefan" |
|
6771 | 6745 |
! |
6746 |
||
6747 |
readingLinesDo:aBlock |
|
20158 | 6748 |
"Create a read stream on the receiver file and |
6771 | 6749 |
evaluate aBlock for each line read from the stream. |
6750 |
If the file cannot be opened, an error is raised. |
|
6751 |
Ensures that the stream is closed." |
|
6752 |
||
6753 |
self readingFileDo:[:stream | |
|
20158 | 6754 |
stream linesDo:aBlock |
6771 | 6755 |
]. |
6756 |
||
6757 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6758 |
'/etc/passwd' asFilename |
20158 | 6759 |
readingLinesDo:[:eachLine | |
6760 |
Transcript showCR:eachLine. |
|
6761 |
]. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6762 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6763 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6764 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6765 |
'/etc/xxxxx' asFilename |
20158 | 6766 |
readingLinesDo:[:eachLine | |
6767 |
Transcript showCR:eachLine. |
|
6768 |
]. |
|
6771 | 6769 |
" |
6529 | 6770 |
! ! |
6771 |
||
2922 | 6772 |
!Filename methodsFor:'special accessing'! |
6773 |
||
6774 |
osName |
|
24066 | 6775 |
"special - return the OS's name for the receiver. |
6776 |
Note: this may return an absolute pathName, if there are |
|
6777 |
place holders in the name. |
|
6778 |
Otherwise it keeps the name relative or absolute as it is." |
|
2922 | 6779 |
|
6780 |
self isDirectory ifTrue:[ |
|
24017 | 6781 |
^ self osNameForDirectory |
2922 | 6782 |
]. |
6783 |
^ self osNameForFile |
|
24066 | 6784 |
|
6785 |
"Modified (comment): / 12-04-2019 / 11:51:00 / Stefan Vogel" |
|
2922 | 6786 |
! |
6787 |
||
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
6788 |
osNameForAccess |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
6789 |
"internal - return the OS's name for the receiver to |
3665 | 6790 |
access its fileInfo. |
6791 |
This may be redefined for systems, where a special suffix must be |
|
6792 |
added in order to access directories (or others) as a file. |
|
6793 |
(i.e. under VMS, a '.dir' suffix is added to access directories)" |
|
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
6794 |
|
7064 | 6795 |
^ self osNameForFile |
3665 | 6796 |
|
6797 |
"Modified: / 21.7.1998 / 10:40:40 / cg" |
|
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
6798 |
! |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
6799 |
|
2922 | 6800 |
osNameForDirectory |
3753 | 6801 |
"internal - return the OS's name for the receiver to |
24066 | 6802 |
access it as a directory. |
6803 |
Note: this may return an absolute pathName, if there are |
|
6804 |
place holders in the name. |
|
6805 |
Otherwise it keeps the name relative or absolute as it is." |
|
6806 |
||
2922 | 6807 |
|
14218 | 6808 |
^ self osNameForFile |
3753 | 6809 |
|
24060 | 6810 |
" |
6811 |
'.' asFilename osNameForDirectory |
|
6812 |
'.' asFilename pathName |
|
6813 |
" |
|
6814 |
||
6815 |
"Modified: / 12-08-1998 / 14:44:32 / cg" |
|
6816 |
"Modified (comment): / 11-04-2019 / 18:13:09 / Stefan Vogel" |
|
2922 | 6817 |
! |
6818 |
||
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
6819 |
osNameForDirectoryContents |
3753 | 6820 |
"internal - return the OS's name for the receiver to |
24066 | 6821 |
access it as a directory when reading its contents. |
6822 |
Note: this may return an absolute pathName, if there are |
|
6823 |
place holders in the name. |
|
6824 |
Otherwise it keeps the name relative or absolute as it is." |
|
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
6825 |
|
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
6826 |
^ self osNameForDirectory |
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
6827 |
|
24066 | 6828 |
"Created: / 03-08-1998 / 21:36:06 / cg" |
6829 |
"Modified: / 12-08-1998 / 14:44:34 / cg" |
|
6830 |
"Modified (comment): / 12-04-2019 / 11:51:57 / Stefan Vogel" |
|
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
6831 |
! |
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
6832 |
|
2922 | 6833 |
osNameForFile |
6834 |
"internal - return the OS's name for the receiver to |
|
24066 | 6835 |
access it as a file. |
6836 |
Note: this may return an absolute pathName, if there are |
|
6837 |
place holders in the name. |
|
6838 |
Otherwise it keeps the name relative or absolute as it is." |
|
2922 | 6839 |
|
19670 | 6840 |
(nameString startsWith:$~) ifFalse:[ |
6841 |
^ nameString. |
|
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
6842 |
]. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
6843 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6844 |
^ self species nameWithSpecialExpansions:nameString. |
24066 | 6845 |
|
6846 |
"Modified (comment): / 12-04-2019 / 11:50:45 / Stefan Vogel" |
|
2922 | 6847 |
! ! |
6848 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6849 |
!Filename methodsFor:'suffixes'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6850 |
|
11748 | 6851 |
addSuffix:aSuffix |
19440 | 6852 |
"return a new filename for the receiver's name with a additional suffix. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6853 |
The new suffix is simply appended to the name, |
14306
f41ca29d9b54
comment/format in: #addSuffix:
Stefan Vogel <sv@exept.de>
parents:
14232
diff
changeset
|
6854 |
regardless whether there is already an existing suffix. |
f41ca29d9b54
comment/format in: #addSuffix:
Stefan Vogel <sv@exept.de>
parents:
14232
diff
changeset
|
6855 |
See also #withSuffix:" |
11748 | 6856 |
|
6857 |
aSuffix isEmptyOrNil ifTrue:[ |
|
24013 | 6858 |
^ self. |
11748 | 6859 |
]. |
6860 |
||
15811 | 6861 |
^ self species named: |
24013 | 6862 |
(self name |
6863 |
, self species suffixSeparator asString |
|
6864 |
, aSuffix asString) |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6865 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6866 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6867 |
'abc.st' asFilename addSuffix:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6868 |
'a.b.c' asFilename addSuffix:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6869 |
'.b.c.' asFilename addSuffix:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6870 |
'.b.c' asFilename addSuffix:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6871 |
'.c.' asFilename addSuffix:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6872 |
'.c' asFilename addSuffix:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6873 |
'c.' asFilename addSuffix:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6874 |
'.' asFilename addSuffix:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6875 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6876 |
'abc.st' asFilename addSuffix:'o' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6877 |
'abc' asFilename addSuffix:'o' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6878 |
'a.b.c' asFilename addSuffix:'o' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6879 |
'a.b.c.' asFilename addSuffix:'o' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6880 |
'.b.c.' asFilename addSuffix:'o' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6881 |
'.c.' asFilename addSuffix:'o' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6882 |
'.c' asFilename addSuffix:'o' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6883 |
'c.' asFilename addSuffix:'o' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6884 |
'.' asFilename addSuffix:'o' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6885 |
'/foo/bar/baz.st' asFilename addSuffix:'c' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6886 |
'/foo/bar/baz.c' asFilename addSuffix:'st' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6887 |
'/foo/bar.c/baz.c' asFilename addSuffix:'st' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6888 |
'/foo/bar.c/baz' asFilename addSuffix:'st' |
11748 | 6889 |
" |
6890 |
! |
|
6891 |
||
2906 | 6892 |
hasSuffix:aSuffixString |
6893 |
"return true if my suffix is the same as aString. |
|
6894 |
This cares for systems, where case is ignored in filenames" |
|
6895 |
||
6896 |
|mySuffix| |
|
6897 |
||
6898 |
mySuffix := self suffix. |
|
15811 | 6899 |
self species isCaseSensitive ifTrue:[ |
24017 | 6900 |
^ mySuffix = aSuffixString |
2906 | 6901 |
]. |
24101 | 6902 |
^ mySuffix sameAs:aSuffixString |
2906 | 6903 |
|
6904 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6905 |
'abc.st' asFilename hasSuffix:'st' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6906 |
'abc.ST' asFilename hasSuffix:'st' |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
6907 |
'.ST' asFilename hasSuffix:'st' -- false expected here |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
6908 |
'.foorc' asFilename hasSuffix:'foorc' -- false expected here |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6909 |
'.foorc.sav' asFilename hasSuffix:'sav' |
2906 | 6910 |
" |
6911 |
||
24101 | 6912 |
"Modified: / 07-09-1997 / 02:55:25 / cg" |
6913 |
"Modified: / 01-05-2019 / 11:22:37 / Claus Gittinger" |
|
2906 | 6914 |
! |
6915 |
||
10155 | 6916 |
nameWithoutSuffix |
19440 | 6917 |
"return the receiver's name without the suffix. |
10155 | 6918 |
If the name has no suffix, the original name is returned." |
6919 |
||
6920 |
|nm idx idxFromEnd| |
|
6921 |
||
6922 |
nm := self baseName. |
|
15811 | 6923 |
idx := nm lastIndexOf:(self species suffixSeparator). |
10155 | 6924 |
(idx == 0) ifTrue:[^ nameString]. |
6925 |
"/ be careful: if the name consists only of suffix (i.e '.foo'), |
|
6926 |
"/ the suffix is considered empty. |
|
6927 |
(idx == 1) ifTrue:[^ nameString]. |
|
6928 |
||
6929 |
idxFromEnd := nm size - idx. |
|
6930 |
idx := nameString size - idxFromEnd. |
|
6931 |
||
6932 |
^ nameString copyTo:(idx - 1) |
|
6933 |
||
6934 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6935 |
'abc.st' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6936 |
'abc' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6937 |
'/abc' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6938 |
'/abc.d' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6939 |
'./abc' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6940 |
'./abc.d' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6941 |
'./.abc' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6942 |
'a.b.c' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6943 |
'a.b.' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6944 |
'.b.c' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6945 |
'.b.' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6946 |
'.b' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6947 |
'/foo/bar/baz.c' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6948 |
'/foo/bar.x/baz.c' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6949 |
'/foo/bar.x/baz' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6950 |
'/foo/bar/baz/foo.c/bar' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6951 |
'/foo/bar/baz/foo.c/bar.c' asFilename nameWithoutSuffix |
10155 | 6952 |
" |
6953 |
||
6954 |
"Modified: / 07-09-1995 / 11:15:42 / claus" |
|
6955 |
"Created: / 07-11-2006 / 13:55:18 / cg" |
|
6956 |
! |
|
6957 |
||
9453 | 6958 |
prefix |
6959 |
"return my prefix. |
|
6960 |
The suffix is the namepart after the final period character, |
|
6961 |
or the empty string, if the name does not contain a period." |
|
6962 |
||
6963 |
^ self prefixAndSuffix at:1 |
|
6964 |
||
6965 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6966 |
'abc.st' asFilename prefix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6967 |
'abc' asFilename prefix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6968 |
'a.b.c' asFilename prefix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6969 |
'a.b.c' asFilename prefix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6970 |
'a.' asFilename prefix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6971 |
'.a' asFilename prefix |
9453 | 6972 |
" |
6973 |
||
6974 |
"Modified: / 07-09-1995 / 11:09:03 / claus" |
|
6975 |
"Created: / 13-07-2006 / 10:27:19 / fm" |
|
6976 |
! |
|
6977 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6978 |
prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6979 |
"return an array consisting of my prefix and suffix. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6980 |
The suffix is the namepart after the final period character, |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6981 |
the prefix everything before, except for the period. |
1517 | 6982 |
The directory name part is stripped off (i.e. the returned prefix |
16578 | 6983 |
will consist of the file's basename only.) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6984 |
(on some systems, the suffix-character may be different from a period). |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6985 |
For example, foo.bar.baz has a prefix of 'foo.bar' and a suffix of '.baz'. |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
6986 |
An exception to the above: if the name starts with the suffixCharacter, |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
6987 |
that part is NOT considered a suffix. Thus, '.foorc' has no suffix and a prefix of |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
6988 |
'.foorc'. |
1517 | 6989 |
See also: #withoutSuffix and #withSuffix |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6990 |
Notice: |
24017 | 6991 |
there is currently no known system which uses other than |
6992 |
the period character as suffixCharacter." |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6993 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6994 |
|nm idx| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6995 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6996 |
nm := self baseName. |
15811 | 6997 |
idx := nm lastIndexOf:(self species suffixSeparator). |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
6998 |
"/ be careful: if the name consists only of suffix (i.e '.foo'), |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
6999 |
"/ the suffix is considered empty. |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
7000 |
((idx == 1) or:[ idx == 0 ]) ifTrue:[ |
24017 | 7001 |
^ Array with:nm with:'' |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
7002 |
]. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7003 |
^ Array |
24017 | 7004 |
with:(nm copyTo:idx-1) |
7005 |
with:(nm copyFrom:idx+1) |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7006 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7007 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7008 |
'abc.st' asFilename prefixAndSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7009 |
'abc' asFilename prefixAndSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7010 |
'a.b.c' asFilename prefixAndSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7011 |
'/foo/bar.c/baz.c' asFilename prefixAndSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7012 |
'a.' asFilename prefixAndSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7013 |
'.a' asFilename prefixAndSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7014 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7015 |
|parts| |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
7016 |
parts := 'Object.st' asFilename prefixAndSuffix. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7017 |
((parts at:1) , '.o') asFilename |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
7018 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
7019 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
7020 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1517 | 7021 |
"Modified: 3.7.1996 / 10:53:10 / cg" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
7022 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
7023 |
|
2906 | 7024 |
suffix |
7025 |
"return my suffix. |
|
7026 |
The suffix is the namepart after the final period character, |
|
7027 |
or the empty string, if the name does not contain a period." |
|
7028 |
||
7029 |
^ self prefixAndSuffix at:2 |
|
7030 |
||
7031 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7032 |
'abc.st' asFilename suffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7033 |
'abc' asFilename suffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7034 |
'a.b.c' asFilename suffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7035 |
'a.b.c' asFilename suffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7036 |
'a.' asFilename suffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7037 |
'.a' asFilename suffix |
2906 | 7038 |
" |
7039 |
||
7040 |
"Modified: 7.9.1995 / 11:09:03 / claus" |
|
7041 |
! |
|
7042 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
7043 |
withSuffix:aSuffix |
19440 | 7044 |
"return a new filename for the receiver's name with a different suffix. |
6256 | 7045 |
If the name already has a suffix, the new suffix replaces it; |
1993 | 7046 |
otherwise, the new suffix is simply appended to the name." |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
7047 |
|
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
7048 |
aSuffix isEmptyOrNil ifTrue:[ |
24013 | 7049 |
^ self. |
6262 | 7050 |
]. |
7051 |
||
15811 | 7052 |
^ self species named: |
24013 | 7053 |
(self nameWithoutSuffix |
7054 |
, self class suffixSeparator asString |
|
7055 |
, aSuffix asString) |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7056 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7057 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7058 |
'abc.st' asFilename withSuffix:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7059 |
'a.b.c' asFilename withSuffix:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7060 |
'.b.c.' asFilename withSuffix:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7061 |
'.b.c' asFilename withSuffix:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7062 |
'.c.' asFilename withSuffix:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7063 |
'.c' asFilename withSuffix:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7064 |
'c.' asFilename withSuffix:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7065 |
'.' asFilename withSuffix:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7066 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7067 |
'abc.st' asFilename withSuffix:'o' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7068 |
'abc' asFilename withSuffix:'o' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7069 |
'a.b.c' asFilename withSuffix:'o' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7070 |
'a.b.c.' asFilename withSuffix:'o' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7071 |
'.b.c.' asFilename withSuffix:'o' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7072 |
'.c.' asFilename withSuffix:'o' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7073 |
'.c' asFilename withSuffix:'o' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7074 |
'c.' asFilename withSuffix:'o' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7075 |
'.' asFilename withSuffix:'o' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7076 |
'/foo/bar/baz.st' asFilename withSuffix:'c' |
24013 | 7077 |
'/foo/bar/baz.c' asFilename withSuffix:'.st' |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7078 |
'/foo/bar.c/baz.c' asFilename withSuffix:'st' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7079 |
'/foo/bar.c/baz' asFilename withSuffix:'st' |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
7080 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
7081 |
|
10155 | 7082 |
"Modified: / 07-09-1995 / 11:15:42 / claus" |
7083 |
"Modified: / 07-11-2006 / 13:58:45 / cg" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
7084 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
7085 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
7086 |
withoutSuffix |
19440 | 7087 |
"return a new filename for the receiver's name without the suffix. |
10155 | 7088 |
If the name has no suffix, a filename representing the same file as the receiver is returned." |
7089 |
||
7090 |
|n| |
|
7091 |
||
7092 |
n := self nameWithoutSuffix. |
|
7093 |
n = nameString ifTrue:[^ self]. |
|
15811 | 7094 |
^ self species named:n |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
7095 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
7096 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7097 |
'abc.st' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7098 |
'abc' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7099 |
'/abc' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7100 |
'/abc.d' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7101 |
'./abc' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7102 |
'./abc.d' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7103 |
'./.abc' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7104 |
'a.b.c' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7105 |
'a.b.' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7106 |
'.b.c' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7107 |
'.b.' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7108 |
'.b' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7109 |
'/foo/bar/baz.c' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7110 |
'/foo/bar.x/baz.c' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7111 |
'/foo/bar.x/baz' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7112 |
'/foo/bar/baz/foo.c/bar' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7113 |
'/foo/bar/baz/foo.c/bar.c' asFilename withoutSuffix |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
7114 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
7115 |
|
10155 | 7116 |
"Modified: / 07-09-1995 / 11:15:42 / claus" |
7117 |
"Modified: / 07-11-2006 / 13:57:45 / cg" |
|
174 | 7118 |
! ! |
7119 |
||
5597 | 7120 |
!Filename methodsFor:'testing'! |
7121 |
||
7122 |
isFilename |
|
7123 |
"return true, if the receiver is some kind of filename; |
|
7124 |
false is returned here - the method is redefined from Object." |
|
7125 |
||
7126 |
^true |
|
7127 |
||
7128 |
||
7129 |
! ! |
|
7130 |
||
10271 | 7131 |
!Filename methodsFor:'writing-files'! |
7132 |
||
14512 | 7133 |
appendingFileDo:aBlock |
7134 |
"create a append-stream on the receiver file, evaluate aBlock, passing that stream as arg, |
|
19088 | 7135 |
and return the block's value. |
14512 | 7136 |
If the file cannot be opened, an exception is raised. |
7137 |
Ensures that the stream is closed." |
|
7138 |
||
23667 | 7139 |
|stream| |
7140 |
||
7141 |
stream := self appendStream. |
|
7142 |
^ [ |
|
7143 |
aBlock value:stream |
|
14512 | 7144 |
] ensure:[ |
22448 | 7145 |
stream close |
14512 | 7146 |
]. |
7147 |
||
7148 |
" |
|
14513 | 7149 |
'ttt' asFilename appendingFileDo:[:s | |
22448 | 7150 |
s nextPutLine:'hello'. |
7151 |
s nextPutLine:'world'. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7152 |
] |
14512 | 7153 |
" |
7154 |
||
7155 |
"Created: / 09-11-2012 / 10:07:41 / sr" |
|
23667 | 7156 |
"Modified: / 06-02-2019 / 11:37:58 / Stefan Vogel" |
14512 | 7157 |
! |
7158 |
||
23253 | 7159 |
contents:aStringOrByteArrayOrCollectionOfLines |
10271 | 7160 |
"create (or overwrite) a file given its contents as a collection of lines. |
7161 |
Raises an error, if the file is unwritable." |
|
7162 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7163 |
^ self |
23253 | 7164 |
writingFileDo:[:s | |
7165 |
aStringOrByteArrayOrCollectionOfLines isNonByteCollection ifTrue:[ |
|
7166 |
"a StringCollection or a collection of lines" |
|
7167 |
aStringOrByteArrayOrCollectionOfLines do:[:each | s nextPutLine:(each ? '')] |
|
7168 |
] ifFalse:[ |
|
7169 |
"something string-like" |
|
7170 |
aStringOrByteArrayOrCollectionOfLines isString ifFalse:[ |
|
7171 |
s binary |
|
7172 |
]. |
|
7173 |
s nextPutAll:aStringOrByteArrayOrCollectionOfLines |
|
7174 |
] |
|
7175 |
]. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7176 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7177 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7178 |
'foo1' asFilename contents:#('one' 'two' 'three') |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7179 |
'foo2' asFilename contents:'Hello world' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
7180 |
'foo3' asFilename contents:#[1 2 3 4 5] |
10271 | 7181 |
" |
7182 |
||
7183 |
"Created: / 11-12-2006 / 14:11:21 / cg" |
|
10779 | 7184 |
"Modified: / 08-11-2007 / 13:28:41 / cg" |
23253 | 7185 |
"Modified (format): / 01-08-2018 / 18:11:58 / Claus Gittinger" |
10271 | 7186 |
! |
7187 |
||
7188 |
writingFileDo:aBlock |
|
23939 | 7189 |
"create a write-stream on the receiver file, evaluate aBlock, |
7190 |
passing that stream as arg, |
|
19088 | 7191 |
and return the block's value. |
10271 | 7192 |
If the file cannot be opened, an exception is raised. |
7193 |
Ensures that the stream is closed." |
|
7194 |
||
23667 | 7195 |
|stream| |
7196 |
||
7197 |
stream := self writeStream. |
|
7198 |
^ [ |
|
7199 |
aBlock value:stream |
|
10271 | 7200 |
] ensure:[ |
22448 | 7201 |
stream close |
10271 | 7202 |
]. |
7203 |
||
7204 |
" |
|
7205 |
'ttt' asFilename writingFileDo:[:s | |
|
22448 | 7206 |
s nextPutLine:'hello'. |
7207 |
s nextPutLine:'world'. |
|
10271 | 7208 |
] |
7209 |
" |
|
7210 |
||
7211 |
"Created: / 11-12-2006 / 14:09:39 / cg" |
|
23667 | 7212 |
"Modified: / 06-02-2019 / 11:37:37 / Stefan Vogel" |
23939 | 7213 |
"Modified (comment): / 18-03-2019 / 11:29:44 / Claus Gittinger" |
10271 | 7214 |
! ! |
7215 |
||
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
7216 |
!Filename class methodsFor:'documentation'! |
630 | 7217 |
|
7218 |
version |
|
18490 | 7219 |
^ '$Header$' |
12318 | 7220 |
! |
7221 |
||
7222 |
version_CVS |
|
18490 | 7223 |
^ '$Header$' |
630 | 7224 |
! ! |
6771 | 7225 |
|
14628 | 7226 |
|
2906 | 7227 |
Filename initialize! |