author | Claus Gittinger <cg@exept.de> |
Sun, 30 Sep 2018 11:02:47 +0200 | |
changeset 23393 | 6f06e66359ca |
parent 23332 | 92a3564b47ab |
child 23407 | 98893f399451 |
permissions | -rw-r--r-- |
18272 | 1 |
"{ Encoding: utf8 }" |
2 |
||
1 | 3 |
" |
5 | 4 |
COPYRIGHT (c) 1992 by Claus Gittinger |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
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 |
14567 | 19 |
instanceVariableNames:'nameString' |
20452 | 20 |
classVariableNames:'ConcreteClass DefaultTempDirectory TempDirectory' |
14567 | 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 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
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 ?: |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
94 |
[exBegin] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
95 |
|f| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
96 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
97 |
f := 'foobar' asFilename. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
98 |
^ f exists |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
99 |
[exEnd] |
360 | 100 |
|
101 |
||
102 |
is it a directory ?: |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
103 |
[exBegin] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
104 |
|f| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
105 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
106 |
f := '/tmp' asFilename. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
107 |
^ f isDirectory. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
108 |
[exEnd] |
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: |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
112 |
[exBegin] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
113 |
^ Filename defaultDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
114 |
[exEnd] |
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): |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
119 |
[exBegin] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
120 |
|f| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
121 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
122 |
f := '..' asFilename. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
123 |
^ f pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
124 |
[exEnd] |
360 | 125 |
|
126 |
||
127 |
get a directories directory: |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
128 |
[exBegin] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
129 |
|f| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
130 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
131 |
f := Filename defaultDirectory. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
132 |
^ f directory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
133 |
[exEnd] |
360 | 134 |
|
135 |
||
136 |
get a files directory: |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
137 |
[exBegin] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
138 |
|f| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
139 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
140 |
f := './smalltalk' asFilename. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
141 |
^ f directory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
142 |
[exEnd] |
360 | 143 |
|
144 |
||
145 |
getting access & modification times: |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
146 |
[exBegin] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
147 |
|f| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
148 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
149 |
f := '/tmp' asFilename. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
150 |
^ f dates |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
151 |
[exEnd] |
360 | 152 |
|
153 |
access time only: |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
154 |
[exBegin] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
155 |
|f| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
156 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
157 |
f := '/tmp' asFilename. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
158 |
^ f dates at:#accessed |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
159 |
[exEnd] |
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: |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
163 |
[exBegin] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
164 |
|f| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
165 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
166 |
f := '/tmp' asFilename. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
167 |
^ f info |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
168 |
[exEnd] |
360 | 169 |
|
170 |
||
171 |
getting a temporary file (unique name): |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
172 |
[exBegin] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
173 |
|f| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
174 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
175 |
f := Filename newTemporary. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
176 |
^ f |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
177 |
[exEnd] |
360 | 178 |
|
179 |
creating, writing, reading and removing a temporary file: |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
180 |
[exBegin] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
181 |
|f writeStream readStream| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
182 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
183 |
f := Filename newTemporary. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
184 |
writeStream := f writeStream. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
185 |
writeStream nextPutAll:'hello world'. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
186 |
writeStream cr. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
187 |
writeStream close. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
188 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
189 |
'contents (as seen by unix''s cat command:' printNL. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
190 |
OperatingSystem executeCommand:('cat ' , f pathName). |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
191 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
192 |
readStream := f readStream. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
193 |
Transcript showCR:'contents as seen by smalltalk:'. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
194 |
Transcript showCR:(readStream upToEnd). |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
195 |
readStream close. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
196 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
197 |
f delete. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
198 |
[exEnd] |
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: |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
202 |
[exBegin] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
203 |
|f files| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
204 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
205 |
f := Filename currentDirectory. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
206 |
files := f directoryContents. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
207 |
Transcript showCR:'the files are:'. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
208 |
Transcript showCR:(files printString). |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
209 |
[exEnd] |
360 | 210 |
|
211 |
||
212 |
editing a file: |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
213 |
[exBegin] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
214 |
|f| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
215 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
216 |
f := Filename newTemporary. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
217 |
(f writeStream) nextPutAll:'hello world'; close. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
218 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
219 |
f edit |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
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:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
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:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
244 |
ConcreteClass := UnixFilename |
8754 | 245 |
] ifFalse:[OperatingSystem isMSDOSlike ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
246 |
ConcreteClass := PCFilename |
8754 | 247 |
] ifFalse:[OperatingSystem isVMSlike ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
248 |
ConcreteClass := OpenVMSFilename |
2906 | 249 |
] ifFalse:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
250 |
self error:'Filename: unknown OperatingSystem when initializing concrete Filename class'. |
8754 | 251 |
]]]. |
252 |
||
253 |
ConcreteClass isNil ifTrue:[ |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
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:[ |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
291 |
exeName := OperatingSystem nameOfSTXExecutable. |
17227 | 292 |
] ifFalse:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
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 |
||
309 |
|s dir| |
|
12972 | 310 |
|
311 |
s := OperatingSystem getApplicationDataDirectoryFor:appName. |
|
312 |
s isNil ifTrue:[ |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
313 |
^ self homeDirectory |
12972 | 314 |
]. |
12974 | 315 |
dir := self named:s. |
316 |
dir exists ifFalse:[ |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
317 |
dir makeDirectory |
12974 | 318 |
]. |
319 |
^ dir |
|
12972 | 320 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
321 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
322 |
Filename applicationDataDirectoryFor:'smalltalk' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
323 |
Filename applicationDataDirectoryFor:'expecco' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
324 |
applicationDataDirectoryFor:'expecco' |
12972 | 325 |
" |
326 |
||
327 |
"Created: / 29-07-2010 / 12:05:35 / sr" |
|
328 |
! |
|
329 |
||
3959 | 330 |
currentDirectory |
331 |
"return a filename for the current directory" |
|
332 |
||
13109 | 333 |
^ self named:(OperatingSystem getCurrentDirectory). |
3959 | 334 |
|
335 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
336 |
Filename currentDirectory |
3959 | 337 |
" |
338 |
! |
|
339 |
||
340 |
defaultDirectory |
|
341 |
"ST80 compatibility: same as currentDirectory" |
|
342 |
||
343 |
^ self currentDirectory |
|
344 |
||
345 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
346 |
Filename defaultDirectory |
3959 | 347 |
" |
348 |
! |
|
349 |
||
12336
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
350 |
defaultTempDirectory |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
351 |
"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
|
352 |
That is the same as TempDirectory, except that TempDirectory can be changed |
17048 | 353 |
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
|
354 |
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
|
355 |
|
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
356 |
DefaultTempDirectory isNil ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
357 |
self tempDirectory. "/ actually sets DefaultTempDirectory as side effect |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
358 |
DefaultTempDirectory isNil ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
359 |
DefaultTempDirectory := TempDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
360 |
]. |
12336
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
361 |
]. |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
362 |
|
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
363 |
DefaultTempDirectory exists ifFalse:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
364 |
DefaultTempDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
365 |
makeDirectory; |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
366 |
addAccessRights:#(readUser readGroup readOthers |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
367 |
writeUser writeGroup writeOthers |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
368 |
executeUser executeGroup executeOthers |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
369 |
removeOnlyByOwner). |
12336
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
370 |
]. |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
371 |
^ DefaultTempDirectory |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
372 |
|
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
373 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
374 |
Filename tempDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
375 |
Filename defaultTempDirectory |
12336
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
376 |
" |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
377 |
|
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
378 |
"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
|
379 |
"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
|
380 |
! |
7610de9a7e4b
provide access to the default (original, unchanged) tempDirectory
Claus Gittinger <cg@exept.de>
parents:
12318
diff
changeset
|
381 |
|
10546 | 382 |
desktopDirectory |
383 |
"return your desktop directory. |
|
20413 | 384 |
Under windows, that's the real desktop directory; |
10546 | 385 |
under other OperatingSystems, the home directory is returned." |
386 |
||
387 |
|s| |
|
388 |
||
389 |
s := OperatingSystem getDesktopDirectory. |
|
390 |
s isNil ifTrue:[ |
|
20413 | 391 |
^ self homeDirectory |
10546 | 392 |
]. |
393 |
^ self named:s |
|
394 |
||
395 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
396 |
Filename desktopDirectory |
10546 | 397 |
" |
398 |
||
399 |
"Created: / 16-05-2007 / 13:18:34 / cg" |
|
400 |
! |
|
401 |
||
11763 | 402 |
documentsDirectory |
403 |
"return your documents directory. |
|
20413 | 404 |
Under windows, that's the real 'Documents' or 'My Documents'; |
11763 | 405 |
under other OperatingSystems, the home directory is returned." |
406 |
||
407 |
|s| |
|
408 |
||
409 |
s := OperatingSystem getDocumentsDirectory. |
|
410 |
s isNil ifTrue:[ |
|
20413 | 411 |
^ self homeDirectory |
11763 | 412 |
]. |
413 |
^ self named:s |
|
414 |
||
415 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
416 |
Filename documentsDirectory |
11763 | 417 |
" |
418 |
||
419 |
"Created: / 16-05-2007 / 13:18:34 / cg" |
|
420 |
! |
|
421 |
||
22676 | 422 |
downloadsDirectory |
423 |
"return the downloads directory. |
|
424 |
Some OperatingSystems do not support this - on those, |
|
425 |
the documentsDirectory is returned. |
|
426 |
Notice: services under windows do not have a user/home and therefore |
|
427 |
no downloads directory." |
|
428 |
||
429 |
|home dir| |
|
430 |
||
431 |
home := self homeDirectory. |
|
432 |
home isNil ifTrue:[^ nil]. |
|
433 |
#( |
|
434 |
'Downloads' |
|
435 |
'downloads' |
|
436 |
'Download' |
|
437 |
'download' |
|
438 |
) do:[:eachTry | |
|
439 |
(dir := home / eachTry) exists ifTrue:[ |
|
440 |
^ dir |
|
441 |
]. |
|
442 |
]. |
|
443 |
^ nil |
|
444 |
||
445 |
" |
|
446 |
Filename downloadsDirectory |
|
447 |
" |
|
448 |
! |
|
449 |
||
3959 | 450 |
findDefaultDirectory |
451 |
"same as #defaultDirectory for ST80 compatibility" |
|
452 |
||
453 |
^ self defaultDirectory |
|
454 |
||
455 |
"Created: 20.6.1997 / 17:00:29 / cg" |
|
456 |
! |
|
457 |
||
458 |
fromComponents:aCollectionOfDirectoryNames |
|
459 |
"create & return a new filename from components given in |
|
460 |
aCollectionOfDirectoryNames. If the first component is the name of the |
|
461 |
root directory (i.e. '/') an absolute path-filename is returned." |
|
462 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
463 |
self isAbstract ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
464 |
^ ConcreteClass fromComponents:aCollectionOfDirectoryNames |
3959 | 465 |
]. |
466 |
||
6802 | 467 |
^ self named:(self nameFromComponents:aCollectionOfDirectoryNames) |
3959 | 468 |
|
469 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
470 |
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
|
471 |
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
|
472 |
UnixFilename fromComponents:#('/' 'foo' 'bar' 'baz') |
8754 | 473 |
OpenVMSFilename fromComponents:#('foo' 'bar' 'baz') |
474 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
475 |
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
|
476 |
Filename fromComponents:#('/') |
3959 | 477 |
|
478 |
Filename fromComponents: |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
479 |
(Filename components:('.' asFilename pathName)) |
3959 | 480 |
|
481 |
Filename fromComponents: |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
482 |
(Filename components:('.' asFilename name)) |
3959 | 483 |
" |
484 |
||
485 |
"Modified: 8.9.1997 / 00:23:16 / cg" |
|
486 |
! |
|
487 |
||
488 |
fromUser |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
489 |
"show a box to enter a filename. |
3959 | 490 |
Return a filename instance or nil (if cancel was pressed)." |
491 |
||
492 |
|name| |
|
493 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
494 |
name := Dialog |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
495 |
requestFileName:'filename:' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
496 |
default:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
497 |
fromDirectory:(FileSelectionBox lastFileSelectionDirectory). |
8738 | 498 |
|
499 |
name notEmptyOrNil ifTrue:[ |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
500 |
^ self named:name |
3978
b2babde0857b
use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents:
3959
diff
changeset
|
501 |
]. |
3959 | 502 |
^ nil |
503 |
||
504 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
505 |
Filename fromUser |
3959 | 506 |
" |
507 |
||
508 |
"Modified: 19.4.1996 / 13:57:44 / cg" |
|
509 |
! |
|
510 |
||
511 |
homeDirectory |
|
512 |
"return your homeDirectory. |
|
513 |
Some OperatingSystems do not support this - on those, the defaultDirectory |
|
17113 | 514 |
(which is the currentDirectory) is returned. |
515 |
Notice: services under windows also do not have a home directory." |
|
3959 | 516 |
|
517 |
|s| |
|
518 |
||
519 |
s := OperatingSystem getHomeDirectory. |
|
520 |
s isNil ifTrue:[ |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
521 |
^ self defaultDirectory |
3959 | 522 |
]. |
523 |
^ self named:s |
|
524 |
||
525 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
526 |
Filename homeDirectory |
3959 | 527 |
" |
528 |
||
529 |
"Modified: 8.9.1997 / 00:25:23 / cg" |
|
530 |
! |
|
531 |
||
532 |
named:aString |
|
533 |
"return a filename for a directory named aString. |
|
534 |
This is the same as 'aString asFilename'." |
|
535 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
536 |
self isAbstract ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
537 |
^ ConcreteClass named:aString |
3959 | 538 |
]. |
8738 | 539 |
^ self basicNew setName:aString |
3959 | 540 |
|
541 |
" |
|
542 |
Filename named:'/tmp/fooBar' |
|
543 |
" |
|
544 |
||
545 |
"Modified: 7.9.1997 / 23:30:06 / cg" |
|
546 |
! |
|
547 |
||
548 |
newTemporary |
|
549 |
"return a new unique filename - use this for temporary files. |
|
550 |
The filenames returned are '/tmp/stxtmp_xx_nn' where xx is our |
|
551 |
unix process id, and nn is a unique number, incremented with every |
|
552 |
call to this method. |
|
23043 | 553 |
If any of the environment variables STX_TMPDIR, ST_TMPDIR, TMPDIR is set, |
4757 | 554 |
its value defines the temp directory. |
555 |
Notice, that no file is created by this - only a unique name |
|
15459 | 556 |
is generated. |
557 |
||
16787 | 558 |
DO NOT USE THIS FOR PLAIN FILES - IT IS UNSECURE use FileStream>>#newTemporary |
559 |
(the insecurity is due to a small chance for some other program to open/create |
|
560 |
the file, as only a name is generated here. However, chances are small as the name |
|
561 |
is reasonably random - but for security relevant applications, this may be relevant) |
|
562 |
" |
|
3959 | 563 |
|
9912 | 564 |
^ self newTemporaryIn:(self tempDirectory) |
3959 | 565 |
|
566 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
567 |
Filename newTemporary |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
568 |
Filename newTemporary |
3959 | 569 |
" |
570 |
||
23043 | 571 |
"Modified: / 07-09-1995 / 10:48:31 / claus" |
572 |
"Modified: / 07-03-1996 / 14:51:33 / cg" |
|
573 |
"Modified (comment): / 31-05-2018 / 09:57:58 / Claus Gittinger" |
|
3959 | 574 |
! |
575 |
||
9912 | 576 |
newTemporaryDirectory |
577 |
"return a new unique temporary directory - use this for temporary files. |
|
578 |
The directories returned are '/tmp/stxtmp_xx_nn' where xx is our |
|
579 |
unix process id, and nn is a unique number, incremented with every |
|
580 |
call to this method. |
|
23043 | 581 |
If any of the environment variables STX_TMPDIR, ST_TMPDIR, TMPDIR is set, |
9912 | 582 |
its value defines the temp directory." |
583 |
||
584 |
^ self newTemporaryDirectoryIn:(self tempDirectory) |
|
23043 | 585 |
|
586 |
"Modified (comment): / 31-05-2018 / 09:57:54 / Claus Gittinger" |
|
9912 | 587 |
! |
588 |
||
589 |
newTemporaryDirectoryIn:aDirectoryOrNil |
|
590 |
"return a new unique temporary directory in another directory, or the current dir. |
|
591 |
Use this for temporary files. |
|
592 |
The directories returned are '/tmp/stxtmp_xx_nn' where xx is our |
|
593 |
unix process id, and nn is a unique number, incremented with every |
|
594 |
call to this method. |
|
23043 | 595 |
If any of the environment variables STX_TMPDIR, ST_TMPDIR, TMPDIR... is set, |
9912 | 596 |
its value defines the temp directory." |
597 |
||
598 |
|tempdir| |
|
599 |
||
15811 | 600 |
tempdir := self newTemporaryIn:aDirectoryOrNil. |
9912 | 601 |
tempdir exists ifTrue:[ |
23043 | 602 |
tempdir recursiveRemove. |
9912 | 603 |
]. |
604 |
tempdir makeDirectory. |
|
605 |
^ tempdir |
|
23043 | 606 |
|
607 |
"Modified (comment): / 31-05-2018 / 09:57:49 / Claus Gittinger" |
|
9912 | 608 |
! |
609 |
||
610 |
newTemporaryIn:aDirectoryOrNil |
|
3959 | 611 |
"return a new unique filename - use this for temporary files. |
612 |
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
|
613 |
where xx is our unix process id, and nn is a unique number, incremented |
3959 | 614 |
with every call to this method. |
615 |
Notice: only a unique filename object is created and returned - no physical |
|
616 |
file is created by this method (i.e. you have to send #writeStream or |
|
617 |
whatever to it in order to really create something). |
|
15459 | 618 |
See also: #newTemporary which looks for a good temp directory. |
619 |
||
620 |
DO NOT USE THIS FOR PLAIN FILES - IT IS UNSECURE use FileStream>>#newTemporaryIn:" |
|
3959 | 621 |
|
12617 | 622 |
^ self newTemporaryIn:aDirectoryOrNil nameTemplate:(self tempFileNameTemplate) |
3959 | 623 |
|
624 |
"temp files in '/tmp': |
|
625 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
626 |
Filename newTemporary |
19665 | 627 |
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
|
628 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
629 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
630 |
"temp files somewhere |
3959 | 631 |
(not recommended - use above since it can be controlled via shell variables): |
632 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
633 |
UnixFilename newTemporaryIn:'/tmp' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
634 |
UnixFilename newTemporaryIn:'/tmp' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
635 |
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
|
636 |
UnixFilename newTemporaryIn:'/' |
3959 | 637 |
" |
638 |
||
639 |
"a local temp file: |
|
640 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
641 |
Filename newTemporaryIn:'' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
642 |
Filename newTemporaryIn:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
643 |
Filename newTemporaryIn:'.' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
644 |
Filename newTemporaryIn:('source' asFilename) |
3959 | 645 |
" |
646 |
||
647 |
"Modified: / 7.9.1995 / 10:48:31 / claus" |
|
648 |
"Modified: / 11.8.1998 / 22:51:43 / cg" |
|
649 |
! |
|
650 |
||
9912 | 651 |
newTemporaryIn:aDirectoryOrNil nameTemplate:template |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
652 |
"return a new unique filename - use this for temporary files. |
9912 | 653 |
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
|
654 |
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
|
655 |
with every call to this method respectively. |
19665 | 656 |
If the template does not contain %-meta characters, and the file already exists, |
657 |
a sequence of _1, _2,... is appended to the name. This is dangerous, as it does not prevent race |
|
658 |
conditions (if two such files are created at the same time). |
|
659 |
||
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
660 |
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
|
661 |
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
|
662 |
whatever to it in order to really create something). |
15459 | 663 |
See also: #newTemporary which looks for a good temp directory. |
664 |
||
665 |
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
|
666 |
|
19665 | 667 |
|newTempFilename oldNameString nextSeqNr| |
8738 | 668 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
669 |
self isAbstract ifTrue:[ |
19665 | 670 |
^ ConcreteClass newTemporaryIn:aDirectoryOrNil nameTemplate:template |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
671 |
]. |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
672 |
|
8738 | 673 |
"although the above allows things to be redefined in concrete classes, |
674 |
the following should work on all systems ..." |
|
675 |
||
676 |
[ |
|
19665 | 677 |
|nameString fn| |
678 |
||
679 |
"Use random numbers in order to improve the security |
|
680 |
by making the generated names less predictable" |
|
681 |
nameString := template bindWith:(OperatingSystem getProcessId) with:(RandomGenerator nextLettersOrDigits:4). |
|
682 |
(oldNameString = nameString) ifTrue:[ |
|
683 |
"/ ouch - the given template seems to not generate unique file names. |
|
684 |
"/ append a sequence number |
|
685 |
nextSeqNr := (nextSeqNr ? 0) + 1. |
|
686 |
fn := nameString asFilename. |
|
687 |
nameString := fn withoutSuffix name,'_',nextSeqNr asString,'.' , fn suffix. |
|
688 |
]. |
|
689 |
||
690 |
aDirectoryOrNil isNil ifTrue:[ |
|
691 |
newTempFilename := self named:nameString |
|
692 |
] ifFalse:[ |
|
693 |
newTempFilename := aDirectoryOrNil asFilename construct:nameString |
|
694 |
]. |
|
695 |
oldNameString := nameString. |
|
8738 | 696 |
] doWhile:[ |
19665 | 697 |
"care for existing leftOver tempFiles |
698 |
from a previous boot of the OS |
|
699 |
i.e. my pid could be the same as when executed |
|
700 |
the last time before system reboot ...)" |
|
701 |
||
702 |
newTempFilename exists |
|
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
703 |
]. |
8738 | 704 |
^ newTempFilename |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
705 |
|
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
706 |
"temp files in '/tmp': |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
707 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
708 |
Filename newTemporary |
19665 | 709 |
Filename newTemporaryIn:nil nameTemplate:'out_%1_%2.txt' |
710 |
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
|
711 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
712 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
713 |
"temp files somewhere |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
714 |
(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
|
715 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
716 |
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
|
717 |
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
|
718 |
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
|
719 |
UnixFilename newTemporaryIn:'/' nameTemplate:'foo%1_%2' |
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 |
|
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
722 |
"a local temp file: |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
723 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
724 |
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
|
725 |
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
|
726 |
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
|
727 |
Filename newTemporaryIn:('source' asFilename) nameTemplate:'foo%1_%2' |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
728 |
" |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
729 |
|
12918
a9de9243a951
changed: #newTemporaryIn:nameTemplate:
Claus Gittinger <cg@exept.de>
parents:
12910
diff
changeset
|
730 |
"Modified: / 07-09-1995 / 10:48:31 / claus" |
a9de9243a951
changed: #newTemporaryIn:nameTemplate:
Claus Gittinger <cg@exept.de>
parents:
12910
diff
changeset
|
731 |
"Modified: / 07-05-2010 / 11:46:05 / cg" |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
732 |
! |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
733 |
|
4199 | 734 |
nullDevice |
735 |
"return the filename of the nullDevice (if available). |
|
736 |
returns nil, if the OperatingSystem does not support this." |
|
737 |
||
738 |
|s| |
|
739 |
||
8754 | 740 |
s := self nullFilename. |
4199 | 741 |
s isNil ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
742 |
^ nil |
4199 | 743 |
]. |
744 |
^ self named:s |
|
745 |
||
746 |
" |
|
8754 | 747 |
Filename nullDevice |
748 |
UnixFilename nullDevice |
|
749 |
PCFilename nullDevice |
|
4199 | 750 |
" |
751 |
||
752 |
"Created: / 19.5.1999 / 12:24:26 / cg" |
|
753 |
! |
|
754 |
||
6256 | 755 |
remoteHost:remoteHostString rootComponents:aCollectionOfDirectoryNames |
756 |
"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
|
757 |
aCollectionOfDirectoryNames on a host named remoteHostString. |
6256 | 758 |
An absolute network-filename is returned." |
759 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
760 |
self isAbstract ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
761 |
^ ConcreteClass remoteHost:remoteHostString |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
762 |
rootComponents:aCollectionOfDirectoryNames |
6256 | 763 |
]. |
764 |
||
10390 | 765 |
remoteHostString notEmptyOrNil ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
766 |
self error:'remote hosts are not supported by OS' |
10390 | 767 |
]. |
768 |
||
769 |
^ self rootComponents:aCollectionOfDirectoryNames |
|
770 |
||
771 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
772 |
'file:///tmp/test' asURI asFilename |
10390 | 773 |
" |
6256 | 774 |
! |
775 |
||
776 |
rootComponents:aCollectionOfDirectoryNames |
|
777 |
"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
|
778 |
aCollectionOfDirectoryNames. |
6256 | 779 |
An absolute path-filename is returned." |
780 |
||
781 |
|sep s| |
|
782 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
783 |
self isAbstract ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
784 |
^ ConcreteClass rootComponents:aCollectionOfDirectoryNames |
6256 | 785 |
]. |
786 |
||
787 |
"/ fallBack - works on Unix & MSDOS |
|
788 |
||
8243 | 789 |
sep := self separatorString. |
18272 | 790 |
s := CharacterWriteStream new. |
6256 | 791 |
aCollectionOfDirectoryNames do:[:component | |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
792 |
component ~= sep ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
793 |
s nextPutAll:sep; nextPutAll:component |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
794 |
] |
6256 | 795 |
]. |
796 |
s := s contents. |
|
797 |
s size == 0 ifTrue:[s := sep]. |
|
798 |
^ self named:s |
|
799 |
||
800 |
" |
|
8754 | 801 |
Filename rootComponents:#('/' 'foo' 'bar' 'baz') |
802 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
803 |
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
|
804 |
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
|
805 |
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
|
806 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
807 |
Filename rootComponents:#('/') |
6256 | 808 |
|
809 |
Filename rootComponents: |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
810 |
(Filename components:('.' asFilename pathName)) |
6256 | 811 |
|
812 |
Filename rootComponents: |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
813 |
(Filename components:('.' asFilename name)) |
6256 | 814 |
" |
815 |
||
816 |
"Modified: 8.9.1997 / 00:23:16 / cg" |
|
817 |
! |
|
818 |
||
3959 | 819 |
rootDirectory |
820 |
"return a filename for the root directory" |
|
821 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
822 |
self isAbstract ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
823 |
^ ConcreteClass rootDirectory |
3959 | 824 |
]. |
825 |
||
826 |
"/ fallBack - works on Unix & MSDOS (but not on VMS) |
|
827 |
||
8243 | 828 |
^ self named:(self separatorString) |
3959 | 829 |
|
830 |
" |
|
831 |
Filename rootDirectory |
|
832 |
" |
|
833 |
||
834 |
"Modified: 8.9.1997 / 00:24:15 / cg" |
|
835 |
! |
|
836 |
||
837 |
rootDirectoryOnVolume:aVolumeName |
|
838 |
"return a filename for the root directory on some volume" |
|
839 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
840 |
self isAbstract ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
841 |
^ ConcreteClass rootDirectoryOnVolume:aVolumeName |
3959 | 842 |
]. |
843 |
||
844 |
"/ fallBack - works on Unix (not on MSDOS or VMS) |
|
845 |
||
846 |
^ self rootDirectory |
|
847 |
||
848 |
" |
|
849 |
Filename rootDirectoryOnVolume:'/phys/idefix' |
|
850 |
Filename rootDirectoryOnVolume:'d:' |
|
851 |
" |
|
852 |
||
853 |
"Modified: / 5.10.1998 / 12:45:39 / cg" |
|
854 |
! |
|
855 |
||
856 |
tempDirectory |
|
857 |
"return the temp directory as a filename. |
|
23043 | 858 |
If any of the environment variables STX_TMPDIR, ST_TMPDIR, TMPDIR,... |
859 |
is set, its value defines the name, |
|
3959 | 860 |
otherwise, '/tmp' is used. (at least on unix ...). |
861 |
||
862 |
Notice: do not hardcode '/tmp' into your programs - things may be |
|
23043 | 863 |
different on other operating systems. Also, the user may want to set the |
864 |
TMPDIR environment variable to have her temp files somewhere else." |
|
3959 | 865 |
|
866 |
|tempDir| |
|
867 |
||
9806 | 868 |
TempDirectory isNil ifTrue:[ |
23043 | 869 |
tempDir := self named:(self defaultTempDirectoryName pathName). |
870 |
tempDir exists ifFalse:[ |
|
871 |
tempDir |
|
872 |
makeDirectory; |
|
873 |
addAccessRights:#(readUser readGroup readOthers |
|
874 |
writeUser writeGroup writeOthers |
|
875 |
executeUser executeGroup executeOthers |
|
876 |
removeOnlyByOwner). |
|
877 |
]. |
|
878 |
TempDirectory := DefaultTempDirectory := tempDir construct:'stx_tmp'. |
|
3959 | 879 |
]. |
10551
4924bf1ce2e3
#tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents:
10546
diff
changeset
|
880 |
|
4924bf1ce2e3
#tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents:
10546
diff
changeset
|
881 |
"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
|
882 |
by a cleanup (cron) job. |
19114 | 883 |
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
|
884 |
|
4924bf1ce2e3
#tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents:
10546
diff
changeset
|
885 |
TempDirectory exists ifFalse:[ |
23043 | 886 |
TempDirectory |
887 |
makeDirectory; |
|
888 |
addAccessRights:#(readUser readGroup readOthers |
|
889 |
writeUser writeGroup writeOthers |
|
890 |
executeUser executeGroup executeOthers |
|
891 |
removeOnlyByOwner). |
|
10551
4924bf1ce2e3
#tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents:
10546
diff
changeset
|
892 |
]. |
9806 | 893 |
^ TempDirectory |
3959 | 894 |
|
895 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
896 |
Filename tempDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
897 |
Filename tempDirectory pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
898 |
Filename tempDirectory exists |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
899 |
Filename tempDirectory isWritable |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
900 |
(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
|
901 |
(Filename tempDirectory construct:'foo') remove |
3959 | 902 |
" |
903 |
||
9806 | 904 |
"Created: / 07-03-1996 / 14:51:18 / cg" |
13781 | 905 |
"Modified: / 07-10-2011 / 18:39:25 / cg" |
23043 | 906 |
"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
|
907 |
! |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
908 |
|
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
909 |
tempDirectory:aFilename |
17048 | 910 |
"set the default temporary directory. |
911 |
This allows overwriting the automatically determined tmpDirectory |
|
912 |
by a knowledgable stand alone startup program. |
|
19114 | 913 |
Do not use elsewhere (and only if absolutely required)" |
11757
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
914 |
|
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
915 |
|temp| |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
916 |
|
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
917 |
aFilename isNil ifTrue:[ |
19599 | 918 |
TempDirectory := nil. |
919 |
^ self. |
|
11757
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
920 |
]. |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
921 |
|
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
922 |
temp := aFilename asFilename. |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
923 |
self assert:temp isDirectory. |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
924 |
TempDirectory := temp. |
16382 | 925 |
! |
926 |
||
927 |
trashDirectoryOrNil |
|
928 |
"if the underlying OS uses/supports a trash folder, |
|
929 |
return it. Otherwise return nil. |
|
930 |
Asks the OS for the pathname; for example, on OSX, '~/.Trash' is returned." |
|
931 |
||
932 |
|s| |
|
933 |
||
934 |
s := OperatingSystem getTrashDirectory. |
|
935 |
s isNil ifTrue:[ |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
936 |
^ nil |
16382 | 937 |
]. |
938 |
^ self named:s |
|
939 |
||
940 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
941 |
Filename desktopDirectory |
16382 | 942 |
" |
943 |
||
944 |
"Created: / 16-05-2007 / 13:18:34 / cg" |
|
16648 | 945 |
! |
946 |
||
947 |
usersPrivateSmalltalkDirectory |
|
948 |
^ Filename homeDirectory / '.smalltalk' |
|
949 |
||
950 |
" |
|
951 |
Filename usersPrivateSmalltalkDirectory |
|
952 |
" |
|
3959 | 953 |
! ! |
954 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
955 |
!Filename class methodsFor:'defaults'! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
956 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
957 |
concreteClass |
6256 | 958 |
"different subclasses of Filename are used for different |
959 |
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
|
960 |
|
2906 | 961 |
^ ConcreteClass ? self |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
962 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
963 |
"Created: 14.2.1997 / 16:36:13 / cg" |
2906 | 964 |
"Modified: 7.9.1997 / 23:29:20 / cg" |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
965 |
! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
966 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
967 |
defaultClass |
6256 | 968 |
"different subclasses of Filename are used for different |
969 |
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
|
970 |
|
2906 | 971 |
^ ConcreteClass |
972 |
||
973 |
"Modified: 8.9.1997 / 00:36:01 / cg" |
|
7836 | 974 |
! |
975 |
||
976 |
defaultTempDirectoryName |
|
977 |
"return the default temp directory as a filename. |
|
978 |
This is used, if no special preferences were defined in |
|
979 |
any of the TEMP-environment variables (see tempDirectory)." |
|
980 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
981 |
self isAbstract ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
982 |
^ ConcreteClass defaultTempDirectoryName |
7836 | 983 |
]. |
984 |
||
10994
1a3776d0b845
always return a fileName from defaultTempDirectoryName
fm
parents:
10969
diff
changeset
|
985 |
^ '/tmp' asFilename |
7836 | 986 |
|
987 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
988 |
Filename defaultTempDirectoryName |
7836 | 989 |
" |
990 |
||
991 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
|
992 |
"Created: 7.3.1996 / 14:51:18 / cg" |
|
993 |
"Modified: 8.9.1997 / 00:24:53 / cg" |
|
19599 | 994 |
! |
995 |
||
996 |
defaultVolumeName |
|
997 |
^ '/' |
|
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
998 |
! ! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
999 |
|
2922 | 1000 |
!Filename class methodsFor:'misc'! |
1001 |
||
3077 | 1002 |
filterSeps:aFilenameString |
1003 |
"ST80 compatibility: |
|
1004 |
filter out (invalid) separators in aFilenameString. |
|
1005 |
We recommend using #makeLegalFilename" |
|
1006 |
||
16762 | 1007 |
^ aFilenameString copyReplaceAll:(Character space) with:$_ ifNone:aFilenameString. |
3077 | 1008 |
|
1009 |
"Created: / 1.11.1997 / 12:39:50 / cg" |
|
3658 | 1010 |
"Modified: / 18.7.1998 / 22:53:24 / cg" |
3077 | 1011 |
! |
1012 |
||
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1013 |
nameWithSpecialExpansions:aString |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1014 |
"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
|
1015 |
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
|
1016 |
|
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1017 |
|dir user cutIdx idx userInfo| |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1018 |
|
19670 | 1019 |
(aString startsWith:$~) ifFalse:[ |
1020 |
^ aString. |
|
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1021 |
]. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1022 |
|
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1023 |
aString size > 1 ifTrue:[ |
19670 | 1024 |
idx := aString indexOf:self separator. |
1025 |
idx == 0 ifTrue:[ |
|
1026 |
"aString is '~user'" |
|
1027 |
user := aString copyFrom:2. |
|
1028 |
cutIdx := aString size + 1. |
|
1029 |
] ifFalse:[ |
|
1030 |
"aString is '~user/something'" |
|
1031 |
user := aString copyFrom:2 to:(idx - 1). |
|
1032 |
cutIdx := idx. |
|
1033 |
]. |
|
1034 |
user notEmpty ifTrue:[ |
|
1035 |
userInfo := OperatingSystem userInfoOf:user. |
|
1036 |
userInfo notNil ifTrue:[ |
|
1037 |
dir := userInfo at:#dir ifAbsent:nil. |
|
1038 |
]. |
|
1039 |
dir isNil ifTrue:[ |
|
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1040 |
"/ ('Filename [info]: unknown user: ' , user) infoPrintCR. |
19670 | 1041 |
^ aString |
1042 |
]. |
|
1043 |
]. |
|
14220
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 |
dir isNil ifTrue:[ |
19670 | 1046 |
"aString is '~' or '~/'" |
1047 |
dir := OperatingSystem getHomeDirectory. |
|
1048 |
cutIdx := 2. |
|
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1049 |
]. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1050 |
|
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1051 |
^ dir , (aString copyFrom:cutIdx) |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1052 |
|
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1053 |
" |
20709 | 1054 |
Filename nameWithSpecialExpansions:'~' |
1055 |
Filename nameWithSpecialExpansions:'~\work' |
|
1056 |
Filename nameWithSpecialExpansions:'~stefan' |
|
1057 |
Filename nameWithSpecialExpansions:'~stefan\work' |
|
1058 |
Filename nameWithSpecialExpansions:'~foo' |
|
1059 |
Filename nameWithSpecialExpansions:'~foo\bar' |
|
1060 |
" |
|
1061 |
||
1062 |
" |
|
1063 |
UnixFilename nameWithSpecialExpansions:'~' |
|
1064 |
UnixFilename nameWithSpecialExpansions:'~/work' |
|
1065 |
UnixFilename nameWithSpecialExpansions:'~stefan' |
|
1066 |
UnixFilename nameWithSpecialExpansions:'~stefan/work' |
|
1067 |
UnixFilename nameWithSpecialExpansions:'~foo' |
|
1068 |
UnixFilename nameWithSpecialExpansions:'~foo/bar' |
|
1069 |
" |
|
1070 |
||
1071 |
" |
|
1072 |
PCFilename nameWithSpecialExpansions:'~' |
|
1073 |
PCFilename nameWithSpecialExpansions:'~\work' |
|
1074 |
PCFilename nameWithSpecialExpansions:'~stefan' |
|
1075 |
PCFilename nameWithSpecialExpansions:'~stefan\work' |
|
1076 |
PCFilename nameWithSpecialExpansions:'~foo' |
|
1077 |
PCFilename nameWithSpecialExpansions:'~foo\bar' |
|
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1078 |
" |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1079 |
! |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1080 |
|
16999 | 1081 |
possiblyQuotedPathname:aPath |
1082 |
"return a filename path usable as command line argument, |
|
1083 |
by quoting in double quotes if there are any embedded special characters. |
|
1084 |
On Unix systems, special characters might also be prefixed by a backslash character." |
|
1085 |
||
19670 | 1086 |
(aPath startsWith:$") ifFalse:[ |
1087 |
(aPath includes:Character space) ifTrue:[ |
|
1088 |
^ '"',aPath,'"' |
|
1089 |
]. |
|
16999 | 1090 |
]. |
1091 |
^ aPath |
|
1092 |
||
1093 |
||
1094 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1095 |
Filename possiblyQuotedPathname:'/tmp/bla' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1096 |
Filename possiblyQuotedPathname:'/tmp directory/bla' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1097 |
Filename possiblyQuotedPathname:'/tmp directory/bla file' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1098 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1099 |
! |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1100 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1101 |
suggest:aFilenameString |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1102 |
"return a fileNamestring based on the argument, |
3077 | 1103 |
which is legal on the current platform." |
1104 |
||
1105 |
^ self canonicalize:aFilenameString |
|
1106 |
||
1107 |
"Created: / 1.11.1997 / 12:42:39 / cg" |
|
2922 | 1108 |
! ! |
1109 |
||
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1110 |
!Filename class methodsFor:'queries'! |
2 | 1111 |
|
10663
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1112 |
currentDirectoryName |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1113 |
"return a filename for the current directory" |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1114 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1115 |
self isAbstract ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1116 |
^ ConcreteClass currentDirectoryName |
10663
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1117 |
]. |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1118 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1119 |
"/ 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
|
1120 |
|
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 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1124 |
Filename currentDirectoryName |
10663
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 |
"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
|
1128 |
"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
|
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 |
defaultDirectoryName |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1132 |
"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
|
1133 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1134 |
^ self defaultDirectory name |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1135 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1136 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1137 |
Filename defaultDirectoryName |
10663
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1138 |
" |
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 |
|
2963 | 1141 |
directorySuffix |
1142 |
"Return the OS dependent directory suffix string, or nil if there is none. |
|
1143 |
The default is nil here, redefined for VMS" |
|
1144 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1145 |
self isAbstract ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1146 |
^ ConcreteClass directorySuffix |
2963 | 1147 |
]. |
1148 |
||
1149 |
^ nil |
|
1150 |
! |
|
1151 |
||
1523 | 1152 |
errorReporter |
1153 |
"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
|
1154 |
|
1523 | 1155 |
^ FileStream |
1156 |
||
1157 |
"Created: 2.7.1996 / 12:30:25 / stefan" |
|
1158 |
! |
|
1159 |
||
440 | 1160 |
filenameCompletionFor:aString directory:inDirectory directoriesOnly:directoriesOnly filesOnly:filesOnly ifMultiple:aBlock |
1161 |
"perform filename completion on aString in some directory; |
|
1162 |
return the longest matching filename prefix as a string. |
|
1318 | 1163 |
The boolean directoriesOnly and filesOnly control respectively, |
1164 |
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
|
1165 |
If multiple files match, the exception block aBlock is evaluated with a |
1318 | 1166 |
filename representing the directory (where the match was done) as argument. |
440 | 1167 |
(this may be different from the inDirectory argument, if aString is absolute |
1168 |
or starts with ../)" |
|
1169 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1170 |
self isAbstract ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1171 |
^ ConcreteClass |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1172 |
filenameCompletionFor:aString |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1173 |
directory:inDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1174 |
directoriesOnly:directoriesOnly |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1175 |
filesOnly:filesOnly |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1176 |
ifMultiple:aBlock |
2906 | 1177 |
]. |
6839
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1178 |
^ self filenameCompletionFor:aString directory:inDirectory directoriesOnly:directoriesOnly filesOnly:filesOnly ifMultiple:aBlock forMultipleDo:nil |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1179 |
! |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1180 |
|
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1181 |
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
|
1182 |
"perform filename completion on aString in some directory; |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1183 |
return the longest matching filename prefix as a string. |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1184 |
The boolean directoriesOnly and filesOnly control respectively, |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1185 |
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
|
1186 |
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
|
1187 |
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
|
1188 |
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
|
1189 |
(list of matched filenames) as arguments. |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1190 |
(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
|
1191 |
or starts with ../)" |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1192 |
|
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1193 |
|s f matchSet nMatch name dir isAbsolute sep| |
2906 | 1194 |
|
5642
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1195 |
aString size == 0 ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1196 |
aBlock value:(self named:'.'). |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1197 |
^ '' |
440 | 1198 |
]. |
1199 |
||
5642
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1200 |
sep := self separator. |
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1201 |
|
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1202 |
"/ 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
|
1203 |
|
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1204 |
f := self named:aString. |
3854
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
1205 |
isAbsolute := f isAbsolute. |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1206 |
matchSet := f filenameCompletionIn:inDirectory. "/ BAD DESIGN: has side effect on f |
440 | 1207 |
dir := f directory. |
1208 |
||
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
1209 |
matchSet := matchSet select:[:aFilename | |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1210 |
|f isDir| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1211 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1212 |
isAbsolute ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1213 |
f := aFilename asFilename |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1214 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1215 |
f := (dir construct:aFilename). |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1216 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1217 |
isDir := f isDirectory. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1218 |
directoriesOnly ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1219 |
isDir |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1220 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1221 |
filesOnly ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1222 |
isDir not |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1223 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1224 |
true |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1225 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1226 |
] |
440 | 1227 |
]. |
1228 |
||
6803 | 1229 |
f := f asCanonicalizedFilename. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1230 |
(nMatch := matchSet size) ~~ 1 ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1231 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1232 |
more than one possible completion - |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1233 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1234 |
aMultipleBlock notNil ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1235 |
aMultipleBlock value:f value:matchSet. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1236 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1237 |
aBlock value:f |
440 | 1238 |
]. |
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
1239 |
|
440 | 1240 |
" |
1241 |
even with more than one possible completion, |
|
1242 |
f's name is now the common prefix |
|
1243 |
" |
|
1244 |
name := f asString. |
|
4323
8b3752e1b060
add trailing filename separator if match is a directory
Claus Gittinger <cg@exept.de>
parents:
4246
diff
changeset
|
1245 |
|
8b3752e1b060
add trailing filename separator if match is a directory
Claus Gittinger <cg@exept.de>
parents:
4246
diff
changeset
|
1246 |
nMatch <= 1 ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1247 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1248 |
exactly one possible completion - |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1249 |
" |
3752 | 1250 |
"/ f := dir construct:matchSet first. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1251 |
false "directoriesOnly" ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1252 |
(f exists and:[f isDirectory]) ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1253 |
(name endsWith:sep) ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1254 |
name := name , sep asString |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1255 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1256 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1257 |
] |
440 | 1258 |
]. |
1259 |
||
5642
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1260 |
s := name. |
440 | 1261 |
|
1262 |
"/ special: if there was no change, and the string represented |
|
1263 |
"/ 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
|
1264 |
((nMatch == 1) or:[s = aString]) ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1265 |
(s endsWith:sep) ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1266 |
(self named:s) isDirectory ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1267 |
^ s , sep asString |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1268 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1269 |
]. |
440 | 1270 |
]. |
1271 |
||
1272 |
^ s |
|
1318 | 1273 |
|
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
1274 |
"Modified: / 30.4.1999 / 09:40:13 / cg" |
615 | 1275 |
! |
1276 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1277 |
filesMatching:aPattern |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1278 |
"return a collection of strings, representing the names |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1279 |
of files matching aPattern. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1280 |
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
|
1281 |
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
|
1282 |
The returned strings are the expanded names, in the same form |
2550 | 1283 |
as given in pattern. |
1284 |
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
|
1285 |
|
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1286 |
|basePattern dir d files| |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1287 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1288 |
self isAbstract ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1289 |
^ ConcreteClass filesMatching:aPattern |
2906 | 1290 |
]. |
1291 |
||
1292 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
|
1293 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1294 |
dir := aPattern asFilename directoryName. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1295 |
basePattern := aPattern asFilename baseName. |
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1296 |
d := dir asFilename. |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1297 |
files := dir asFilename filesMatchingWithoutDotDirs:basePattern. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1298 |
dir = '.' ifTrue:[^ files]. |
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1299 |
^ files collect:[:base | d constructString:base]. |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1300 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1301 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1302 |
Filename filesMatching:'*' |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1303 |
Filename filesMatching:'/*' |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1304 |
Filename filesMatching:'/usr/local/*' |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1305 |
" |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1306 |
|
2906 | 1307 |
"Modified: 8.9.1997 / 00:32:31 / cg" |
615 | 1308 |
! |
1309 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1310 |
isAbstract |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1311 |
"return true, if this is not a concrete class" |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1312 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1313 |
^ self == Filename |
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1314 |
! |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1315 |
|
2903 | 1316 |
isBadCharacter:aCharacter |
1317 |
"return true, if aCharacter is unallowed in a filename." |
|
1318 |
||
22127 | 1319 |
self isAbstract ifTrue:[ |
1320 |
^ ConcreteClass isBadCharacter:aCharacter |
|
2906 | 1321 |
]. |
1322 |
||
8095
bfbd1309a4a6
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
8036
diff
changeset
|
1323 |
^ aCharacter isControlCharacter |
22127 | 1324 |
|
1325 |
"Modified (format): / 27-07-2017 / 14:25:01 / stefan" |
|
2903 | 1326 |
! |
1327 |
||
1328 |
isCaseSensitive |
|
1329 |
"return true, if filenames are case sensitive. |
|
19821 | 1330 |
We ask the OS about this, to be independent here. |
1331 |
This is not really correct, as the sensitivity may depend on |
|
1332 |
the paricular mounted file system (NFS, for example). |
|
1333 |
So we need a query on the instance side" |
|
2903 | 1334 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1335 |
self isAbstract ifTrue:[ |
19821 | 1336 |
^ ConcreteClass isCaseSensitive |
2906 | 1337 |
]. |
1338 |
||
2903 | 1339 |
^ OperatingSystem caseSensitiveFilenames |
2906 | 1340 |
|
1341 |
"Modified: 8.9.1997 / 00:33:32 / cg" |
|
2903 | 1342 |
! |
1343 |
||
615 | 1344 |
localNameStringFrom:aString |
1345 |
"ST-80 compatibility. |
|
1346 |
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
|
1347 |
GUESS: |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1348 |
does it strip off any volume characters and make a path relative ?" |
2922 | 1349 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1350 |
self isAbstract ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1351 |
^ ConcreteClass localNameStringFrom:aString |
2906 | 1352 |
]. |
1353 |
||
15227 | 1354 |
^ aString withoutPrefix:self separatorString |
615 | 1355 |
|
1356 |
"Modified: 7.9.1995 / 10:44:56 / claus" |
|
2906 | 1357 |
"Modified: 8.9.1997 / 00:33:51 / cg" |
615 | 1358 |
! |
1359 |
||
2908 | 1360 |
maxComponentLength |
1361 |
"return the maximum number of characters a filename component may |
|
1362 |
be in size. This depends on the OperatingSystem." |
|
1363 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1364 |
self isAbstract ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1365 |
^ ConcreteClass maxComponentLength |
2908 | 1366 |
]. |
1367 |
^ OperatingSystem maxFileNameLength |
|
1368 |
! |
|
1369 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1370 |
maxLength |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1371 |
"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
|
1372 |
This depends on the OperatingSystem." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1373 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1374 |
self isAbstract ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1375 |
^ ConcreteClass maxLength |
2908 | 1376 |
]. |
1377 |
^ OperatingSystem maxPathLength |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1378 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1379 |
"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
|
1380 |
"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
|
1381 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1382 |
|
3171 | 1383 |
nullFilename |
1384 |
"Return the OS dependent filename for /dev/null, or nil if there is none. |
|
1385 |
The default is nil here" |
|
1386 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1387 |
self isAbstract ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1388 |
^ ConcreteClass nullFilename |
3171 | 1389 |
]. |
1390 |
||
8754 | 1391 |
^ OperatingSystem getNullDevice |
3171 | 1392 |
|
1393 |
"Created: / 12.1.1998 / 12:15:30 / stefan" |
|
1394 |
! |
|
1395 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1396 |
parentDirectoryName |
615 | 1397 |
"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
|
1398 |
This is '..' for unix and dos-like systems. |
615 | 1399 |
(there may be more in the future." |
1400 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1401 |
self isAbstract ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1402 |
^ ConcreteClass parentDirectoryName |
2906 | 1403 |
]. |
1404 |
||
1405 |
^ OperatingSystem parentDirectoryName |
|
1406 |
||
1407 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1408 |
Filename parentDirectoryName |
2906 | 1409 |
" |
1410 |
||
1411 |
"Modified: 8.9.1997 / 00:34:39 / cg" |
|
615 | 1412 |
! |
1413 |
||
1414 |
separator |
|
1415 |
"return the file/directory separator. |
|
15246 | 1416 |
This is to be redefined in concrete classes." |
1417 |
||
1418 |
^ ConcreteClass separator |
|
8243 | 1419 |
|
1420 |
" |
|
8754 | 1421 |
Filename separator |
1422 |
PCFilename separator |
|
8243 | 1423 |
" |
2906 | 1424 |
|
1425 |
"Modified: 8.9.1997 / 00:20:28 / cg" |
|
615 | 1426 |
! |
1427 |
||
8243 | 1428 |
separatorString |
1429 |
"return the file/directory separator as a string." |
|
1430 |
||
1431 |
^ self separator asString |
|
1432 |
||
1433 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1434 |
Filename separatorString |
8243 | 1435 |
" |
1436 |
! |
|
1437 |
||
615 | 1438 |
suffixSeparator |
1439 |
"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
|
1440 |
Usually, this is $. for unix-like and msdos systems |
1318 | 1441 |
(there is currently no known system, where this differs)" |
615 | 1442 |
|
1443 |
^ $. |
|
1444 |
||
1445 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1446 |
Filename suffixSeparator |
615 | 1447 |
" |
1448 |
||
1449 |
"Modified: 7.9.1995 / 11:10:43 / claus" |
|
1318 | 1450 |
"Modified: 30.4.1996 / 12:14:25 / cg" |
615 | 1451 |
! |
1452 |
||
2906 | 1453 |
tempFileNameTemplate |
1454 |
"return a template for temporary files. |
|
1455 |
This is expanded with the current processID and a sequenceNumber |
|
1456 |
to generate a unique filename." |
|
1457 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1458 |
self isAbstract ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1459 |
^ ConcreteClass tempFileNameTemplate |
2906 | 1460 |
]. |
1461 |
||
1462 |
^ 'stxtmp_%1_%2' |
|
1463 |
||
1464 |
"Created: 8.9.1997 / 00:01:46 / cg" |
|
1465 |
"Modified: 8.9.1997 / 00:35:02 / cg" |
|
1466 |
! |
|
1467 |
||
615 | 1468 |
volumes |
1469 |
"ST-80 compatibility. |
|
2896 | 1470 |
GUESS: does it return the available drives on MSDOS systems ? |
1471 |
Q: what does this do on Unix systems ? (used in FileNavigator-goody)." |
|
1472 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1473 |
self isAbstract ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1474 |
^ ConcreteClass volumes |
2906 | 1475 |
]. |
1476 |
||
2896 | 1477 |
^ OperatingSystem getDriveList |
615 | 1478 |
|
8679 | 1479 |
" |
1480 |
Filename volumes |
|
1481 |
" |
|
615 | 1482 |
! ! |
1483 |
||
6383 | 1484 |
!Filename class methodsFor:'utilities'! |
1485 |
||
16389 | 1486 |
canonicalize:aPathString |
1487 |
"convert the argument, aPathString to a good format. |
|
1488 |
This should eliminate useless directory components (i.e. '././') |
|
1489 |
and useless tree walks (i.e. '../foo/..')." |
|
1490 |
||
1491 |
^ self nameFromComponents:(self canonicalizedNameComponents:aPathString) |
|
1492 |
||
1493 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1494 |
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
|
1495 |
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
|
1496 |
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
|
1497 |
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
|
1498 |
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
|
1499 |
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
|
1500 |
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
|
1501 |
Filename canonicalize:'cg/../../..' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1502 |
Filename canonicalize:'./' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1503 |
Filename canonicalize:'/home/.' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1504 |
Filename canonicalize:'/home/../..' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1505 |
Filename canonicalize:'//foo' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1506 |
Filename canonicalize:'///foo' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1507 |
Filename canonicalize:'//foo//bar' |
16389 | 1508 |
" |
1509 |
! |
|
1510 |
||
1511 |
canonicalizedNameComponents:aPathString |
|
1512 |
"convert the argument, aPathString to a good format. |
|
1513 |
This should eliminate useless directory components (i.e. '././') |
|
1514 |
and useless tree walks (i.e. '../foo/..'). |
|
1515 |
||
1516 |
Answer a sequenceable collection of name components." |
|
1517 |
||
1518 |
|comps newComps rootName dotDot dot| |
|
1519 |
||
1520 |
dotDot := self parentDirectoryName. |
|
1521 |
dot := self currentDirectoryName. |
|
1522 |
rootName := self separatorString. |
|
1523 |
||
1524 |
comps := self components:aPathString. |
|
1525 |
newComps := OrderedCollection new:comps size. |
|
1526 |
comps do:[:eachComponent | |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1527 |
eachComponent ~= dot ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1528 |
eachComponent = dotDot ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1529 |
(newComps isEmpty |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1530 |
or:[(newComps size == 1 and:[newComps first startsWith:rootName]) |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1531 |
or:[newComps last = dotDot]]) ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1532 |
newComps add:eachComponent |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1533 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1534 |
newComps removeLast |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1535 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1536 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1537 |
newComps add:eachComponent |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1538 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1539 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1540 |
]. |
16389 | 1541 |
"/ add current Directory if empty |
1542 |
newComps isEmpty ifTrue:[ |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1543 |
newComps add:dot. |
16389 | 1544 |
]. |
1545 |
^ newComps |
|
1546 |
||
1547 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1548 |
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
|
1549 |
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
|
1550 |
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
|
1551 |
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
|
1552 |
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
|
1553 |
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
|
1554 |
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
|
1555 |
Filename canonicalizedNameComponents:'cg/../../..' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1556 |
Filename canonicalizedNameComponents:'/' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1557 |
Filename canonicalizedNameComponents:'./' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1558 |
Filename canonicalizedNameComponents:'/.' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1559 |
Filename canonicalizedNameComponents:'/home/.' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1560 |
Filename canonicalizedNameComponents:'/home' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1561 |
Filename canonicalizedNameComponents:'/home/../..' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1562 |
Filename canonicalizedNameComponents:'//foo' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1563 |
Filename canonicalizedNameComponents:'///foo' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1564 |
Filename canonicalizedNameComponents:'//foo//bar' |
16389 | 1565 |
" |
1566 |
! |
|
1567 |
||
1568 |
components:aString |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1569 |
"separate the pathName given by aString into |
16578 | 1570 |
a collection containing the directory components and the file's name as |
16389 | 1571 |
the final component. |
1572 |
If the argument names an absolute path, the first component will be the |
|
1573 |
name of the root directory (i.e. '/')." |
|
1574 |
||
1575 |
|sep f vol rest components| |
|
1576 |
||
1577 |
self isAbstract ifTrue:[ |
|
19821 | 1578 |
^ ConcreteClass components:aString |
16389 | 1579 |
]. |
1580 |
||
1581 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
|
1582 |
"/ However, MSDOS drive-letters and network drives are |
|
1583 |
"/ not correctly handled here. |
|
1584 |
||
1585 |
sep := self separator. |
|
1586 |
f := aString asFilename. |
|
1587 |
vol := f volume. |
|
1588 |
vol size ~~ 0 ifTrue:[ |
|
19821 | 1589 |
rest := f localPathName. |
16389 | 1590 |
] ifFalse:[ |
19821 | 1591 |
rest := aString |
16389 | 1592 |
]. |
1593 |
||
1594 |
components := rest asCollectionOfSubstringsSeparatedBy:sep. |
|
1595 |
(rest startsWith:sep) ifTrue:[ |
|
19821 | 1596 |
"first was a separator - root directory - restore" |
1597 |
(rest size > 1 and:[rest second = sep and:[vol isEmptyOrNil]]) ifTrue:[ |
|
1598 |
"keep \\ for windows network paths" |
|
1599 |
components at:1 put:(String with:sep with:sep). |
|
1600 |
] ifFalse:[ |
|
1601 |
components at:1 put:sep asString. |
|
1602 |
]. |
|
16389 | 1603 |
]. |
1604 |
||
1605 |
"/ prepend volume to first component (the root directory) |
|
1606 |
vol size ~~ 0 ifTrue:[ |
|
20694 | 1607 |
vol last = $: ifTrue:[ |
1608 |
vol := vol, (components at:1). |
|
1609 |
]. |
|
1610 |
components at:1 put:vol. |
|
1611 |
]. |
|
1612 |
components := components select:[:each| each notEmpty]. |
|
1613 |
||
16389 | 1614 |
^ components |
1615 |
||
1616 |
" |
|
19821 | 1617 |
Unix: |
1618 |
UnixFilename components:'/foo/bar/baz' |
|
1619 |
UnixFilename components:'/' |
|
1620 |
UnixFilename components:'//' |
|
1621 |
UnixFilename components:'foo/bar/baz' |
|
1622 |
UnixFilename components:'foo/bar' |
|
1623 |
UnixFilename components:'foo' |
|
1624 |
UnixFilename components:'/foo' |
|
1625 |
UnixFilename components:'//foo' |
|
1626 |
UnixFilename components:'' |
|
1627 |
||
1628 |
Windows: |
|
1629 |
PCFilename components:'\' |
|
1630 |
PCFilename components:'\foo' |
|
1631 |
PCFilename components:'\foo\' |
|
1632 |
PCFilename components:'\foo\bar' |
|
1633 |
PCFilename components:'\foo\bar\' |
|
1634 |
PCFilename components:'c:' |
|
1635 |
PCFilename components:'c:\' |
|
1636 |
PCFilename components:'c:\foo' |
|
1637 |
PCFilename components:'c:\foo\' |
|
1638 |
PCFilename components:'c:\foo\bar' |
|
1639 |
PCFilename components:'c:\foo\bar\' |
|
1640 |
PCFilename components:'\\idefix' |
|
1641 |
PCFilename components:'\\idefix\home' |
|
1642 |
PCFilename components:'\\idefix\home\bar' |
|
16389 | 1643 |
" |
1644 |
||
1645 |
"Modified: / 24.9.1998 / 19:10:52 / cg" |
|
1646 |
! |
|
1647 |
||
19821 | 1648 |
filesMatchingGLOB:pattern |
1649 |
"does a GLOB filename expansion. |
|
1650 |
Generates and returns a possibly empty list of files which match |
|
1651 |
the given glob pattern" |
|
1652 |
||
1653 |
^ OrderedCollection withCollectedContents:[:coll | |
|
1654 |
pattern asFilename filesMatchingGLOBDo:[:each | coll add:each] |
|
1655 |
] |
|
1656 |
||
1657 |
" |
|
1658 |
Filename filesMatchingGLOB:'./A*' |
|
1659 |
Filename filesMatchingGLOB:'/etc/A*' |
|
1660 |
Filename filesMatchingGLOB:'/*/A*' |
|
1661 |
'.' asFilename filesMatchingGLOB:'A*' |
|
1662 |
" |
|
1663 |
! |
|
1664 |
||
6802 | 1665 |
nameFromComponents:aCollectionOfDirectoryNames |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1666 |
"return a filenameString from components given in aCollectionOfDirectoryNames. |
6802 | 1667 |
If the first component is the name of the root directory (i.e. '/'), |
1668 |
an absolute path-string is returned." |
|
1669 |
||
1670 |
|sep s| |
|
1671 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1672 |
self isAbstract ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1673 |
^ ConcreteClass nameFromComponents:aCollectionOfDirectoryNames |
6802 | 1674 |
]. |
1675 |
||
1676 |
"/ fallBack - works on Unix & MSDOS |
|
1677 |
||
8243 | 1678 |
sep := self separatorString. |
6802 | 1679 |
s := ''. |
1680 |
aCollectionOfDirectoryNames keysAndValuesDo:[:index :component | |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1681 |
index == 1 ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1682 |
s := component. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1683 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1684 |
(index == 2 and:[ (s endsWith:sep) ]) ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1685 |
s := s , component |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1686 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1687 |
s := s , sep , component |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1688 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1689 |
]. |
6802 | 1690 |
]. |
1691 |
^ s |
|
1692 |
||
1693 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1694 |
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
|
1695 |
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
|
1696 |
Filename nameFromComponents:#('/') |
7074 | 1697 |
|
1698 |
|comps| |
|
1699 |
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
|
1700 |
Filename nameFromComponents:comps |
7074 | 1701 |
|
1702 |
|comps| |
|
1703 |
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
|
1704 |
Filename nameFromComponents:comps |
7074 | 1705 |
|
1706 |
|comps| |
|
1707 |
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
|
1708 |
Filename nameFromComponents:comps |
7074 | 1709 |
|
1710 |
|comps| |
|
1711 |
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
|
1712 |
Filename nameFromComponents:comps |
7074 | 1713 |
|
1714 |
|comps| |
|
1715 |
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
|
1716 |
Filename nameFromComponents:comps |
7074 | 1717 |
|
1718 |
|comps| |
|
1719 |
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
|
1720 |
Filename nameFromComponents:comps |
7074 | 1721 |
|
1722 |
|comps| |
|
1723 |
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
|
1724 |
Filename nameFromComponents:comps |
6802 | 1725 |
" |
1726 |
||
1727 |
"Modified: 8.9.1997 / 00:23:16 / cg" |
|
1728 |
! |
|
1729 |
||
6383 | 1730 |
readingFile:aPathName do:aBlock |
20158 | 1731 |
"Create a read stream on a file, evaluate aBlock, passing that stream, |
1732 |
and return the block's value. |
|
6383 | 1733 |
Ensures that the stream is closed." |
1734 |
||
6529 | 1735 |
^ aPathName asFilename readingFileDo:aBlock. |
1736 |
||
1737 |
" |
|
1738 |
read the first line from some file: |
|
1739 |
||
1740 |
|rslt| |
|
1741 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1742 |
rslt := |
20158 | 1743 |
Filename |
1744 |
readingFile:'/etc/passwd' |
|
1745 |
do:[:s | |
|
1746 |
s nextLine |
|
1747 |
]. |
|
6529 | 1748 |
Transcript showCR:rslt. |
1749 |
" |
|
1750 |
||
1751 |
" |
|
1752 |
find all used shells in /etc/passwd and count their usage: |
|
1753 |
||
6383 | 1754 |
|rslt| |
1755 |
||
6529 | 1756 |
rslt := |
20158 | 1757 |
Filename |
1758 |
readingFile:'/etc/passwd' |
|
1759 |
do: |
|
1760 |
[:s | |
|
1761 |
|shells| |
|
1762 |
||
1763 |
shells := Bag new. |
|
1764 |
s linesDo: |
|
1765 |
[:line | |
|
1766 |
|parts| |
|
1767 |
||
1768 |
parts := line asCollectionOfSubstringsSeparatedBy:$:. |
|
1769 |
shells add:(parts seventh). |
|
1770 |
]. |
|
1771 |
shells contents |
|
1772 |
]. |
|
6529 | 1773 |
Transcript showCR:rslt. |
1774 |
" |
|
6383 | 1775 |
! ! |
1776 |
||
7261 | 1777 |
!Filename methodsFor:'Compatibility-VW5.4'! |
6139 | 1778 |
|
1779 |
asLogicalFileSpecification |
|
1780 |
^ self |
|
1781 |
||
1782 |
"Created: / 30.10.2001 / 17:31:10 / cg" |
|
6447 | 1783 |
! |
1784 |
||
10583 | 1785 |
canBeWritten |
1786 |
"same as isWritable - for ST-80 compatibility" |
|
1787 |
||
1788 |
^ self isWritable |
|
1789 |
||
1790 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1791 |
'/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
|
1792 |
'/tmp' asFilename canBeWritten |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1793 |
'Makefile' asFilename canBeWritten |
10583 | 1794 |
" |
1795 |
! |
|
1796 |
||
7596 | 1797 |
definitelyExists |
1798 |
"for now - a kludge" |
|
1799 |
||
1800 |
^ self exists |
|
1801 |
! |
|
1802 |
||
22943 | 1803 |
delete |
1804 |
"remove the file - same as remove, for ST-80 compatibility" |
|
1805 |
||
1806 |
self remove |
|
1807 |
! |
|
1808 |
||
6447 | 1809 |
extension |
6454 | 1810 |
"return the receiver's extension; |
1811 |
that is the characters from and including |
|
1812 |
the last period or nil, if there is none." |
|
1813 |
||
1814 |
|string idx| |
|
1815 |
||
1816 |
string := self asString. |
|
1817 |
idx := string lastIndexOf:$.. |
|
1818 |
idx > 1 ifTrue:[ |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1819 |
^ string copyFrom:idx |
6454 | 1820 |
]. |
1821 |
^ nil |
|
1822 |
||
1823 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1824 |
'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
|
1825 |
'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
|
1826 |
'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
|
1827 |
'foo.' asFilename extension |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1828 |
'foo' asFilename extension |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1829 |
'.login' asFilename extension |
6454 | 1830 |
" |
6139 | 1831 |
! ! |
1832 |
||
615 | 1833 |
!Filename methodsFor:'comparing'! |
1834 |
||
16255 | 1835 |
< aFilename |
1836 |
"compare file names - used for sorting" |
|
1837 |
||
1838 |
^ self asString < aFilename asString |
|
1839 |
! |
|
1840 |
||
615 | 1841 |
= aFilename |
1842 |
"return true, if the argument represents the same filename" |
|
1843 |
||
1844 |
|str| |
|
1845 |
||
1846 |
self species == aFilename species ifTrue:[ |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1847 |
str := aFilename asString. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1848 |
self species isCaseSensitive ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1849 |
^ nameString = str |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1850 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1851 |
^ nameString sameAs:str |
615 | 1852 |
]. |
1853 |
^ false |
|
1854 |
! |
|
1855 |
||
5877 | 1856 |
contentsIsPrefixOf:aFilename |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1857 |
"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
|
1858 |
is the same as or a prefix of the contents of the file represented by the argument, aFilename. |
16578 | 1859 |
This compares the files' actual contents; not the filenames." |
3868 | 1860 |
|
8771 | 1861 |
|f2 s1 s2 bufferSize buffer1 buffer2 n| |
1862 |
||
1863 |
bufferSize := 8192 * 4. |
|
4979 | 1864 |
|
1865 |
f2 := aFilename asFilename. |
|
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1866 |
self fileSize > f2 fileSize ifTrue:[^ false]. |
3868 | 1867 |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1868 |
[ |
22401 | 1869 |
s1 := self readStream. |
1870 |
s2 := f2 readStream. |
|
1871 |
s1 binary. |
|
1872 |
s2 binary. |
|
1873 |
||
1874 |
buffer1 := ByteArray new:bufferSize. |
|
1875 |
buffer2 := ByteArray new:bufferSize. |
|
1876 |
||
1877 |
[s1 atEnd] whileFalse:[ |
|
1878 |
n := s1 nextBytes:bufferSize into:buffer1 startingAt:1. |
|
1879 |
n == 0 ifTrue:[ |
|
1880 |
"/ receiver at end. |
|
1881 |
^ true |
|
1882 |
]. |
|
1883 |
(s2 nextBytes:n into:buffer2 startingAt:1) ~~ n ifTrue:[ |
|
1884 |
"/ aFilename shorter (cannot happen as mySize is <= argument file's size) |
|
1885 |
^ false |
|
1886 |
]. |
|
1887 |
buffer1 ~= buffer2 ifTrue:[ |
|
1888 |
^ false |
|
1889 |
] |
|
1890 |
]. |
|
1891 |
"/ 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
|
1892 |
] ensure:[ |
22401 | 1893 |
s1 notNil ifTrue:[s1 close]. |
1894 |
s2 notNil ifTrue:[s2 close]. |
|
3868 | 1895 |
]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1896 |
^ true |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1897 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1898 |
" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1899 |
|s| |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1900 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1901 |
s := 'testFile1' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1902 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1903 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1904 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1905 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1906 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1907 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1908 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1909 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1910 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1911 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1912 |
|
5877 | 1913 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifFalse:[self halt]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1914 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1915 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1916 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1917 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1918 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1919 |
s nextPutAll:'44444'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1920 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1921 |
|
5877 | 1922 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifFalse:[self halt]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1923 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1924 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1925 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1926 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1927 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1928 |
|
5877 | 1929 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifTrue:[self halt]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1930 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1931 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1932 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1933 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1934 |
s nextPutAll:'33334'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1935 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1936 |
|
5877 | 1937 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifTrue:[self halt]. |
1938 |
||
1939 |
" |
|
1940 |
! |
|
1941 |
||
1942 |
contentsStartsWithContentsOf:aFilename |
|
1943 |
"return true if the contents of the file represented by aFilename |
|
1944 |
is the same as or a prefix of the contents of the file represented by the receiver. |
|
16578 | 1945 |
This compares the files' actual contents; not the filenames." |
5877 | 1946 |
|
1947 |
^ aFilename asFilename contentsIsPrefixOf:self |
|
1948 |
||
1949 |
" |
|
1950 |
|s| |
|
1951 |
||
1952 |
s := 'testFile1' asFilename writeStream. |
|
1953 |
s nextPutAll:'11111'. |
|
1954 |
s nextPutAll:'22222'. |
|
1955 |
s nextPutAll:'33333'. |
|
1956 |
s close. |
|
1957 |
||
1958 |
s := 'testFile2' asFilename writeStream. |
|
1959 |
s nextPutAll:'11111'. |
|
1960 |
s nextPutAll:'22222'. |
|
1961 |
s nextPutAll:'33333'. |
|
1962 |
s close. |
|
1963 |
||
1964 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifFalse:[self halt]. |
|
1965 |
||
1966 |
s := 'testFile2' asFilename writeStream. |
|
1967 |
s nextPutAll:'11111'. |
|
1968 |
s nextPutAll:'22222'. |
|
1969 |
s nextPutAll:'33333'. |
|
1970 |
s nextPutAll:'44444'. |
|
1971 |
s close. |
|
1972 |
||
1973 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifFalse:[self halt]. |
|
1974 |
||
1975 |
s := 'testFile2' asFilename writeStream. |
|
1976 |
s nextPutAll:'11111'. |
|
1977 |
s nextPutAll:'22222'. |
|
1978 |
s close. |
|
1979 |
||
1980 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifTrue:[self halt]. |
|
1981 |
||
1982 |
s := 'testFile2' asFilename writeStream. |
|
1983 |
s nextPutAll:'11111'. |
|
1984 |
s nextPutAll:'22222'. |
|
1985 |
s nextPutAll:'33334'. |
|
1986 |
s close. |
|
1987 |
||
1988 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifTrue:[self halt]. |
|
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1989 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1990 |
" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1991 |
! |
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 |
hash |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1994 |
"return an integer useful as a hash-key" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1995 |
|
15811 | 1996 |
self species isCaseSensitive ifFalse:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1997 |
"/ asLowercase is slightly better: |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1998 |
"/ it never converts single-byte strings to double one's, |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1999 |
"/ whereas asUppercase might (for umlaut-y) |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2000 |
^ nameString asUppercase hash |
11424
c169cc34afe9
fixed hash for case-insensitive files
Claus Gittinger <cg@exept.de>
parents:
11406
diff
changeset
|
2001 |
]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2002 |
^ nameString hash |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2003 |
! |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2004 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2005 |
sameContentsAs:aFilename |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2006 |
"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
|
2007 |
same contents as the file represented by the argument, aFilename. |
16578 | 2008 |
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
|
2009 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2010 |
|f2| |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2011 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2012 |
f2 := aFilename asFilename. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2013 |
f2 fileSize = self fileSize ifFalse:[^ false]. |
5877 | 2014 |
^ self contentsIsPrefixOf:f2. |
3868 | 2015 |
|
2016 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2017 |
'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
|
2018 |
'Make.proto' asFilename sameContentsAs:'Make.proto' |
3868 | 2019 |
" |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2020 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2021 |
" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2022 |
|s| |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2023 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2024 |
s := 'testFile1' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2025 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2026 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2027 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2028 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2029 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2030 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2031 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2032 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2033 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2034 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2035 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2036 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifFalse:[self halt]. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2037 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2038 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2039 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2040 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2041 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2042 |
s nextPutAll:'44444'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2043 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2044 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2045 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifTrue:[self halt]. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2046 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2047 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2048 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2049 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2050 |
s close. |
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 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifTrue:[self halt]. |
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 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2055 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2056 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2057 |
s nextPutAll:'33334'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2058 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2059 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2060 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifTrue:[self halt]. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2061 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2062 |
" |
615 | 2063 |
! ! |
2064 |
||
2065 |
!Filename methodsFor:'converting'! |
|
2066 |
||
2067 |
asAbsoluteFilename |
|
2068 |
"return the receiver converted to a filename with |
|
2069 |
an absolute pathname." |
|
2070 |
||
15811 | 2071 |
^ self species named:self pathName |
7332 | 2072 |
|
2073 |
" |
|
2074 |
'.' asFilename |
|
2075 |
'.' asFilename asAbsoluteFilename |
|
9173 | 2076 |
'c:' asFilename asAbsoluteFilename |
7332 | 2077 |
" |
615 | 2078 |
! |
2079 |
||
10769 | 2080 |
asAutoDeletedFilename |
13653
6821135a2e1a
comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents:
13424
diff
changeset
|
2081 |
"will automatically delete myself, when no longer referenced" |
6821135a2e1a
comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents:
13424
diff
changeset
|
2082 |
|
11784 | 2083 |
^ AutoDeletedFilename basicNew setName:self name |
13653
6821135a2e1a
comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents:
13424
diff
changeset
|
2084 |
|
6821135a2e1a
comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents:
13424
diff
changeset
|
2085 |
"Modified (comment): / 07-09-2011 / 12:20:59 / cg" |
10769 | 2086 |
! |
2087 |
||
21390 | 2088 |
asBackupFilename |
2089 |
"return the receiver converted to a backup filename." |
|
2090 |
||
2091 |
"/ ^ self species named:(nameString, '~'). |
|
2092 |
"/ ^ self species named:(self directoryName, '/~', self baseName). |
|
2093 |
||
2094 |
^ self addSuffix:'bak' |
|
2095 |
||
2096 |
" |
|
2097 |
'bla' asFilename asBackupFilename |
|
2098 |
'/home/user/directory/bla' asFilename asBackupFilename |
|
2099 |
'directory/bla' asFilename asBackupFilename |
|
2100 |
" |
|
2101 |
||
2102 |
"Created: / 09-02-2017 / 12:57:28 / stefan" |
|
2103 |
! |
|
2104 |
||
6802 | 2105 |
asCanonicalizedFilename |
2106 |
"return the receiver converted to a filename without intermediate ..'s and .'s |
|
2107 |
(similar to an absolute pathname, but symlinks are not resolved)." |
|
2108 |
||
15811 | 2109 |
^ self species named:(self species canonicalize:nameString) |
7074 | 2110 |
|
2111 |
" |
|
2112 |
'c:\test\work' asFilename asCanonicalizedFilename |
|
2113 |
'/test/work' asFilename asCanonicalizedFilename |
|
2114 |
" |
|
6802 | 2115 |
! |
2116 |
||
615 | 2117 |
asFilename |
20413 | 2118 |
"return the receiver converted to a filename; here, that's the receiver itself." |
2119 |
||
2120 |
"That's pretty easy here :-)" |
|
615 | 2121 |
^ self |
1970 | 2122 |
|
2123 |
"Modified: 12.11.1996 / 12:40:03 / cg" |
|
615 | 2124 |
! |
2125 |
||
21390 | 2126 |
asNonBackupFilename |
2127 |
"return the receiver converted to a backup filename." |
|
2128 |
||
2129 |
nameString last == $~ ifTrue:[ |
|
2130 |
^ self class named:(nameString copyButLast:1). |
|
2131 |
]. |
|
2132 |
(self hasSuffix:'bak') ifTrue:[ |
|
2133 |
^ self withoutSuffix |
|
2134 |
]. |
|
2135 |
^ self. |
|
2136 |
||
2137 |
" |
|
2138 |
'bla.bak' asFilename asNonBackupFilename |
|
2139 |
'/home/user/directory/bla.bak' asFilename asNonBackupFilename |
|
2140 |
'directory/bla.bak' asFilename asNonBackupFilename |
|
2141 |
'directory/bla~' asFilename asNonBackupFilename |
|
2142 |
" |
|
2143 |
||
2144 |
"Created: / 09-02-2017 / 14:01:47 / stefan" |
|
2145 |
! |
|
2146 |
||
615 | 2147 |
asString |
2148 |
"return the receiver converted to a string" |
|
2149 |
||
2150 |
^ nameString |
|
2151 |
! |
|
2152 |
||
6256 | 2153 |
asURI |
15001 | 2154 |
"return the receiver converted to a file URI" |
6256 | 2155 |
|
2156 |
^ FileURI fromFilename:self. |
|
2157 |
! |
|
2158 |
||
15001 | 2159 |
asURL |
2160 |
"return an URL-object from myself" |
|
2161 |
||
2162 |
^ URL fromString:self pathName. |
|
2163 |
! |
|
2164 |
||
19665 | 2165 |
asUniqueFilename |
22939 | 2166 |
"If a file by my name already exists, return a new filename with a unique string appended. |
2167 |
Here, a somewhat naive strategy is performed, by trying _1, _2,... |
|
2168 |
until a new name is generated." |
|
19665 | 2169 |
|
2170 |
|fn baseFn nextSeqNr| |
|
2171 |
||
2172 |
fn := baseFn := self. |
|
2173 |
nextSeqNr := 0. |
|
2174 |
[ fn exists ] whileTrue:[ |
|
20453 | 2175 |
|newFn suff| |
19665 | 2176 |
|
2177 |
nextSeqNr := (nextSeqNr ? 0) + 1. |
|
20453 | 2178 |
suff := baseFn suffix. |
2179 |
suff notEmpty ifTrue:[ suff := '.',suff ]. |
|
2180 |
fn := self class named:((baseFn withoutSuffix name,'_',nextSeqNr asString),suff). |
|
19665 | 2181 |
]. |
2182 |
^ fn |
|
2183 |
||
2184 |
" |
|
2185 |
'aaa.txt' asFilename contents:'bla'. |
|
20453 | 2186 |
'aaa.1.2.3.apk.txt' asFilename asUniqueFilename contents:'bla2'. |
19665 | 2187 |
'aaa.txt' asFilename asUniqueFilename contents:'bla3'. |
2188 |
'aaa.txt' asFilename asUniqueFilename contents:'bla4'. |
|
2189 |
#('aaa.txt' 'aaa_1.txt' 'aaa_2.txt' 'aaa_3.txt') do:[:f | f asFilename delete]. |
|
2190 |
" |
|
2191 |
! |
|
2192 |
||
5890 | 2193 |
components |
19440 | 2194 |
"return the receiver's filename components - that is the name of each directory |
5890 | 2195 |
along the pathName (that DOES include the root directory)" |
2196 |
||
15811 | 2197 |
^ self species components:self name |
5890 | 2198 |
|
2199 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2200 |
'.' asFilename asAbsoluteFilename components |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2201 |
'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
|
2202 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2203 |
! |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2204 |
|
23129 | 2205 |
makeLegalBasename |
2206 |
"convert the receiver's name to be a legal basename. |
|
2207 |
This removes/replaces invalid characters and/or compresses |
|
2208 |
the name as required by the OS. |
|
2209 |
It also replaces the directory separator (i.e. '/') by an inderscore. |
|
2210 |
The implementation may change in the future to be more |
|
2211 |
OS specific." |
|
2212 |
||
2213 |
" |
|
2214 |
actually, in Unix spaces are allowed - but it makes life |
|
2215 |
so hard; therefore, replace them by underscores ... |
|
2216 |
" |
|
2217 |
nameString := nameString copy |
|
2218 |
replaceAllForWhich:[:each| |
|
2219 |
each isSeparator |
|
2220 |
or:[self class isBadCharacter:each]] |
|
2221 |
with:$_. |
|
2222 |
" |
|
2223 |
need more - especially on SYS5.3 type systems, |
|
2224 |
we may want to contract the fileName to 14 characters. |
|
2225 |
" |
|
2226 |
^ self |
|
2227 |
||
2228 |
" |
|
2229 |
'hello world' asFilename makeLegalBasename |
|
2230 |
('abc' copyWith:Character return) asFilename makeLegalBasename |
|
2231 |
('a/b/c' copyWith:Character return) asFilename makeLegalBasename |
|
2232 |
" |
|
2233 |
||
2234 |
"Created: / 25-06-2018 / 17:11:41 / Claus Gittinger" |
|
2235 |
! |
|
2236 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2237 |
makeLegalFilename |
19440 | 2238 |
"convert the receiver's name to be a legal filename. |
1970 | 2239 |
This removes/replaces invalid characters and/or compresses |
2240 |
the name as required by the OS. |
|
615 | 2241 |
The implementation may change in the future to be more |
2242 |
OS specific." |
|
2243 |
||
2244 |
" |
|
2245 |
actually, in Unix spaces are allowed - but it makes life |
|
2246 |
so hard; therefore, replace them by underscores ... |
|
2247 |
" |
|
22127 | 2248 |
|separator| |
2249 |
||
2250 |
separator := self separator. |
|
23129 | 2251 |
nameString := nameString copy |
2252 |
replaceAllForWhich:[:each| |
|
2253 |
each == Character space |
|
2254 |
or:[each ~= separator and:[self class isBadCharacter:each]]] |
|
2255 |
with:$_. |
|
615 | 2256 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2257 |
need more - especially on SYS5.3 type systems, |
615 | 2258 |
we may want to contract the fileName to 14 characters. |
2259 |
" |
|
2260 |
^ self |
|
2261 |
||
2262 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2263 |
'hello world' asFilename makeLegalFilename |
22127 | 2264 |
('abc' copyWith:Character return) asFilename makeLegalFilename |
2265 |
" |
|
2266 |
||
2267 |
"Modified: / 20-07-1998 / 13:16:51 / cg" |
|
2268 |
"Modified (comment): / 27-07-2017 / 15:53:53 / stefan" |
|
23129 | 2269 |
"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
|
2270 |
! |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2271 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2272 |
withEncoding:encodingSymbol |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2273 |
"dummy for now - for ST80 compatibility" |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2274 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2275 |
^ self |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2276 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2277 |
"Created: 20.6.1997 / 17:01:28 / cg" |
2 | 2278 |
! ! |
2279 |
||
18272 | 2280 |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2281 |
!Filename methodsFor:'enumerating-contents'! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2282 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2283 |
allDirectoriesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2284 |
"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
|
2285 |
The block is invoked with a filename-arguments. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2286 |
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
|
2287 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2288 |
This excludes entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2289 |
NoOp for non-existing directories; however, this behavior |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2290 |
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
|
2291 |
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
|
2292 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2293 |
self recursiveDirectoryContentsDo:[:eachFileOrDirectoryName | |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2294 |
|eachFileOrDirectory| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2295 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2296 |
eachFileOrDirectory := self construct:eachFileOrDirectoryName. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2297 |
eachFileOrDirectory isDirectory ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2298 |
aBlock value:eachFileOrDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2299 |
] |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2300 |
]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2301 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2302 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2303 |
'.' asFilename allDirectoriesDo:[:fn | Transcript showCR:fn name]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2304 |
'.' asFilename directoriesDo:[:fn | Transcript showCR:fn name]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2305 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2306 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2307 |
|
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2308 |
allParentDirectoriesDo:aBlock |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2309 |
"evaluate aBlock for all (recursive) directories along the parent directory path. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2310 |
The block is invoked with a filename-arguments." |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2311 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2312 |
|parent here| |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2313 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2314 |
here := self. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2315 |
parent := here directory. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2316 |
[here notNil and:[parent ~= here]] whileTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2317 |
aBlock value:parent. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2318 |
here := parent. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2319 |
parent := here directory. |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2320 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2321 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2322 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2323 |
'.' asFilename allParentDirectoriesDo:[:fn | Transcript showCR:fn pathName]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2324 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2325 |
! |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2326 |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2327 |
directoriesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2328 |
"evaluate aBlock for directories contained in the directory represented by the receiver. |
23159 | 2329 |
The block is invoked with a filename-argument. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2330 |
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
|
2331 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2332 |
This excludes entries for '.' or '..'. |
18686 | 2333 |
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
|
2334 |
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
|
2335 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2336 |
self directoryContentsAsFilenamesDo:[:eachFileOrDirectory | |
23159 | 2337 |
eachFileOrDirectory isDirectory ifTrue:[ |
2338 |
aBlock value:eachFileOrDirectory |
|
2339 |
] |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2340 |
]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2341 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2342 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2343 |
'.' asFilename directoriesDo:[:fn | Transcript showCR:fn baseName]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2344 |
" |
23159 | 2345 |
|
2346 |
"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
|
2347 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2348 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2349 |
directoryContentsAsFilenamesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2350 |
"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
|
2351 |
The block is invoked with a filename-argument. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2352 |
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
|
2353 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2354 |
This excludes entries for '.' or '..'. |
17310 | 2355 |
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
|
2356 |
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
|
2357 |
Notice: this enumerates fileName objects; see also |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2358 |
#directoryContentsDo:, which enumerates strings." |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2359 |
|
6776
11df52e55905
better loop (dont preread all items in ..asFilenamesDo:)
penk
parents:
6773
diff
changeset
|
2360 |
self directoryContentsDo:[:entry | |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2361 |
aBlock value:(self construct:entry). |
6776
11df52e55905
better loop (dont preread all items in ..asFilenamesDo:)
penk
parents:
6773
diff
changeset
|
2362 |
] |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2363 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2364 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2365 |
'.' asFilename directoryContentsAsFilenamesDo:[:fn | Transcript showCR:fn pathName]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2366 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2367 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2368 |
"Modified: / 18.9.1997 / 18:42:23 / stefan" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2369 |
"Modified: / 23.12.1999 / 20:56:35 / cg" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2370 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2371 |
|
7464 | 2372 |
directoryContentsDo:aBlock |
2373 |
"evaluate aBlock for each file in the directory represented by the receiver. |
|
2374 |
The block is invoked with a string as argument. |
|
2375 |
The enumerations order is undefined - i.e. usually NOT sorted by |
|
2376 |
filenames (but by creation time - on some systems). |
|
2377 |
This excludes entries for '.' or '..'. |
|
17310 | 2378 |
An OpenError exception is raised it the directory does not exist or is not readable. |
7464 | 2379 |
So users of this method better test for existing directory before. |
2380 |
Notice: this enumerates strings; see also |
|
2381 |
#directoryContentsAsFilenamesDo:, which enumerates fileName objects." |
|
2382 |
||
20533 | 2383 |
|s files| |
17310 | 2384 |
|
2385 |
s := DirectoryStream directoryNamed:self osNameForDirectoryContents. |
|
2386 |
"check for nil, in order to allow to proceed from an OpenError" |
|
2387 |
s notNil ifTrue:[ |
|
20533 | 2388 |
"/ the old code did a recursive call with the stream open. |
2389 |
"/ for very very deep hierarchies, this lead to having too many file streams open for |
|
2390 |
"/ some operating systems. |
|
2391 |
"/ (and therefore to a blocked system, sooner or later, when running out of open files) |
|
2392 |
"/ new code reads the directory first, then does the recursion. |
|
2393 |
||
2394 |
"/ [ |
|
2395 |
"/ [s atEnd] whileFalse:[ |
|
2396 |
"/ |fn| |
|
2397 |
"/ |
|
2398 |
"/ fn := s nextLine. |
|
2399 |
"/ (fn notNil and:[fn ~= '.' and:[fn ~= '..']]) ifTrue:[ |
|
2400 |
"/ aBlock value:fn |
|
2401 |
"/ ]. |
|
2402 |
"/ ]. |
|
2403 |
"/ ] ensure:[ |
|
2404 |
"/ s close. |
|
2405 |
"/ ]. |
|
2406 |
files := OrderedCollection new. |
|
2407 |
||
19821 | 2408 |
[ |
2409 |
[s atEnd] whileFalse:[ |
|
2410 |
|fn| |
|
2411 |
||
2412 |
fn := s nextLine. |
|
2413 |
(fn notNil and:[fn ~= '.' and:[fn ~= '..']]) ifTrue:[ |
|
20533 | 2414 |
files add:fn |
19821 | 2415 |
]. |
2416 |
]. |
|
2417 |
] ensure:[ |
|
2418 |
s close. |
|
20533 | 2419 |
]. |
2420 |
files do:aBlock |
|
7464 | 2421 |
]. |
2422 |
||
2423 |
" |
|
2424 |
'.' asFilename directoryContentsDo:[:fn | Transcript showCR:fn]. |
|
7473 | 2425 |
'doeSnotExIST' asFilename directoryContentsDo:[:fn | Transcript showCR:fn]. |
17310 | 2426 |
[ |
19821 | 2427 |
'doeSnotExIST' asFilename directoryContentsDo:[:fn | Transcript showCR:fn]. |
17310 | 2428 |
] on:OpenError do:[:ex| ex proceed] |
7464 | 2429 |
" |
2430 |
||
2431 |
"Modified: / 18.9.1997 / 18:42:23 / stefan" |
|
2432 |
"Modified: / 23.12.1999 / 20:56:35 / cg" |
|
2433 |
! |
|
2434 |
||
9806 | 2435 |
filesDo:aBlock |
18734 | 2436 |
"evaluate aBlock for all regular files (i.e. subdirs are ignored) |
2437 |
contained in the directory represented by the receiver." |
|
9806 | 2438 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2439 |
^ self directoryContentsAsFilenamesDo:[:eachFileOrDirectory | |
19599 | 2440 |
eachFileOrDirectory isRegularFile ifTrue:[ |
2441 |
aBlock value: eachFileOrDirectory |
|
2442 |
]. |
|
17310 | 2443 |
]. |
9806 | 2444 |
|
2445 |
" |
|
2446 |
'.' asFilename filesDo:[:f | Transcript showCR:f]. |
|
2447 |
" |
|
2448 |
||
2449 |
"Created: / 29-08-2006 / 11:03:15 / cg" |
|
10557 | 2450 |
"Modified: / 29-05-2007 / 12:02:46 / cg" |
9806 | 2451 |
! |
2452 |
||
19821 | 2453 |
filesMatchingGLOB:pattern do:aBlock |
2454 |
"Interpreting pattern as a GLOB pattern, |
|
2455 |
evaluate aBlock for each file in me, which matches. |
|
2456 |
Returns the number of matches." |
|
2457 |
||
2458 |
self assert:(pattern asFilename isAbsolute not). |
|
2459 |
^ self filesMatchingGLOBComponents:(Filename components:pattern) do:aBlock |
|
2460 |
||
2461 |
" |
|
2462 |
'..' asFilename filesMatchingGLOB:'A*' do:[:fn | Transcript showCR:fn]. |
|
2463 |
'../..' asFilename filesMatchingGLOB:'lib*/*.st' do:[:fn | Transcript showCR:fn]. |
|
23393 | 2464 |
'/Library/Java/JavaVirtualMachines' asFilename filesMatchingGLOB:'*.jdk' do:[:fn | Transcript showCR:fn]. |
2465 |
" |
|
2466 |
||
2467 |
"Modified (comment): / 30-09-2018 / 10:59:19 / Claus Gittinger" |
|
19821 | 2468 |
! |
2469 |
||
2470 |
filesMatchingGLOBComponents:patternComponents do:aBlock |
|
2471 |
"patternComponents is a component-collection with possible GLOB patterns. |
|
2472 |
Evaluate aBlock for each file in me, which matches. |
|
2473 |
Returns the number of matches" |
|
2474 |
||
2475 |
|dirPath subComponents count| |
|
2476 |
||
2477 |
dirPath := patternComponents first. |
|
2478 |
subComponents := patternComponents copyFrom:2. |
|
2479 |
||
2480 |
dirPath includesMatchCharacters ifFalse:[ |
|
2481 |
| sub | |
|
2482 |
||
2483 |
sub := (self / dirPath). |
|
2484 |
subComponents isEmpty ifTrue:[ |
|
2485 |
"/ I am a leaf |
|
2486 |
sub exists ifTrue:[ |
|
2487 |
aBlock value:sub. |
|
2488 |
^ 1. |
|
2489 |
]. |
|
2490 |
^ 0 |
|
2491 |
] ifFalse:[ |
|
2492 |
^ sub filesMatchingGLOBComponents:subComponents do:aBlock |
|
2493 |
]. |
|
2494 |
] ifTrue:[ |
|
2495 |
count := 0. |
|
2496 |
subComponents isEmpty ifTrue:[ |
|
2497 |
"/ I am a leaf |
|
2498 |
self isDirectory ifTrue:[ |
|
2499 |
self filesMatching:dirPath do:[:eachMatchingFile | |
|
2500 |
aBlock value:(self / eachMatchingFile). |
|
2501 |
count := count + 1. |
|
2502 |
] |
|
2503 |
] |
|
2504 |
] ifFalse:[ |
|
2505 |
self filesMatching:dirPath do:[:eachMatchingSubDir | |
|
2506 |
|sub| |
|
2507 |
sub := (self / eachMatchingSubDir). |
|
2508 |
sub isDirectory ifTrue:[ |
|
2509 |
count := count + (sub filesMatchingGLOBComponents:subComponents do:aBlock) |
|
2510 |
]. |
|
2511 |
]. |
|
2512 |
]. |
|
2513 |
^ count |
|
2514 |
]. |
|
2515 |
||
2516 |
" |
|
2517 |
'/etc/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2518 |
'../A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2519 |
'../../lib*/*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2520 |
" |
|
2521 |
! |
|
2522 |
||
2523 |
filesMatchingGLOBDo:aBlock |
|
2524 |
"Interpreting myself as a GLOB pattern, |
|
2525 |
evaluate aBlock for each file which matches." |
|
2526 |
||
2527 |
|parts dirPath subComponents count top| |
|
2528 |
||
2529 |
parts := self components. |
|
2530 |
dirPath := parts first. |
|
2531 |
subComponents := parts copyFrom:2. |
|
2532 |
||
2533 |
OpenError handle:[:ex | |
|
2534 |
('%1 [info]: failed to open %2: %3' |
|
2535 |
bindWith:self class name |
|
2536 |
with:ex pathName |
|
2537 |
with:ex description) infoPrintCR. |
|
2538 |
self breakPoint:#cg. |
|
2539 |
ex proceed. |
|
2540 |
] do:[ |
|
2541 |
top := dirPath asFilename. |
|
2542 |
||
2543 |
dirPath includesMatchCharacters ifFalse:[ |
|
2544 |
top isAbsolute ifFalse:[ |
|
2545 |
top := Filename currentDirectory construct:dirPath. |
|
2546 |
]. |
|
2547 |
^ top filesMatchingGLOBComponents:subComponents do:aBlock |
|
2548 |
]. |
|
2549 |
||
2550 |
top isAbsolute ifFalse:[ |
|
2551 |
top := Filename currentDirectory. |
|
2552 |
]. |
|
2553 |
count := 0. |
|
2554 |
top filesMatching:dirPath do:[:sub | |
|
2555 |
count := count + ((self / sub) filesMatchingGLOBComponents:subComponents do:aBlock) |
|
2556 |
]. |
|
2557 |
^ count |
|
2558 |
]. |
|
2559 |
||
2560 |
" |
|
2561 |
'/etc/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2562 |
'/etc/a*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2563 |
'../A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2564 |
'../../lib*/*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2565 |
'../../lib*/[A-D]*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2566 |
'../../*/[A-D]*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2567 |
'../../*/*/[A-D]*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2568 |
'../../*java*/*/[A-D]*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2569 |
'../../*java*/*/Ary.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2570 |
'/*/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2571 |
'*/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2572 |
'../*/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2573 |
'./*/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2574 |
'./*/*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2575 |
'././A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2576 |
" |
|
2577 |
! |
|
2578 |
||
18734 | 2579 |
filesWithSuffix:suffix do:aBlock |
2580 |
"evaluate aBlock for all regular files with a given suffix |
|
2581 |
contained in the directory represented by the receiver. |
|
2582 |
(i.e. subdirs are ignored)" |
|
2583 |
||
2584 |
^ self directoryContentsAsFilenamesDo:[:eachFileOrDirectory | |
|
19599 | 2585 |
(eachFileOrDirectory hasSuffix:suffix) ifTrue:[ |
2586 |
eachFileOrDirectory isRegularFile ifTrue:[ |
|
2587 |
aBlock value: eachFileOrDirectory |
|
2588 |
]. |
|
2589 |
]. |
|
18734 | 2590 |
]. |
2591 |
||
2592 |
" |
|
2593 |
'.' asFilename filesWithSuffix:'so' do:[:f | Transcript showCR:f]. |
|
2594 |
" |
|
2595 |
! |
|
2596 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2597 |
recursiveDirectoryContentsAsFilenamesDo:aBlock |
13191
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2598 |
"evaluate aBlock for all files and directories found under the receiver. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2599 |
The block is invoked with the filenames as argument. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2600 |
The walk is bread-first. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2601 |
This excludes any entries for '.' or '..'. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2602 |
Subdirectory files are included with a relative pathname. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2603 |
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
|
2604 |
|
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2605 |
self recursiveDirectoryContentsDo:[:relFn | |
19664 | 2606 |
aBlock value:(self construct:relFn) |
13191
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2607 |
]. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2608 |
|
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2609 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2610 |
'.' asFilename recursiveDirectoryContentsAsFilenamesDo:[:f | Transcript showCR:f] |
13191
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2611 |
" |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2612 |
|
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2613 |
"Modified: / 12-09-2010 / 15:43:22 / cg" |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2614 |
! |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2615 |
|
20686 | 2616 |
recursiveDirectoryContentsAsFilenamesDo:aBlock filterForVisitingDirectories:filterOrNil |
2617 |
"evaluate aBlock for all files and directories found under the receiver. |
|
2618 |
The block is invoked with the filenames as argument. |
|
2619 |
The walk is bread-first. |
|
2620 |
This excludes any entries for '.' or '..'. |
|
2621 |
Subdirectory files are included with a relative pathname. |
|
2622 |
If filterOrNil is nonNil, it is passed every directory about to be walked into; |
|
2623 |
if it returns false, that directory is not entered. |
|
2624 |
Warning: this may take a long time to execute |
|
2625 |
(especially with deep and/or remote fileSystems)." |
|
2626 |
||
2627 |
self |
|
2628 |
recursiveDirectoryContentsDo:[:relFn | |
|
2629 |
aBlock value:(self construct:relFn) |
|
2630 |
] |
|
2631 |
filterForVisitingDirectories:filterOrNil. |
|
2632 |
||
2633 |
" |
|
2634 |
'.' asFilename recursiveDirectoryContentsAsFilenamesDo:[:f | Transcript showCR:f] |
|
2635 |
" |
|
2636 |
||
2637 |
"Modified: / 12-09-2010 / 15:43:22 / cg" |
|
2638 |
! |
|
2639 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2640 |
recursiveDirectoryContentsDo:aBlock |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2641 |
"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
|
2642 |
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
|
2643 |
The walk is bread-first. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2644 |
This excludes any entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2645 |
Subdirectory files are included with a relative pathname. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2646 |
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
|
2647 |
|
19664 | 2648 |
self |
2649 |
recursiveDirectoryContentsWithPrefix:'' |
|
2650 |
filesDo:aBlock |
|
2651 |
directoriesDo:aBlock |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2652 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2653 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2654 |
'.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2655 |
" |
13057
4f7fa62156ac
comment/format in: #recursiveDirectoryContentsDo:
Claus Gittinger <cg@exept.de>
parents:
12975
diff
changeset
|
2656 |
|
4f7fa62156ac
comment/format in: #recursiveDirectoryContentsDo:
Claus Gittinger <cg@exept.de>
parents:
12975
diff
changeset
|
2657 |
"Modified: / 12-09-2010 / 15:43:22 / cg" |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2658 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2659 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2660 |
recursiveDirectoryContentsDo:aBlock directoryPrefix:aPrefix |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2661 |
"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
|
2662 |
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
|
2663 |
The walk is breadth-first. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2664 |
This excludes any entries for '.' or '..'. |
19664 | 2665 |
The argument to aBlock is a pathname relative to aPrefix. |
19114 | 2666 |
A proceedable exception is raised forn non-accessible directories. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2667 |
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
|
2668 |
|
19664 | 2669 |
self |
2670 |
recursiveDirectoryContentsWithPrefix:aPrefix |
|
2671 |
filesDo:aBlock |
|
2672 |
directoriesDo:aBlock |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2673 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2674 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2675 |
'.' 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
|
2676 |
'/etc' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2677 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2678 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2679 |
|
20686 | 2680 |
recursiveDirectoryContentsDo:aBlock filterForVisitingDirectories:filterOrNil |
2681 |
"evaluate aBlock for all files and directories found under the receiver. |
|
2682 |
The block is invoked with the relative filenames as string-argument. |
|
2683 |
The walk is bread-first. |
|
2684 |
This excludes any entries for '.' or '..'. |
|
2685 |
Subdirectory files are included with a relative pathname. |
|
2686 |
If filterOrNil is nonNil, it is passed every directory about to be walked into; |
|
2687 |
if it returns false, that directory is not entered. |
|
2688 |
Warning: this may take a long time to execute |
|
2689 |
(especially with deep and/or remote fileSystems)." |
|
2690 |
||
2691 |
self |
|
2692 |
recursiveDirectoryContentsWithPrefix:'' |
|
2693 |
filesDo:aBlock |
|
2694 |
directoriesDo:aBlock |
|
2695 |
filterForVisitingDirectories:filterOrNil |
|
2696 |
||
2697 |
" |
|
2698 |
'.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] |
|
2699 |
" |
|
2700 |
||
2701 |
"Modified: / 12-09-2010 / 15:43:22 / cg" |
|
2702 |
! |
|
2703 |
||
19664 | 2704 |
recursiveDirectoryContentsWithPrefix:aPrefix filesDo:fileBlock directoriesDo:dirBlock |
2705 |
"evaluate aBlock for all files and directories found under the receiver. |
|
2706 |
The blocks are invoked with a relative pathname as string-argument. |
|
2707 |
The walk is breadth-first (first files, then directories). |
|
2708 |
This excludes any entries for '.' or '..'. |
|
2709 |
A proceedable exception is raised for non-accessible directories. |
|
20686 | 2710 |
Warning: this may take a long time to execute |
2711 |
(especially with deep and/or remote fileSystems)." |
|
2712 |
||
2713 |
self |
|
2714 |
recursiveDirectoryContentsWithPrefix:aPrefix |
|
2715 |
filesDo:fileBlock |
|
2716 |
directoriesDo:dirBlock |
|
2717 |
filterForVisitingDirectories:nil |
|
2718 |
||
2719 |
" |
|
2720 |
'.' asFilename |
|
2721 |
recursiveDirectoryContentsWithPrefix:'bla' |
|
2722 |
filesDo:[:f | Transcript show:'file: '; showCR:f] |
|
2723 |
directoriesDo:[:f | Transcript show:'dir: '; showCR:f] |
|
2724 |
" |
|
2725 |
! |
|
2726 |
||
22500 | 2727 |
recursiveDirectoryContentsWithPrefix:aPrefix filesDo:fileBlock directoriesDo:dirBlock |
2728 |
filterForVisitingDirectories:filterOrNil |
|
2729 |
||
20686 | 2730 |
"evaluate aBlock for all files and directories found under the receiver. |
2731 |
The blocks are invoked with a relative pathname as string-argument. |
|
2732 |
The walk is breadth-first (first files, then directories). |
|
2733 |
This excludes any entries for '.' or '..'. |
|
2734 |
A proceedable exception is raised for non-accessible directories. |
|
2735 |
If filterOrNil is nonNil, it is passed every directory about to be walked into; |
|
2736 |
if it returns false, that directory is not entered. |
|
2737 |
Warning: this may take a long time to execute |
|
2738 |
(especially with deep and/or remote fileSystems). |
|
2739 |
" |
|
19664 | 2740 |
|
2741 |
|fileNames dirNames p| |
|
2742 |
||
2743 |
"/ first collect files and dirs |
|
2744 |
fileNames := OrderedCollection new. |
|
2745 |
dirNames := OrderedCollection new. |
|
2746 |
||
2747 |
self directoryContentsDo:[:f | |t| |
|
2748 |
t := self construct:f. |
|
2749 |
t isDirectory ifTrue:[ |
|
20686 | 2750 |
(filterOrNil isNil or:[filterOrNil value:t]) ifTrue:[ |
2751 |
dirBlock notNil ifTrue:[ |
|
2752 |
t isSymbolicLink ifFalse:[ |
|
2753 |
dirNames add:f |
|
2754 |
] |
|
19664 | 2755 |
] |
2756 |
] |
|
2757 |
] ifFalse:[ |
|
2758 |
fileBlock notNil ifTrue:[ |
|
2759 |
fileNames add:f |
|
2760 |
] |
|
2761 |
] |
|
2762 |
]. |
|
2763 |
||
2764 |
aPrefix size > 0 ifTrue:[ |
|
2765 |
p := aPrefix , self separator |
|
2766 |
] ifFalse:[ |
|
2767 |
p := '' |
|
2768 |
]. |
|
2769 |
||
2770 |
fileBlock notNil ifTrue:[ |
|
2771 |
fileNames do:[:aFile | fileBlock value:(p , aFile)]. |
|
2772 |
]. |
|
2773 |
dirBlock notNil ifTrue:[ |
|
2774 |
dirNames do:[:dN | |
|
20686 | 2775 |
|subDir| |
2776 |
||
2777 |
subDir := (self construct:dN). |
|
2778 |
(filterOrNil isNil or:[filterOrNil value:subDir]) ifTrue:[ |
|
2779 |
dirBlock value:(p , dN). |
|
2780 |
subDir |
|
2781 |
recursiveDirectoryContentsWithPrefix:(p , dN) |
|
2782 |
filesDo:fileBlock directoriesDo:dirBlock |
|
22500 | 2783 |
filterForVisitingDirectories:filterOrNil |
20686 | 2784 |
]. |
19664 | 2785 |
]. |
2786 |
]. |
|
2787 |
||
2788 |
" |
|
2789 |
'.' asFilename |
|
2790 |
recursiveDirectoryContentsWithPrefix:'bla' |
|
2791 |
filesDo:[:f | Transcript show:'file: '; showCR:f] |
|
2792 |
directoriesDo:[:f | Transcript show:'dir: '; showCR:f] |
|
2793 |
" |
|
2794 |
! |
|
2795 |
||
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2796 |
withAllDirectoriesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2797 |
"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
|
2798 |
The block is invoked with a filename-arguments. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2799 |
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
|
2800 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2801 |
This excludes entries for '.' or '..'. |
17310 | 2802 |
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
|
2803 |
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
|
2804 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2805 |
self isDirectory ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2806 |
aBlock value:self. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2807 |
]. |
17310 | 2808 |
self allDirectoriesDo:aBlock. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2809 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2810 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2811 |
'.' asFilename withAllDirectoriesDo:[:fn | Transcript showCR:fn name]. |
17310 | 2812 |
'IdoNOTexist' asFilename withAllDirectoriesDo:[:fn | Transcript showCR:fn name]. |
2813 |
'/etc/hosts' asFilename withAllDirectoriesDo:[:fn | Transcript showCR:fn name]. |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2814 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2815 |
! ! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2816 |
|
542 | 2817 |
!Filename methodsFor:'error handling'! |
2818 |
||
615 | 2819 |
fileCreationError:filename |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2820 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2821 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2822 |
"report an error that some file could not be created" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2823 |
|
615 | 2824 |
^ OperatingSystem accessDeniedErrorSignal |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2825 |
raiseRequestWith:filename?self |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2826 |
errorString:(' - cannot create/write file: "%1"' bindWith:(filename ? self) asString) |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2827 |
! |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2828 |
|
615 | 2829 |
reportError:string with:filename |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2830 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2831 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2832 |
"report an error" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2833 |
|
15192 | 2834 |
^ OsError |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2835 |
raiseRequestWith:filename?self |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2836 |
errorString:string |
615 | 2837 |
! ! |
2838 |
||
2839 |
!Filename methodsFor:'file access'! |
|
2840 |
||
3015 | 2841 |
appendStream |
2842 |
"return a stream for appending to the file represented by the receiver. |
|
2843 |
If the file does not already exist, it is created. |
|
2844 |
Same as #appendingWriteStream for ST-80 compatibility." |
|
2845 |
||
2846 |
^ self appendingWriteStream |
|
2847 |
! |
|
2848 |
||
615 | 2849 |
appendingWriteStream |
2850 |
"return a stream for appending to the file represented by the receiver. |
|
5720 | 2851 |
If the file does not already exist, it is created; |
2852 |
if it does exist, writes are appended at the end." |
|
615 | 2853 |
|
2947 | 2854 |
^ FileStream appendingOldFileNamed:(self osNameForAccess) |
5720 | 2855 |
|
2856 |
" |
|
2857 |
|s| |
|
2858 |
||
2859 |
s := '/tmp/foo' asFilename writeStream. |
|
2860 |
s nextPutAll:'1234567890'. |
|
2861 |
s close. |
|
2862 |
||
2863 |
s := '/tmp/foo' asFilename appendingWriteStream. |
|
2864 |
s nextPutAll:'abcdef'. |
|
2865 |
s close. |
|
2866 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2867 |
'/tmp/foo' asFilename contents |
5720 | 2868 |
" |
615 | 2869 |
! |
2870 |
||
15490 | 2871 |
existingReadWriteStream |
2872 |
"return a stream for read/write the file represented by the receiver. |
|
2873 |
If the file does not already exist, an exception is raised." |
|
2874 |
||
2875 |
^ FileStream oldFileNamed:(self osNameForAccess) |
|
2876 |
||
2877 |
" |
|
2878 |
'/tmp/blaFaselQuall666666' asFilename remove. |
|
2879 |
'/tmp/blaFaselQuall666666' asFilename existingReadWriteStream. |
|
2880 |
" |
|
2881 |
" |
|
2882 |
|s| |
|
2883 |
s := '/tmp/foo' asFilename readWriteStream. |
|
2884 |
s nextPutAll:'1234567890'; close. |
|
2885 |
s := '/tmp/foo' asFilename existingReadWriteStream. |
|
2886 |
s nextPutAll:'abcdef'; close. |
|
2887 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2888 |
'/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
|
2889 |
'/tmp/foo' asFilename remove |
15490 | 2890 |
" |
2891 |
! |
|
2892 |
||
615 | 2893 |
newReadWriteStream |
2894 |
"return a stream for read/write the file represented by the receiver. |
|
5720 | 2895 |
If the file does not already exist, it is created; |
2896 |
if it does exist, it is truncated." |
|
615 | 2897 |
|
2947 | 2898 |
^ FileStream newFileNamed:(self osNameForAccess) |
5720 | 2899 |
|
2900 |
" |
|
2901 |
|s| |
|
2902 |
||
2903 |
s := '/tmp/foo' asFilename writeStream. |
|
2904 |
s nextPutAll:'1234567890'. |
|
2905 |
s close. |
|
2906 |
||
2907 |
s := '/tmp/foo' asFilename newReadWriteStream. |
|
2908 |
s nextPutAll:'12345'. |
|
2909 |
s close. |
|
2910 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2911 |
'/tmp/foo' asFilename contents |
5720 | 2912 |
" |
615 | 2913 |
! |
2914 |
||
15459 | 2915 |
openWithMode:anArrayOrString |
2916 |
"return a stream for read/write the file represented by the receiver. |
|
2917 |
If the file does not already exist, it is created; |
|
2918 |
if it does exist, it is truncated." |
|
2919 |
||
2920 |
^ FileStream open:self osNameForAccess withMode:anArrayOrString |
|
2921 |
||
2922 |
" |
|
2923 |
|s| |
|
2924 |
||
2925 |
s := '/tmp/foo' asFilename openWithMode:'r+'. |
|
2926 |
s nextPutAll:'1234567890'. |
|
2927 |
s close. |
|
2928 |
||
2929 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2930 |
'/tmp/foo' asFilename contents |
15459 | 2931 |
" |
2932 |
! |
|
2933 |
||
615 | 2934 |
readStream |
20156 | 2935 |
"Return a stream for reading from the file represented by the receiver. |
7828 | 2936 |
Raises an error if the file does not exist." |
615 | 2937 |
|
2947 | 2938 |
^ FileStream readonlyFileNamed:(self osNameForAccess) |
615 | 2939 |
|
2940 |
" |
|
20156 | 2941 |
'/tmp/foo' asFilename readStream |
615 | 2942 |
" |
2943 |
! |
|
2944 |
||
2945 |
readWriteStream |
|
2946 |
"return a stream for read/write the file represented by the receiver. |
|
7828 | 2947 |
If the file does not already exist, it is created. |
2948 |
If the file does exist, it is NOT truncated, but rewritten at the beginning." |
|
615 | 2949 |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2950 |
^ FileStream fileNamed:(self osNameForAccess) |
5720 | 2951 |
|
2952 |
" |
|
2953 |
|s| |
|
2954 |
||
2955 |
s := '/tmp/foo' asFilename writeStream. |
|
2956 |
s nextPutAll:'1234567890'. |
|
2957 |
s close. |
|
2958 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2959 |
s := '/tmp/foo' asFilename readWriteStream. |
5720 | 2960 |
s nextPutAll:'abcdef'. |
2961 |
s close. |
|
2962 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2963 |
'/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
|
2964 |
'/tmp/foo' asFilename remove |
5720 | 2965 |
" |
615 | 2966 |
! |
2967 |
||
2968 |
writeStream |
|
2969 |
"return a stream for writing to the file represented by the receiver. |
|
5720 | 2970 |
If the file does not already exist, it is created; |
2971 |
if it does exist, it is truncated." |
|
615 | 2972 |
|
2947 | 2973 |
^ FileStream newFileForWritingNamed:(self osNameForAccess) |
615 | 2974 |
|
2975 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2976 |
'/tmp/foo' asFilename writeStream |
615 | 2977 |
" |
5720 | 2978 |
|
2979 |
" |
|
2980 |
|s| |
|
2981 |
||
2982 |
s := '/tmp/foo' asFilename writeStream. |
|
2983 |
s nextPutAll:'1234567890'. |
|
2984 |
s close. |
|
2985 |
||
2986 |
s := '/tmp/foo' asFilename writeStream. |
|
2987 |
s nextPutAll:'12345'. |
|
2988 |
s close. |
|
2989 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2990 |
'/tmp/foo' asFilename contents |
5720 | 2991 |
" |
615 | 2992 |
! ! |
2993 |
||
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2994 |
!Filename methodsFor:'file access - migration'! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2995 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2996 |
appendingWriteStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2997 |
"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
|
2998 |
If the file does not already exist, it is created; |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2999 |
if it does exist, writes are appended at the end. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3000 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3001 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3002 |
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
|
3003 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3004 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
3005 |
^ [ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3006 |
FileStream appendingOldFileNamed:(self osNameForAccess) |
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
3007 |
] on:FileStream openErrorSignal do:[:ex| nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3008 |
! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3009 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3010 |
newReadWriteStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3011 |
"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
|
3012 |
If the file does not already exist, it is created; |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3013 |
if it does exist, it is truncated. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3014 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3015 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3016 |
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
|
3017 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3018 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
3019 |
^ [ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3020 |
FileStream newFileNamed:(self osNameForAccess) |
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
3021 |
] on:FileStream openErrorSignal do:[:ex|nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3022 |
! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3023 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3024 |
readStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3025 |
"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
|
3026 |
If the file does not already exist, nil is returned. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3027 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3028 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3029 |
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
|
3030 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3031 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
3032 |
^ [ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3033 |
FileStream readonlyFileNamed:(self osNameForAccess) |
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
3034 |
] on:FileStream openErrorSignal do:[:ex|nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3035 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3036 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3037 |
'/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
|
3038 |
'/tmp/foo' asFilename readStream |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3039 |
" |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3040 |
! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3041 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3042 |
readWriteStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3043 |
"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
|
3044 |
If the file does not already exist, it is created. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3045 |
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
|
3046 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3047 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3048 |
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
|
3049 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3050 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
3051 |
^ [ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3052 |
FileStream fileNamed:(self osNameForAccess) |
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
3053 |
] on:FileStream openErrorSignal do:[:ex|^ nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3054 |
! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3055 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3056 |
writeStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3057 |
"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
|
3058 |
If the file does not already exist, it is created; |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3059 |
if it does exist, it is truncated. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3060 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3061 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3062 |
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
|
3063 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3064 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
3065 |
^ [ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3066 |
FileStream newFileForWritingNamed:(self osNameForAccess) |
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
3067 |
] on:FileStream openErrorSignal do:[:ex|^ nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3068 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3069 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3070 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3071 |
'/etc/foo' asFilename writeStreamOrNil |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3072 |
" |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3073 |
! ! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3074 |
|
16310 | 3075 |
!Filename methodsFor:'file access rights'! |
615 | 3076 |
|
12529 | 3077 |
accessRights |
3078 |
"return the access rights of the file as opaque data |
|
3079 |
(SmallInteger in unix/linux)" |
|
3080 |
||
21071 | 3081 |
|access| |
3082 |
||
3083 |
access := OperatingSystem accessModeOf:self osName. |
|
3084 |
access isOSErrorHolder ifTrue:[ |
|
3085 |
access reportProceedableError:'get access rights failed'. |
|
3086 |
]. |
|
3087 |
^ access. |
|
12529 | 3088 |
|
3089 |
" |
|
3090 |
'Make.proto' asFilename accessRights |
|
21071 | 3091 |
'foo' asFilename accessRights |
12529 | 3092 |
" |
3093 |
! |
|
3094 |
||
3095 |
accessRights:opaqueData |
|
3096 |
"set the access rights of the file to opaqueData, |
|
3097 |
which is normally retrieved by Filename>>#accessRights." |
|
3098 |
||
21064 | 3099 |
|osErrorHolder| |
3100 |
||
3101 |
osErrorHolder := OperatingSystem changeAccessModeOf:self osNameForFile to:opaqueData. |
|
3102 |
osErrorHolder notNil ifTrue:[ |
|
3103 |
osErrorHolder reportProceedableError:'change access rights failed'. |
|
3104 |
]. |
|
3105 |
||
12529 | 3106 |
|
3107 |
" |
|
3108 |
|rights| |
|
3109 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3110 |
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
|
3111 |
'Make.proto' asFilename accessRights:rights. |
12529 | 3112 |
" |
3113 |
||
3114 |
"Modified: / 5.5.1999 / 13:41:21 / cg" |
|
3115 |
! |
|
3116 |
||
615 | 3117 |
addAccessRights:aCollection |
3118 |
"add the access rights as specified in aCollection for the file represented |
|
3119 |
by the receiver. The argument must be a collection of symbols, |
|
3120 |
such as #readUser, #writeGroup etc." |
|
3121 |
||
21064 | 3122 |
|access osName osErrorHolder| |
2922 | 3123 |
|
2947 | 3124 |
osName := self osNameForFile. |
2922 | 3125 |
access := OperatingSystem accessModeOf:osName. |
21071 | 3126 |
access isOSErrorHolder ifTrue:[ |
3127 |
access reportProceedableError:'get access rights failed'. |
|
3128 |
]. |
|
3129 |
||
615 | 3130 |
aCollection do:[:accessSymbol | |
21064 | 3131 |
access := access bitOr:(OperatingSystem accessMaskFor:accessSymbol). |
3132 |
]. |
|
3133 |
osErrorHolder := OperatingSystem changeAccessModeOf:osName to:access. |
|
3134 |
osErrorHolder notNil ifTrue:[ |
|
3135 |
osErrorHolder reportProceedableError:'change access rights failed'. |
|
3136 |
]. |
|
615 | 3137 |
|
3138 |
" |
|
3139 |
'foo' asFilename writeStream close. |
|
3140 |
'foo' asFilename addAccessRights:#(readUser readGroup readOthers). |
|
3141 |
'foo' asFilename addAccessRights:#(writeUser writeGroup writeOthers). |
|
3142 |
'foo' asFilename addAccessRights:#(executeUser executeGroup executeOthers). |
|
3143 |
" |
|
3144 |
! |
|
3145 |
||
6223 | 3146 |
makeExecutable |
3147 |
"make the file executable - you must have permission to do so. |
|
3148 |
For directories, execution means: 'allow changing into it'" |
|
3149 |
||
3150 |
^ self addAccessRights:#(executeUser) |
|
3151 |
||
3152 |
"Created: 9.1.1996 / 15:32:47 / cg" |
|
3153 |
! |
|
3154 |
||
3155 |
makeExecutableForAll |
|
3156 |
"make the file executable for all - you must have permission to do so. |
|
3157 |
For directories, execution means: 'allow changing into it'" |
|
3158 |
||
3159 |
^ self addAccessRights:#(executeUser executeGroup executeOthers) |
|
3160 |
||
3161 |
"Created: 9.1.1996 / 15:32:28 / cg" |
|
3162 |
! |
|
3163 |
||
3164 |
makeExecutableForGroup |
|
3165 |
"make the file executable for the group - you must have permission to do so. |
|
3166 |
For directories, execution means: 'allow changing into it'" |
|
3167 |
||
3168 |
^ self addAccessRights:#(executeGroup) |
|
3169 |
||
3170 |
"Created: 9.1.1996 / 15:32:28 / cg" |
|
3171 |
! |
|
3172 |
||
3173 |
makeReadable |
|
3174 |
"make the file readable for the owner - you must have permission to do so." |
|
3175 |
||
3176 |
^ self addAccessRights:#(readUser) |
|
3177 |
! |
|
3178 |
||
3179 |
makeReadableForAll |
|
3180 |
"make the file readable for all - you must have permission to do so." |
|
3181 |
||
3182 |
^ self addAccessRights:#(readUser readGroup readOthers) |
|
3183 |
! |
|
3184 |
||
3185 |
makeReadableForGroup |
|
3186 |
"make the file readable for the group - you must have permission to do so." |
|
3187 |
||
3188 |
^ self addAccessRights:#(readGroup) |
|
3189 |
! |
|
3190 |
||
3191 |
makeUnwritable |
|
3192 |
"make the file unwritable for all - you must have permission to do so." |
|
3193 |
||
3194 |
^ self removeAccessRights:#(writeUser writeGroup writeOthers) |
|
3195 |
! |
|
3196 |
||
3197 |
makeWritable |
|
3198 |
"make the file writableable for all - you must have permission to do so." |
|
3199 |
||
3200 |
^ self addAccessRights:#(writeUser) |
|
3201 |
! |
|
3202 |
||
3203 |
makeWritableForAll |
|
3204 |
"make the file writable for all - you must have permission to do so." |
|
3205 |
||
3206 |
^ self addAccessRights:#(writeUser writeGroup writeOthers) |
|
3207 |
! |
|
3208 |
||
3209 |
makeWritableForGroup |
|
3210 |
"make the file writable for the group - you must have permission to do so." |
|
3211 |
||
3212 |
^ self addAccessRights:#(writeGroup) |
|
3213 |
! |
|
3214 |
||
3215 |
removeAccessRights:aCollection |
|
3216 |
"remove the access rights as specified in aCollection for the file represented |
|
3217 |
by the receiver. The argument must be a collection of symbols, |
|
3218 |
such as #readUser, #writeGroup etc. |
|
3219 |
Raises an exception if not successful." |
|
3220 |
||
21064 | 3221 |
|access osName osErrorHolder| |
6223 | 3222 |
|
3223 |
osName := self osNameForFile. |
|
3224 |
access := OperatingSystem accessModeOf:osName. |
|
21071 | 3225 |
access isOSErrorHolder ifTrue:[ |
3226 |
access reportProceedableError:'get access rights failed'. |
|
3227 |
]. |
|
3228 |
||
6223 | 3229 |
aCollection do:[:accessSymbol | |
21064 | 3230 |
access := access bitAnd:(OperatingSystem accessMaskFor:accessSymbol) bitInvert. |
3231 |
]. |
|
3232 |
osErrorHolder := OperatingSystem changeAccessModeOf:osName to:access. |
|
3233 |
osErrorHolder notNil ifTrue:[ |
|
3234 |
osErrorHolder reportProceedableError:'change access rights failed'. |
|
6223 | 3235 |
]. |
3236 |
||
3237 |
" |
|
3238 |
'foo' asFilename writeStream close. |
|
3239 |
'foo' asFilename removeAccessRights:#(readUser readGroup readOthers). |
|
3240 |
'foo' asFilename removeAccessRights:#(writeUser writeGroup writeOthers). |
|
3241 |
'foo' asFilename removeAccessRights:#(executeUser executeGroup executeOthers). |
|
3242 |
" |
|
3243 |
||
3244 |
"Modified: / 5.5.1999 / 13:41:21 / cg" |
|
3245 |
! |
|
3246 |
||
3247 |
symbolicAccessRights |
|
3248 |
"return the access rights of the file as a aCollection of access symbols. |
|
3249 |
The returned collection consists of symbols like: |
|
21071 | 3250 |
#readUser, #writeGroup etc." |
6223 | 3251 |
|
3252 |
|access osName| |
|
3253 |
||
3254 |
osName := self osNameForFile. |
|
3255 |
access := OperatingSystem accessModeOf:osName. |
|
21071 | 3256 |
access isOSErrorHolder ifTrue:[ |
3257 |
access reportProceedableError:'get access rights failed'. |
|
3258 |
]. |
|
6223 | 3259 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3260 |
^ |
21071 | 3261 |
#( readUser writeUser executeUser |
3262 |
readGroup writeGroup executeGroup |
|
3263 |
readOthers writeOthers executeOthers |
|
3264 |
) select:[:eachSymbolicAccessSymbol | |
|
3265 |
access bitTest:(OperatingSystem accessMaskFor:eachSymbolicAccessSymbol). |
|
3266 |
]. |
|
3267 |
||
3268 |
" |
|
3269 |
'Make.proto' asFilename symbolicAccessRights |
|
6223 | 3270 |
" |
3271 |
||
3272 |
"Modified: / 5.5.1999 / 13:41:21 / cg" |
|
3273 |
! |
|
3274 |
||
3275 |
symbolicAccessRights:aCollectionOfSymbols |
|
3276 |
"set the access rights of the file given a aCollection of access symbols. |
|
3277 |
The collection must consist of symbols like: |
|
21064 | 3278 |
#readUser, #writeGroup etc." |
3279 |
||
3280 |
|access osName osErrorHolder| |
|
6223 | 3281 |
|
3282 |
osName := self osNameForFile. |
|
3283 |
access := aCollectionOfSymbols inject:0 into:[:bitsSoFar :eachSymbolicAccessSymbol | |
|
21064 | 3284 |
bitsSoFar bitOr:(OperatingSystem accessMaskFor:eachSymbolicAccessSymbol) |
3285 |
]. |
|
3286 |
||
3287 |
osErrorHolder := OperatingSystem changeAccessModeOf:osName to:access. |
|
3288 |
osErrorHolder notNil ifTrue:[ |
|
3289 |
osErrorHolder reportProceedableError:'change access rights failed'. |
|
6223 | 3290 |
]. |
3291 |
||
3292 |
" |
|
3293 |
|rights| |
|
3294 |
||
21071 | 3295 |
rights := 'Make.proto' asFilename symbolicAccessRights. |
3296 |
'Make.proto' asFilename symbolicAccessRights:(rights , #(executeOthers)). |
|
6223 | 3297 |
" |
3298 |
||
3299 |
"Modified: / 5.5.1999 / 13:41:21 / cg" |
|
3300 |
! ! |
|
3301 |
||
3302 |
!Filename methodsFor:'file operations'! |
|
3303 |
||
7329 | 3304 |
appendTo:newNameOrStream |
3305 |
"append the file - the argument must be convertable to a filename. |
|
3306 |
Raises an exception, if an error occurs." |
|
3307 |
||
3308 |
|inStream outStream outStreamToClose| |
|
3309 |
||
3310 |
inStream := self readStream. |
|
3311 |
[ |
|
21064 | 3312 |
newNameOrStream isStream ifTrue:[ |
3313 |
outStream := newNameOrStream. |
|
3314 |
] ifFalse:[ |
|
3315 |
outStream := outStreamToClose := newNameOrStream asFilename appendingWriteStream. |
|
3316 |
]. |
|
3317 |
||
3318 |
inStream binary. |
|
3319 |
outStream binary. |
|
3320 |
||
3321 |
inStream copyToEndInto:outStream. |
|
7329 | 3322 |
] ensure:[ |
21064 | 3323 |
inStream close. |
3324 |
outStreamToClose notNil ifTrue:[outStreamToClose close]. |
|
7329 | 3325 |
]. |
3326 |
||
3327 |
" |
|
3328 |
'/etc/group' asFilename appendTo:'/tmp/Makefile.foo'. |
|
3329 |
'Makefile' asFilename appendTo:'/tmp/Makefile.foo' |
|
3330 |
'Makefile' asFilename copyTo:'/' |
|
3331 |
'smalltalk' asFilename copyTo:'/dev/null' |
|
3332 |
" |
|
3333 |
||
3334 |
"Modified: / 23.12.1999 / 21:52:36 / cg" |
|
3335 |
! |
|
3336 |
||
10020 | 3337 |
copyTo:newNameArg |
16578 | 3338 |
"Copy the file's contents into another file. |
9235 | 3339 |
The argument must be convertable to a filename. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3340 |
Raises an exception, if an error occurs." |
615 | 3341 |
|
12529 | 3342 |
|newName inStream outStream newNameAlreadyExists| |
10020 | 3343 |
|
3344 |
newName := newNameArg asFilename. |
|
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
3345 |
|
19957 | 3346 |
"Contents is not copied if newName represents the same file as me." |
10020 | 3347 |
newName asAbsoluteFilename = self asAbsoluteFilename ifTrue: [ ^ self ]. |
8535 | 3348 |
|
19957 | 3349 |
(newName exists and:[newName isDirectory]) ifTrue:[ |
3350 |
newName := newName construct:(self baseName). |
|
3351 |
]. |
|
3352 |
||
615 | 3353 |
inStream := self readStream. |
17143 | 3354 |
inStream isNil ifTrue:[ |
19957 | 3355 |
"open failed, but somenone did a proceed for the OpenError. |
3356 |
Ignore this file but continue in order to copy the rest when |
|
3357 |
doing a recursive copy" |
|
3358 |
^ self. |
|
17143 | 3359 |
]. |
3360 |
||
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
3361 |
[ |
19957 | 3362 |
newNameAlreadyExists := newName exists. |
3363 |
outStream := newName writeStream. |
|
3364 |
newNameAlreadyExists ifFalse:[ |
|
21064 | 3365 |
"ignore the error - may occur when copying to a network drive" |
3366 |
OsError catch:[ |
|
19957 | 3367 |
"would be nice to keep the access rights of the original test suite" |
3368 |
newName accessRights:self accessRights. |
|
3369 |
]. |
|
3370 |
]. |
|
3371 |
inStream binary; buffered:false. |
|
3372 |
outStream binary; buffered:false. |
|
3373 |
inStream copyToEndInto:outStream. |
|
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
3374 |
] ensure:[ |
19957 | 3375 |
inStream close. |
3376 |
outStream notNil ifTrue:[outStream close]. |
|
615 | 3377 |
]. |
3378 |
||
3379 |
" |
|
12529 | 3380 |
'Make.proto' asFilename copyTo:'/tmp/Makefile.foo' |
3381 |
'Make.proto' asFilename copyTo:'/' |
|
615 | 3382 |
'smalltalk' asFilename copyTo:'/dev/null' |
3383 |
" |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3384 |
|
10020 | 3385 |
"Modified: / 10-09-2004 / 09:49:28 / janfrog" |
19957 | 3386 |
"Modified: / 06-06-2016 / 12:15:25 / cg" |
615 | 3387 |
! |
3388 |
||
15465 | 3389 |
copyToStream:outStream |
16578 | 3390 |
"Copy the file's contents into another file. |
15465 | 3391 |
The argument must be convertable to a filename. |
3392 |
Raises an exception, if an error occurs." |
|
3393 |
||
15858 | 3394 |
|inStream resetBinary| |
15465 | 3395 |
|
3396 |
"Contents is not copied if newName represent same file as me." |
|
3397 |
outStream isFileStream ifTrue:[ |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3398 |
outStream fileName asAbsoluteFilename = self asAbsoluteFilename ifTrue: [ ^ self ]. |
15465 | 3399 |
]. |
3400 |
||
3401 |
inStream := self readStream. |
|
3402 |
[ |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3403 |
inStream binary"; buffered:false". |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3404 |
resetBinary := false. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3405 |
outStream isBinary ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3406 |
outStream binary. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3407 |
resetBinary := true. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3408 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3409 |
inStream copyToEndInto:outStream. |
15465 | 3410 |
] ensure:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3411 |
inStream close. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3412 |
resetBinary ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3413 |
outStream text. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3414 |
]. |
15465 | 3415 |
]. |
3416 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3417 |
" |
15465 | 3418 |
|out| |
3419 |
out := FileStream newTemporary. |
|
3420 |
'Make.proto' asFilename copyToStream:out. |
|
3421 |
out reset; contents |
|
3422 |
" |
|
3423 |
! |
|
3424 |
||
6983 | 3425 |
createAsEmptyFile |
19440 | 3426 |
"create an empty file with the receiver's name. |
6983 | 3427 |
Raises an exception if not successful |
3428 |
(either already existing or creation not possible)" |
|
3429 |
||
3430 |
|writeStream| |
|
3431 |
||
3432 |
self exists ifTrue:[ |
|
19599 | 3433 |
OperatingSystem accessDeniedErrorSignal |
3434 |
raiseRequestWith:self |
|
3435 |
errorString:(' - file exists: ' , self asString). |
|
3436 |
^ self |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3437 |
]. |
6983 | 3438 |
|
3439 |
FileStream openErrorSignal handle:[:ex| |
|
19599 | 3440 |
self fileCreationError:self. |
3441 |
^ self |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3442 |
] do:[ |
19599 | 3443 |
writeStream := self newReadWriteStream. |
6983 | 3444 |
]. |
3445 |
writeStream close. |
|
3446 |
! |
|
3447 |
||
21064 | 3448 |
createAsHardLinkTo:linkFilenameString |
3449 |
"create a directory with the receiver's name. |
|
3450 |
Raises an exception if not successful" |
|
3451 |
||
3452 |
|errorHolder| |
|
3453 |
||
3454 |
errorHolder := OperatingSystem createHardLinkFrom:linkFilenameString asFilename osName to:self osName. |
|
3455 |
errorHolder notNil ifTrue:[ |
|
3456 |
errorHolder reportProceedableError:'hard link failed'. |
|
3457 |
]. |
|
3458 |
||
3459 |
" |
|
3460 |
'/tmp/link' asFilename createAsHardLinkTo:'bla' |
|
3461 |
" |
|
3462 |
! |
|
3463 |
||
17143 | 3464 |
createAsSymbolicLinkTo:linkFilenameString |
23057 | 3465 |
"create a symbolic link named linkFilenameString which points to me |
17143 | 3466 |
Raises an exception if not successful" |
3467 |
||
21064 | 3468 |
|errorHolder| |
3469 |
||
3470 |
errorHolder := OperatingSystem createSymbolicLinkFrom:linkFilenameString asFilename osName to:self osName. |
|
3471 |
errorHolder notNil ifTrue:[ |
|
3472 |
errorHolder reportError:'symbolic link failed'. |
|
3473 |
]. |
|
3474 |
||
3475 |
" |
|
3476 |
'/tmp/link' asFilename createAsSymbolicLinkTo:'bla' |
|
17143 | 3477 |
" |
23057 | 3478 |
|
3479 |
"Modified (comment): / 07-06-2018 / 17:16:01 / Claus Gittinger" |
|
17143 | 3480 |
! |
3481 |
||
615 | 3482 |
makeDirectory |
19440 | 3483 |
"create a directory with the receiver's name. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3484 |
Raises an exception if not successful" |
615 | 3485 |
|
21064 | 3486 |
|osErrorHolder| |
3487 |
||
3488 |
osErrorHolder := OperatingSystem createDirectory:(self osNameForDirectory). |
|
3489 |
osErrorHolder notNil ifTrue:[ |
|
3490 |
"/ |
|
3491 |
"/ could have existed before ... |
|
3492 |
"/ |
|
3493 |
(self exists and:[self isDirectory]) ifFalse:[ |
|
3494 |
osErrorHolder reportProceedableError:'make directory failed'. |
|
3495 |
] |
|
3496 |
]. |
|
3497 |
^ nil |
|
1970 | 3498 |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3499 |
"Modified: / 5.5.1999 / 13:36:33 / cg" |
615 | 3500 |
! |
3501 |
||
6996
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3502 |
moveFileTo:newName |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3503 |
"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
|
3504 |
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
|
3505 |
Raise an exception if not successful. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3506 |
(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
|
3507 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3508 |
[self renameTo:newName] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3509 |
on:OsError |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3510 |
do:[:ex | |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3511 |
ex creator == OperatingSystem fileNotFoundErrorSignal ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3512 |
ex reject |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3513 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3514 |
self safeCopyTo:newName. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3515 |
self remove |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3516 |
]. |
6996
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3517 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3518 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3519 |
|f s| |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3520 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3521 |
f := '/tmp/foo' asFilename. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3522 |
s := f writeStream. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3523 |
s nextPutLine:'hello'. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3524 |
s close. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3525 |
f renameTo:'./foo' |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3526 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3527 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3528 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3529 |
|f s| |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3530 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3531 |
f := '/tmp/foo' asFilename. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3532 |
s := f writeStream. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3533 |
s nextPutLine:'hello'. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3534 |
s close. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3535 |
f moveTo:'./foo' |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3536 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3537 |
! |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3538 |
|
16490 | 3539 |
moveTo:newNameArg |
615 | 3540 |
"copy the file represented by the receiver, then delete it. |
3541 |
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
|
3542 |
Raise an exception if not successful. |
3d801043be3f
dont read the whole directory in #directoryContentsDo:
Claus Gittinger <cg@exept.de>
parents:
5577
diff
changeset
|
3543 |
(Notice, that a rename is tried first, in case of non-cross device move)" |
615 | 3544 |
|
16490 | 3545 |
|newName| |
3546 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3547 |
newName := newNameArg asFilename. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3548 |
[self renameTo:newName] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3549 |
on:(OSErrorHolder inappropriateReferentSignal) |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3550 |
do:[:ex | |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3551 |
"handle renames accross device boundaries (Unix. cross device link)" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3552 |
self isDirectory ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3553 |
self recursiveMoveDirectoryTo:newName. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3554 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3555 |
self safeCopyTo:newName. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3556 |
self remove. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3557 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3558 |
]. |
5507
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3559 |
|
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3560 |
" |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3561 |
|f s| |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3562 |
|
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3563 |
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
|
3564 |
s := f writeStream. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3565 |
s nextPutLine:'hello'. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3566 |
s close. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3567 |
f renameTo:'./foo' |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3568 |
" |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3569 |
|
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3570 |
" |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3571 |
|f s| |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3572 |
|
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3573 |
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
|
3574 |
s := f writeStream. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3575 |
s nextPutLine:'hello'. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3576 |
s close. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3577 |
f moveTo:'./foo' |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3578 |
" |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3579 |
! |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3580 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3581 |
recursiveCopyTo:destination |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3582 |
"if I represent a regular file, copy it. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3583 |
Otherwise, copy the directory and recursively |
12975 | 3584 |
all of its subfiles/subdirectories. |
17143 | 3585 |
|
3586 |
Raises an exception if not successful. |
|
3587 |
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
|
3588 |
If a whole directory is to be copied and the destination directory |
17143 | 3589 |
does not exist, it will be created." |
3590 |
||
3591 |
|ok destinationFilename| |
|
3592 |
||
3593 |
destinationFilename := destination asFilename. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3594 |
self isDirectory ifFalse:[ |
19599 | 3595 |
destinationFilename isDirectory ifTrue:[ |
3596 |
destinationFilename := destinationFilename construct:self baseName. |
|
3597 |
]. |
|
3598 |
self copyTo:destinationFilename. |
|
3599 |
^ self. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3600 |
]. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3601 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3602 |
"/ typically, an 'cp -r' is faster; |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3603 |
"/ 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
|
3604 |
"/ fallBack doing a manual directory walk. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3605 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3606 |
ok := OperatingSystem |
19599 | 3607 |
recursiveCopyDirectory:(self osNameForDirectory) |
3608 |
to:(destinationFilename osNameForDirectory). |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3609 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3610 |
ok ifFalse:[ |
19599 | 3611 |
self recursiveCopyWithoutOSCommandTo:destinationFilename |
3612 |
]. |
|
3613 |
||
3614 |
" |
|
3615 |
'.' asFilename recursiveCopyTo:'/temp/xxx'. |
|
17143 | 3616 |
" |
3617 |
||
12975 | 3618 |
"Created: / 05-05-1999 / 13:35:01 / cg" |
3619 |
"Modified: / 31-05-1999 / 13:11:34 / cg" |
|
3620 |
"Modified: / 29-07-2010 / 12:41:06 / sr" |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3621 |
! |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3622 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3623 |
recursiveCopyWithoutOSCommandTo:destination |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3624 |
"if I represent a regular file, copy it. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3625 |
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
|
3626 |
This one walks down the directory hierarchy, not using any OS command to do the copy. |
17143 | 3627 |
Raises an exception if not successful. |
3628 |
||
3629 |
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
|
3630 |
If a whole directory is to be copied and the destination directory |
17143 | 3631 |
does not exist, it will be created." |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3632 |
|
12529 | 3633 |
|destinationFilename| |
3634 |
||
3635 |
destinationFilename := destination asFilename. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3636 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3637 |
self isDirectory ifTrue:[ |
21064 | 3638 |
destinationFilename exists ifFalse:[ |
3639 |
destinationFilename makeDirectory. |
|
3640 |
OsError catch:[ |
|
3641 |
destinationFilename accessRights:self accessRights. |
|
3642 |
]. |
|
3643 |
]. |
|
3644 |
||
3645 |
self directoryContentsDo:[:aFilenameString | |
|
3646 |
|src srcInfo dst info| |
|
3647 |
||
3648 |
src := self construct:aFilenameString. |
|
3649 |
dst := destinationFilename construct:aFilenameString. |
|
3650 |
||
3651 |
srcInfo := src linkInfo. |
|
3652 |
srcInfo isDirectory ifTrue:[ |
|
3653 |
src recursiveCopyWithoutOSCommandTo:dst |
|
3654 |
] ifFalse:[srcInfo isSymbolicLink ifTrue:[ |
|
3655 |
dst |
|
3656 |
remove; |
|
3657 |
createAsSymbolicLinkTo:srcInfo path. |
|
3658 |
] ifFalse:[ |
|
3659 |
src copyTo:dst. |
|
3660 |
]]. |
|
3661 |
]. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3662 |
] ifFalse:[ |
21064 | 3663 |
destinationFilename isDirectory ifTrue:[ |
3664 |
destinationFilename := destinationFilename construct:self baseName. |
|
3665 |
]. |
|
3666 |
self copyTo:destinationFilename. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3667 |
] |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3668 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3669 |
" |
18952 | 3670 |
'.' asFilename recursiveCopyWithoutOSCommandTo:'/temp/xxx'. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3671 |
'smalltalk.rc' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3672 |
" |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3673 |
|
4246 | 3674 |
"Modified: / 31.5.1999 / 18:12:31 / cg" |
615 | 3675 |
! |
3676 |
||
659 | 3677 |
recursiveMakeDirectory |
18490 | 3678 |
"create a directory with the receiver's name and all required intermediate |
659 | 3679 |
directories. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3680 |
Raises an exception if not successful." |
659 | 3681 |
|
21064 | 3682 |
|osErrorHolder| |
3683 |
||
3684 |
osErrorHolder := OperatingSystem recursiveCreateDirectory:(self osNameForDirectory). |
|
3685 |
osErrorHolder notNil ifTrue:[ |
|
3686 |
osErrorHolder reportProceedableError:'recursive makedir failed'. |
|
3687 |
]. |
|
3688 |
||
3689 |
" |
|
3690 |
'k:\bla\quark' asFilename recursiveMakeDirectory |
|
3691 |
" |
|
659 | 3692 |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3693 |
"Created: / 27.11.1995 / 23:36:40 / cg" |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3694 |
"Modified: / 5.5.1999 / 13:38:42 / cg" |
21064 | 3695 |
|
3696 |
" |
|
3697 |
'C:\windows\bla\xx' asFilename recursiveMakeDirectory |
|
3698 |
'C:\windows\bla' asFilename recursiveRemoveAll |
|
3699 |
" |
|
659 | 3700 |
! |
3701 |
||
6997 | 3702 |
recursiveMoveDirectoryTo:newName |
3703 |
"recursively copy the directory represented by the receiver, then delete it. |
|
3704 |
This is different to renaming in case of cross device moves. |
|
3705 |
Raise an exception if not successful. |
|
3706 |
(Notice, that a rename is tried first, in case of non-cross device move)" |
|
3707 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3708 |
[self renameTo:newName] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3709 |
on:OsError |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3710 |
do:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3711 |
self recursiveCopyTo:newName. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3712 |
self recursiveRemove |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3713 |
]. |
6997 | 3714 |
! |
3715 |
||
615 | 3716 |
recursiveRemove |
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
3717 |
"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
|
3718 |
Otherwise, remove the directory and all of its subfiles/subdirectories. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3719 |
Raise an exception if not successful." |
615 | 3720 |
|
3721 |
|ok| |
|
3722 |
||
3302 | 3723 |
"/ 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
|
3724 |
"/ 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
|
3725 |
"/ fallBack doing a manual directory walk. |
3302 | 3726 |
|
3727 |
ok := OperatingSystem recursiveRemoveDirectory:(self osNameForDirectory). |
|
3728 |
ok ifFalse:[ |
|
19599 | 3729 |
self recursiveRemoveWithoutOSCommand |
18952 | 3730 |
]. |
3731 |
||
3732 |
" |
|
3733 |
'foo/bar' asFilename recursiveMakeDirectory. |
|
3734 |
'foo' asFilename remove. |
|
3735 |
self assert:('foo' asFilename exists not). |
|
3736 |
||
3737 |
||
3738 |
'foo' asFilename recursiveRemove. |
|
3739 |
'foo/bar' asFilename recursiveMakeDirectory. |
|
3740 |
'foo' asFilename recursiveRemove. |
|
3741 |
self assert:('foo' asFilename exists not). |
|
3302 | 3742 |
" |
3743 |
||
3744 |
"Created: / 14.11.1995 / 11:19:29 / cg" |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3745 |
"Modified: / 5.5.1999 / 13:43:35 / cg" |
3302 | 3746 |
! |
3747 |
||
13246 | 3748 |
recursiveRemoveAll |
13247
9e47a0e73ba4
comment/format in: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents:
13246
diff
changeset
|
3749 |
"Remove all of my subfiles/subdirectories. |
3302 | 3750 |
Raise an error if not successful. |
3751 |
This one walks down the directory hierarchy, not using any OS |
|
3752 |
command to do the remove." |
|
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
3753 |
|
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
3754 |
self isDirectory ifTrue:[ |
21064 | 3755 |
self directoryContentsAsFilenamesDo:[:eachFilename | |
3756 |
OsError handle:[:ex | |
|
3757 |
eachFilename isDirectory ifFalse:[ ex reject ]. |
|
3758 |
eachFilename |
|
3759 |
recursiveRemoveAll; |
|
3760 |
removeDirectory. |
|
3761 |
] do:[ |
|
3762 |
eachFilename remove |
|
3763 |
]. |
|
18952 | 3764 |
|
3765 |
"/ eachFilename isDirectory ifTrue:[ |
|
3766 |
"/ eachFilename recursiveRemoveWithoutOSCommand |
|
3767 |
"/ ] ifFalse:[ |
|
3768 |
"/ eachFilename remove |
|
3769 |
"/ ]. |
|
21064 | 3770 |
] |
615 | 3771 |
]. |
13246 | 3772 |
|
3773 |
" |
|
3774 |
'foo' asFilename makeDirectory. |
|
3775 |
'foo/bar' asFilename writeStream close. |
|
3776 |
'foo' asFilename remove |
|
3777 |
" |
|
3778 |
" |
|
3779 |
'foo' asFilename makeDirectory. |
|
3780 |
'foo/bar' asFilename writeStream close. |
|
18952 | 3781 |
'foo' asFilename recursiveRemove. |
3782 |
self assert:('foo' asFilename exists not). |
|
13246 | 3783 |
" |
3784 |
||
3785 |
"Created: / 25-01-2011 / 16:42:15 / cg" |
|
3786 |
! |
|
3787 |
||
3788 |
recursiveRemoveWithoutOSCommand |
|
3789 |
"if I represent a regular file, remove it. |
|
3790 |
Otherwise, remove the directory and all of its subfiles/subdirectories. |
|
3791 |
Raise an error if not successful. |
|
3792 |
This one walks down the directory hierarchy, not using any OS |
|
3793 |
command to do the remove." |
|
3794 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3795 |
self |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3796 |
recursiveRemoveAll; |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3797 |
remove. |
615 | 3798 |
|
3799 |
" |
|
3800 |
'foo' asFilename makeDirectory. |
|
3801 |
'foo/bar' asFilename writeStream close. |
|
4940 | 3802 |
'foo' asFilename remove |
615 | 3803 |
" |
3804 |
" |
|
3805 |
'foo' asFilename makeDirectory. |
|
3806 |
'foo/bar' asFilename writeStream close. |
|
4940 | 3807 |
'foo' asFilename recursiveRemove |
615 | 3808 |
" |
3809 |
||
13246 | 3810 |
"Created: / 25-02-1998 / 19:50:40 / cg" |
13949 | 3811 |
"Modified: / 19-01-2012 / 17:18:28 / cg" |
615 | 3812 |
! |
3813 |
||
3814 |
remove |
|
845 | 3815 |
"remove the file/directory. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3816 |
Raises an exception if not successful. |
845 | 3817 |
Use #recursiveRemove in order to (recursively) remove non empty directories." |
615 | 3818 |
|
21064 | 3819 |
|linkInfo osName osErrorHolder| |
8741 | 3820 |
|
18952 | 3821 |
osName := self osNameForAccess. |
21064 | 3822 |
osErrorHolder := OperatingSystem removeFile:osName. |
3823 |
osErrorHolder notNil ifTrue:[ |
|
3824 |
linkInfo := self linkInfo. |
|
3825 |
linkInfo isNil ifTrue:[ |
|
3826 |
"file does not exist - no error" |
|
3827 |
^ self. |
|
3828 |
] ifFalse:[linkInfo isDirectory ifTrue:[ |
|
3829 |
osErrorHolder := OperatingSystem removeDirectory:osName |
|
3830 |
]]. |
|
3831 |
osErrorHolder notNil ifTrue:[ |
|
3832 |
self exists ifTrue:[ |
|
3833 |
osErrorHolder reportProceedableError:'remove failed'. |
|
3834 |
] |
|
3835 |
] |
|
615 | 3836 |
]. |
3837 |
||
3838 |
" |
|
3839 |
(FileStream newFileNamed:'foo') close. |
|
3840 |
'foo' asFilename remove |
|
3841 |
" |
|
3842 |
||
3843 |
" |
|
3844 |
'foo' asFilename makeDirectory. |
|
3845 |
'foo/bar' asFilename writeStream close. |
|
8738 | 3846 |
'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
|
3847 |
'foo' asFilename recursiveRemove. |
615 | 3848 |
" |
3849 |
||
13793
3f1c660956ce
added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents:
13781
diff
changeset
|
3850 |
"Modified: / 20-11-1997 / 17:40:22 / stefan" |
3f1c660956ce
added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents:
13781
diff
changeset
|
3851 |
"Modified: / 11-10-2011 / 10:20:01 / cg" |
615 | 3852 |
! |
3853 |
||
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3854 |
removeDirectory |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3855 |
"remove the directory. |
21441 | 3856 |
Raises an exception if not successful (or if it's not a directory). |
5596 | 3857 |
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
|
3858 |
Use #recursiveRemove in order to (recursively) remove non empty directories." |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3859 |
|
21064 | 3860 |
|osErrorHolder| |
3861 |
||
3862 |
osErrorHolder := OperatingSystem removeDirectory:self osNameForAccess. |
|
3863 |
osErrorHolder notNil ifTrue:[ |
|
3864 |
self exists ifTrue:[ |
|
3865 |
osErrorHolder reportProceedableError:'remove directory failed'. |
|
3866 |
]. |
|
3867 |
]. |
|
3868 |
||
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3869 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3870 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3871 |
(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
|
3872 |
'foo' asFilename removeDirectory |
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3873 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3874 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3875 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3876 |
'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
|
3877 |
'foo' asFilename removeDirectory |
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3878 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3879 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3880 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3881 |
'foo' asFilename makeDirectory. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3882 |
'foo/bar' asFilename writeStream close. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3883 |
('foo' asFilename remove) ifFalse:[ |
21064 | 3884 |
Transcript showCR:'could not remove foo' |
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3885 |
] |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3886 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3887 |
|
21441 | 3888 |
"Modified: / 20-11-1997 / 17:40:22 / stefan" |
3889 |
"Modified: / 05-05-1999 / 13:41:12 / cg" |
|
3890 |
"Modified (comment): / 13-02-2017 / 20:19:10 / cg" |
|
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3891 |
! |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3892 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3893 |
removeFile |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3894 |
"remove the file. |
21441 | 3895 |
Raises an exception if not successful (or if it's not a file). |
5596 | 3896 |
Use #remove if it is not known if the receiver is a directory or file. |
3897 |
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
|
3898 |
|
21064 | 3899 |
|osErrorHolder| |
3900 |
||
3901 |
osErrorHolder := OperatingSystem removeFile:self osNameForAccess. |
|
3902 |
osErrorHolder notNil ifTrue:[ |
|
3903 |
self exists ifTrue:[ |
|
3904 |
osErrorHolder reportProceedableError:'remove of file failed'. |
|
3905 |
]. |
|
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3906 |
]. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3907 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3908 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3909 |
(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
|
3910 |
'foo' asFilename removeFile |
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3911 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3912 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3913 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3914 |
'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
|
3915 |
'foo' asFilename removeFile |
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3916 |
" |
21441 | 3917 |
|
3918 |
"Modified (comment): / 13-02-2017 / 20:19:15 / cg" |
|
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3919 |
! |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3920 |
|
21045 | 3921 |
renameTo:newName |
22503 | 3922 |
"rename the file - the argument must be convertable to a filename. |
15823 | 3923 |
Raises an exception if not successful. |
3924 |
If newName already exists, it will be replaced by myself." |
|
615 | 3925 |
|
21045 | 3926 |
|errorHolder| |
3927 |
||
3928 |
errorHolder := OperatingSystem |
|
3929 |
renameFile:(self osNameForFile) |
|
3930 |
to:(newName asFilename osNameForFile). |
|
3931 |
||
3932 |
errorHolder notNil ifTrue:[ |
|
3933 |
errorHolder |
|
3934 |
parameter:self; |
|
21064 | 3935 |
reportProceedableError:'rename failed'. |
615 | 3936 |
]. |
3937 |
||
3938 |
" |
|
3939 |
'/tmp/foo' asFilename renameTo:'/tmp/bar' |
|
21045 | 3940 |
'/tmp/' asFilename renameTo:'/etc/bar' |
21023 | 3941 |
'C:\windows' asFilename renameTo:'C:\win' |
615 | 3942 |
" |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3943 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3944 |
"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
|
3945 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3946 |
|
15819 | 3947 |
safeCopyTo:newNameArg |
16578 | 3948 |
"Copy the file's contents into another file. |
22542 | 3949 |
Do it safe in an atomic operation which makes sure that no partially written file appears. |
15819 | 3950 |
The argument must be convertable to a filename. |
3951 |
Raises an exception, if an error occurs." |
|
3952 |
||
15823 | 3953 |
|newName inStream accessRights tempStream| |
15819 | 3954 |
|
3955 |
newName := newNameArg asFilename. |
|
3956 |
||
3957 |
"Contents is not copied if newName represent same file as me." |
|
3958 |
newName asAbsoluteFilename = self asAbsoluteFilename ifTrue: [ ^ self ]. |
|
3959 |
||
3960 |
inStream := self readStream. |
|
15823 | 3961 |
newName exists ifTrue:[ |
20252 | 3962 |
accessRights := newName accessRights. |
15819 | 3963 |
] ifFalse:[ |
20252 | 3964 |
accessRights := self accessRights. |
15819 | 3965 |
]. |
3966 |
||
3967 |
[ |
|
20252 | 3968 |
"let the temp filename start with a ~ to make it invisible" |
3969 |
tempStream := FileStream newTemporaryIn:newName directory osNameForFile nameTemplate:'~%1_%2'. |
|
21064 | 3970 |
"ignore the error - may occur when copying to a network drive" |
3971 |
OsError catch:[ |
|
20252 | 3972 |
"would be nice to keep the access rights of the original file" |
3973 |
tempStream fileName accessRights:accessRights. |
|
3974 |
]. |
|
3975 |
||
3976 |
inStream binary; buffered:false. |
|
3977 |
tempStream binary; buffered:false. |
|
3978 |
[ |
|
3979 |
inStream copyToEndInto:tempStream. |
|
3980 |
] ifCurtailed:[ |
|
3981 |
tempStream close. |
|
3982 |
tempStream fileName remove. |
|
3983 |
tempStream := nil. |
|
3984 |
]. |
|
3985 |
tempStream syncData. |
|
15819 | 3986 |
] ensure:[ |
20252 | 3987 |
inStream close. |
3988 |
tempStream notNil ifTrue:[tempStream close]. |
|
15819 | 3989 |
]. |
3990 |
tempStream fileName renameTo:newName. |
|
3991 |
||
3992 |
" |
|
3993 |
'Make.proto' asFilename safeCopyTo:'/tmp/Makefile.foo' |
|
3994 |
'Make.proto' asFilename safeCopyTo:'/' |
|
3995 |
'smalltalk' asFilename safeCopyTo:'/xxxxxxxxxxxxxxxx/bla' |
|
3996 |
" |
|
3997 |
||
3998 |
"Modified: / 10-09-2004 / 09:49:28 / janfrog" |
|
3999 |
"Modified: / 29-09-2006 / 16:26:32 / cg" |
|
22542 | 4000 |
"Modified (comment): / 13-02-2018 / 11:59:48 / mawalch" |
15819 | 4001 |
! |
4002 |
||
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4003 |
truncateTo:newSize |
16578 | 4004 |
"change the file's size. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
4005 |
This may not be supported on all operating systems |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
4006 |
(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
|
4007 |
|
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
4008 |
(OperatingSystem truncateFile:self osNameForFile to:newSize) ifFalse:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4009 |
^ 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
|
4010 |
] |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4011 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4012 |
" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4013 |
|s| |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4014 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4015 |
s := 'test' asFilename writeStream. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4016 |
s next:1000 put:$1. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4017 |
s close. |
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
4018 |
('test' asFilename fileSize) printCR. |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4019 |
'test' asFilename truncateTo:100. |
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
4020 |
('test' asFilename fileSize) printCR. |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
4021 |
" |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
4022 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
4023 |
"Modified: / 5.5.1999 / 13:41:59 / cg" |
615 | 4024 |
! ! |
4025 |
||
4026 |
!Filename methodsFor:'file queries'! |
|
4027 |
||
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4028 |
accessTime |
16578 | 4029 |
"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
|
4030 |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4031 |
| i | |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4032 |
|
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4033 |
(i := self info) isNil ifTrue:[^ nil]. |
6793
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
4034 |
^ i accessTime |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4035 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4036 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4037 |
Filename currentDirectory accessTime |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4038 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4039 |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4040 |
"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
|
4041 |
"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
|
4042 |
"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
|
4043 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4044 |
|
6977 | 4045 |
creationTime |
16578 | 4046 |
"return a timeStamp containing the file's creation time. |
6977 | 4047 |
NOTICE: only windoof distinguishes creation from modification; |
6978 | 4048 |
under unix, nil is returned (callers should fall back and use mod-time then" |
6977 | 4049 |
|
4050 |
|i| |
|
4051 |
||
4052 |
(i := self info) isNil ifTrue:[^ nil]. "/ non-existing |
|
6978 | 4053 |
^ i creationTime |
4054 |
||
4055 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4056 |
Filename currentDirectory creationTime |
6977 | 4057 |
" |
4058 |
||
4059 |
"Created: / 9.7.1996 / 10:18:59 / cg" |
|
4060 |
"Modified: / 26.9.1997 / 13:05:39 / stefan" |
|
4061 |
"Modified: / 14.8.1998 / 17:42:50 / cg" |
|
4062 |
! |
|
4063 |
||
615 | 4064 |
dates |
16578 | 4065 |
"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
|
4066 |
that responds to the at: message with arguments |
615 | 4067 |
#modified, #accessed or #statusChanged." |
4068 |
||
2922 | 4069 |
|info dates osName| |
4070 |
||
2947 | 4071 |
osName := self osNameForAccess. |
2922 | 4072 |
info := OperatingSystem infoOf:osName. |
615 | 4073 |
info isNil ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4074 |
"maybe this is a symbolic link with a broken link target. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4075 |
Answer the dates of the link itself" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4076 |
info := OperatingSystem linkInfoOf:osName. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4077 |
info isNil ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4078 |
^ nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4079 |
] |
615 | 4080 |
]. |
4081 |
dates := IdentityDictionary new. |
|
6978 | 4082 |
dates at:#created put:(info creationTime). |
6793
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
4083 |
dates at:#modified put:(info modificationTime). |
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
4084 |
dates at:#accessed put:(info accessTime). |
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
4085 |
dates at:#statusChanged put:(info statusChangeTime). |
615 | 4086 |
^ dates |
4087 |
||
4088 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4089 |
Filename currentDirectory dates |
615 | 4090 |
'../regression' asFilename dates |
4091 |
" |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4092 |
|
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4093 |
"Modified: 1.11.1996 / 20:19:24 / cg" |
615 | 4094 |
! |
4095 |
||
4096 |
fileSize |
|
4097 |
"return the size of the file in bytes" |
|
4098 |
||
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4099 |
|i| |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4100 |
|
22395 | 4101 |
(i := self info) isNil ifTrue:[^ 0]. |
6794
498d85323172
use #fileSize instead of #size
Claus Gittinger <cg@exept.de>
parents:
6793
diff
changeset
|
4102 |
^ i fileSize |
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4103 |
|
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4104 |
"Modified: / 17.8.1998 / 10:23:46 / cg" |
615 | 4105 |
! |
4106 |
||
4107 |
fileType |
|
4108 |
"this returns a string describing the type of contents of |
|
4109 |
the file. This is done using the unix 'file' command, |
|
4110 |
(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
|
4111 |
On non-unix systems, this may simply return 'file', |
2922 | 4112 |
not knowning about the contents. |
4113 |
Warning: |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4114 |
Since the returned string differs among systems (and language settings), |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4115 |
it is only useful for user-information; |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4116 |
NOT as a tag to be used by a program." |
3665 | 4117 |
|
16755 | 4118 |
|suffix baseNm info mime| |
3665 | 4119 |
|
4120 |
"/ 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
|
4121 |
"/ do the most obvious ones here. |
3665 | 4122 |
"/ (also useful since the 'file' command takes some time, and the code |
4123 |
"/ 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
|
4124 |
|
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4125 |
info := self linkInfo. |
9060 | 4126 |
info isNil ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4127 |
^ 'removed' "/ could happen, when coming from a snapshot image |
9060 | 4128 |
]. |
4129 |
||
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4130 |
info isSymbolicLink ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4131 |
^ 'symbolic link to ' , info path |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
4132 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4133 |
info isDirectory ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4134 |
self isReadable ifFalse:[^ 'directory, unreadable']. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4135 |
self isExecutable ifFalse:[^ 'directory, locked']. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4136 |
^ 'directory' |
2573 | 4137 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4138 |
info isCharacterSpecial ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4139 |
^ 'character device special file' |
3665 | 4140 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4141 |
info isBlockSpecial ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4142 |
^ 'block device special file' |
3665 | 4143 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4144 |
info isSocket ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4145 |
^ 'socket' |
3665 | 4146 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4147 |
info isFifo ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4148 |
^ '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
|
4149 |
]. |
3665 | 4150 |
|
1602 | 4151 |
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
|
4152 |
info fileSize == 0 ifTrue:[^ 'empty']. |
1602 | 4153 |
|
17112 | 4154 |
"/ suffix := self suffix asLowercase. |
4155 |
"/ baseNm := self withoutSuffix baseName asLowercase. |
|
2922 | 4156 |
|
16755 | 4157 |
mime := self mimeTypeOfContents. |
4158 |
mime notNil ifTrue:[ |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4159 |
"/ kludge to avoid making libview a prereq. of libbasic |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4160 |
(Smalltalk at:#MIMETypes) notNil ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4161 |
info := (Smalltalk at:#MIMETypes) fileInfoForMimeType:mime. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4162 |
info notNil ifTrue:[^ info]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4163 |
]. |
1602 | 4164 |
]. |
2906 | 4165 |
^ 'file' |
615 | 4166 |
|
4167 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4168 |
'Makefile' asFilename fileType |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4169 |
'.' asFilename fileType |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4170 |
'/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
|
4171 |
'/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
|
4172 |
'/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
|
4173 |
'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
|
4174 |
'bitmaps/SBrowser.xbm' asFilename fileType |
615 | 4175 |
" |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
4176 |
|
3665 | 4177 |
"Modified: / 21.7.1998 / 11:25:56 / cg" |
615 | 4178 |
! |
4179 |
||
2836 | 4180 |
id |
16578 | 4181 |
"return the file's/directory's file-id (inode number)" |
2836 | 4182 |
|
2947 | 4183 |
^ OperatingSystem idOf:(self osNameForAccess) |
2836 | 4184 |
|
4185 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4186 |
Filename currentDirectory id |
2836 | 4187 |
" |
4188 |
||
4189 |
"Modified: 9.7.1996 / 10:19:27 / cg" |
|
4190 |
"Created: 5.8.1997 / 19:26:01 / cg" |
|
4191 |
! |
|
4192 |
||
615 | 4193 |
info |
16578 | 4194 |
"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
|
4195 |
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
|
4196 |
the returned object) is: |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4197 |
|
22401 | 4198 |
type - a symbol giving the files fileType |
4199 |
mode - numeric access mode |
|
4200 |
uid - owners user id |
|
4201 |
gid - owners group id |
|
4202 |
fileSize - files size |
|
4203 |
id - files number (i.e. inode number) |
|
20798 | 4204 |
accessed - last access time (as osTime-stamp) |
4205 |
modified - last modification time (as osTime-stamp) |
|
23152 | 4206 |
statusChangeTime - last status change (as osTime-stamp) |
615 | 4207 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4208 |
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
|
4209 |
all of the information. |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4210 |
The minimum returned info (i.e. on all OS's) will consist of at least: |
20798 | 4211 |
modified |
4212 |
size |
|
4213 |
type |
|
4214 |
||
4215 |
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
|
4216 |
to either handle nil values, |
615 | 4217 |
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
|
4218 |
(i.e. instead of: |
20798 | 4219 |
someFilename type == #directory |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4220 |
use |
20798 | 4221 |
someFilename isDirectory |
615 | 4222 |
" |
4223 |
||
2947 | 4224 |
^ OperatingSystem infoOf:(self osNameForAccess) |
615 | 4225 |
|
4226 |
" |
|
4227 |
Filename currentDirectory info |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4228 |
'/dev/null' asFilename info |
615 | 4229 |
'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
|
4230 |
'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
|
4231 |
'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
|
4232 |
'../../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
|
4233 |
'.' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4234 |
'..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4235 |
'..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4236 |
'..\..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4237 |
'..\..\..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4238 |
'c:\' asFilename info |
615 | 4239 |
" |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4240 |
|
16272 | 4241 |
"Modified: / 17-08-1998 / 10:24:10 / cg" |
4242 |
"Modified (comment): / 21-03-2014 / 00:35:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
23152 | 4243 |
"Modified (comment): / 29-06-2018 / 09:54:46 / Claus Gittinger" |
615 | 4244 |
! |
4245 |
||
4246 |
linkInfo |
|
16578 | 4247 |
"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
|
4248 |
instead of the link's target. |
615 | 4249 |
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
|
4250 |
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
|
4251 |
is returned |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4252 |
(while in this case, #info returns the info of the target file, |
615 | 4253 |
which is accessed via the symbolic link). |
4254 |
||
4255 |
In addition to the normal entries, Unix returns an additional entry: |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4256 |
path -> the target files pathname |
615 | 4257 |
|
4258 |
See the comment in #info for more details." |
|
4259 |
||
2947 | 4260 |
^ OperatingSystem linkInfoOf:(self osNameForAccess) |
615 | 4261 |
|
4262 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4263 |
Filename currentDirectory linkInfo |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4264 |
'/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
|
4265 |
'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
|
4266 |
'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
|
4267 |
'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
|
4268 |
'../../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
|
4269 |
'/usr/tmp' asFilename linkInfo |
615 | 4270 |
" |
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
4271 |
|
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
4272 |
"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
|
4273 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4274 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4275 |
modificationTime |
16578 | 4276 |
"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
|
4277 |
|
3763
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
4278 |
|i| |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
4279 |
|
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
4280 |
(i := self info) isNil ifTrue:[^ nil]. "/ non-existing |
6793
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
4281 |
^ i modificationTime |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4282 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4283 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4284 |
Filename currentDirectory modificationTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4285 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4286 |
|
3763
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
4287 |
"Created: / 9.7.1996 / 10:18:59 / cg" |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
4288 |
"Modified: / 26.9.1997 / 13:05:39 / stefan" |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
4289 |
"Modified: / 14.8.1998 / 17:42:50 / cg" |
2836 | 4290 |
! |
4291 |
||
4292 |
type |
|
4293 |
"return the symbolic type of the file" |
|
4294 |
||
2947 | 4295 |
^ OperatingSystem typeOf:(self osNameForAccess) |
2836 | 4296 |
|
4297 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4298 |
Filename currentDirectory type |
2836 | 4299 |
" |
4300 |
||
4301 |
"Modified: 9.7.1996 / 10:19:27 / cg" |
|
4302 |
"Created: 5.8.1997 / 19:31:26 / cg" |
|
615 | 4303 |
! ! |
4304 |
||
4305 |
!Filename methodsFor:'file utilities'! |
|
4306 |
||
4307 |
edit |
|
4308 |
"start an editView on the file represented by the receiver" |
|
4309 |
||
4310 |
EditTextView openOn:self asString |
|
4311 |
||
4312 |
" |
|
4313 |
'smalltalk.rc' asFilename edit |
|
4314 |
" |
|
4315 |
! |
|
4316 |
||
4317 |
fileIn |
|
13424 | 4318 |
"load source code from the file" |
4319 |
||
4320 |
^ (ProgrammingLanguage forFile: self) fileIn: self |
|
4321 |
||
4322 |
"Modified: / 16-08-2009 / 13:27:36 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
542 | 4323 |
! ! |
4324 |
||
2 | 4325 |
!Filename methodsFor:'instance creation'! |
4326 |
||
10969
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4327 |
/ subname |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4328 |
"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
|
4329 |
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
|
4330 |
(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
|
4331 |
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
|
4332 |
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
|
4333 |
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
|
4334 |
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
|
4335 |
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
|
4336 |
|
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4337 |
^ 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
|
4338 |
|
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4339 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4340 |
'/tmp' asFilename / 'foo' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4341 |
'/' 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
|
4342 |
'/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
|
4343 |
|
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4344 |
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
|
4345 |
'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
|
4346 |
" |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4347 |
! |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4348 |
|
615 | 4349 |
construct:subname |
4350 |
"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
|
4351 |
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
|
4352 |
(i.e. for a file or a subdirectory in that directory). |
2922 | 4353 |
The argument may not specify an absolute path name. |
4354 |
Please do not use this to create filenames with suffixes, |
|
4355 |
since some systems require special naming conventions. |
|
4356 |
See also: #withSuffix: (which is different, but often needed)." |
|
615 | 4357 |
|
11784 | 4358 |
|constructedName| |
4359 |
||
4360 |
constructedName := self constructString:subname. |
|
15811 | 4361 |
^ self species named:constructedName. |
615 | 4362 |
|
4363 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4364 |
'/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
|
4365 |
'/' asFilename construct:'foo' |
615 | 4366 |
'/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
|
4367 |
'/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
|
4368 |
'/foo/bar' asFilename construct:'baz' asFilename |
2922 | 4369 |
|
4370 |
Bad example; works on UNIX, but may not on others: |
|
11784 | 4371 |
'foo/bar.baz' asFilename construct:'.suff' |
615 | 4372 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4373 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4374 |
"Modified: 29.2.1996 / 20:55:06 / cg" |
2911 | 4375 |
! |
4376 |
||
2922 | 4377 |
constructDirectory:subname |
4378 |
"same as #construct: on most systems. |
|
4379 |
(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
|
4380 |
|
15811 | 4381 |
^ self species named:(self constructDirectoryString:subname) |
2922 | 4382 |
! |
4383 |
||
4384 |
constructDirectoryString:subName |
|
4385 |
"same as #constructString: on most systems. |
|
4386 |
(may allow different/relaxed name syntax of the argument on some systems)" |
|
4387 |
||
4388 |
^ self constructString:subName |
|
4389 |
! |
|
4390 |
||
4391 |
constructString:subName |
|
2911 | 4392 |
"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
|
4393 |
filename-string for an entry within this directory |
2922 | 4394 |
(i.e. for a file or a subdirectory in that directory). |
2960 | 4395 |
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
|
4396 |
The code below works for UNIX & MSDOS; |
2960 | 4397 |
other filename classes (i.e. VMS) may want to redefine this method." |
4398 |
||
4399 |
|sepString sub| |
|
4400 |
||
4401 |
sub := subName asString. |
|
20069 | 4402 |
nameString size == 0 ifTrue:[ |
4403 |
^ sub |
|
4404 |
]. |
|
15811 | 4405 |
sepString := self species separatorString. |
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
4406 |
(nameString endsWith:sepString) ifTrue:[ |
20069 | 4407 |
^ nameString , sub |
6247 | 4408 |
]. |
2960 | 4409 |
^ nameString , sepString , sub |
2911 | 4410 |
|
4411 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4412 |
'/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
|
4413 |
'/' asFilename constructString:'foo' |
2911 | 4414 |
'/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
|
4415 |
'/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
|
4416 |
'' asFilename constructString:'baz' |
2911 | 4417 |
" |
4418 |
||
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
4419 |
"Modified: / 7.9.1995 / 10:15:22 / claus" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
4420 |
"Created: / 9.9.1997 / 08:57:08 / cg" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
4421 |
"Modified: / 20.1.1998 / 15:58:23 / md" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
4422 |
"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
|
4423 |
! |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4424 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4425 |
filenameFor:fileName |
6973 | 4426 |
"return a filename representing the argument, fileName |
4427 |
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
|
4428 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4429 |
|f| |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4430 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4431 |
f := fileName asFilename. |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4432 |
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
|
4433 |
^ (self construct:fileName) |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4434 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4435 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4436 |
'/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
|
4437 |
'/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
|
4438 |
" |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4439 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4440 |
"Created: 18.9.1997 / 14:34:14 / stefan" |
9263 | 4441 |
! |
4442 |
||
4443 |
secureConstruct:subname |
|
4444 |
"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
|
4445 |
filename for an entry within this directory |
9263 | 4446 |
(i.e. for a file or a subdirectory in that directory). |
4447 |
The argument may not specify an absolute path name. |
|
4448 |
Please do not use this to create filenames with suffixes, |
|
4449 |
since some systems require special naming conventions. |
|
4450 |
See also: #withSuffix: (which is different, but often needed). |
|
4451 |
||
4452 |
This method differs from #construct:, by not permitting subName |
|
22927 | 4453 |
to navigate above the current filename (via '..') and is used eg. |
4454 |
by the documentation viewer and other services to prevent remote |
|
4455 |
access outside some predefined root folder." |
|
9263 | 4456 |
|
15811 | 4457 |
^ self species named:(self secureConstructString:subname) |
9263 | 4458 |
|
4459 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4460 |
'/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
|
4461 |
'/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
|
4462 |
'/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
|
4463 |
'/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
|
4464 |
'/' asFilename secureConstruct:'foo' |
9263 | 4465 |
'/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
|
4466 |
'/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
|
4467 |
'/foo/bar' asFilename secureConstruct:'baz' asFilename |
9263 | 4468 |
|
4469 |
Bad example; works on UNIX, but may not on others: |
|
4470 |
'foo/bar.baz' secureConstruct:'.suff' |
|
4471 |
" |
|
4472 |
||
4473 |
"Modified: 29.2.1996 / 20:55:06 / cg" |
|
4474 |
! |
|
4475 |
||
4476 |
secureConstructString:subName |
|
4477 |
"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
|
4478 |
filename-string for an entry within this directory |
9263 | 4479 |
(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
|
4480 |
|
22927 | 4481 |
This method differs from #constructString:, by not permitting subName |
4482 |
to navigate above the current filename (via '..') and is used eg. |
|
4483 |
by the documentation viewer and other services to prevent remote |
|
4484 |
access outside some predefined root folder. |
|
9263 | 4485 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4486 |
The code below works for UNIX & MSDOS; |
22927 | 4487 |
other filename classes (i.e. VMS) have to redefine this method." |
9263 | 4488 |
|
4489 |
|sepString sub normalizedPath pathStream| |
|
4490 |
||
15811 | 4491 |
sepString := self species separatorString. |
9263 | 4492 |
sub := subName asString. |
4493 |
||
4494 |
sub := sub asCollectionOfSubstringsSeparatedByAll:sepString. |
|
4495 |
normalizedPath := OrderedCollection new:sub size. |
|
4496 |
sub do:[:eachPathComponent| |
|
22927 | 4497 |
eachPathComponent = '..' ifTrue:[ |
4498 |
normalizedPath isEmpty ifTrue:[ |
|
4499 |
self error:'secureConstruct: - trying to escape from: ', nameString. |
|
4500 |
]. |
|
4501 |
normalizedPath removeLast. |
|
4502 |
] ifFalse:[(eachPathComponent notEmpty and:[eachPathComponent ~= '.']) ifTrue:[ |
|
4503 |
normalizedPath add:eachPathComponent. |
|
4504 |
]] |
|
9263 | 4505 |
]. |
18272 | 4506 |
pathStream := CharacterWriteStream with:nameString. |
9263 | 4507 |
(nameString notEmpty and:[(nameString endsWith:sepString) not]) ifTrue:[ |
22927 | 4508 |
pathStream nextPutAll:sepString. |
9263 | 4509 |
]. |
4510 |
normalizedPath do:[:eachPathComponent| |
|
22927 | 4511 |
pathStream nextPutAll:eachPathComponent. |
9263 | 4512 |
] separatedBy:[ |
22927 | 4513 |
pathStream nextPutAll:sepString. |
9263 | 4514 |
]. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4515 |
|
9263 | 4516 |
^ pathStream contents. |
4517 |
||
4518 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4519 |
'/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
|
4520 |
'/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
|
4521 |
'/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
|
4522 |
'/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
|
4523 |
'/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
|
4524 |
'/' asFilename secureConstructString:'foo' |
9263 | 4525 |
'/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
|
4526 |
'/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
|
4527 |
'' asFilename secureConstructString:'baz' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4528 |
'' asFilename secureConstructString:'/baz' |
9263 | 4529 |
" |
2 | 4530 |
! ! |
4531 |
||
195 | 4532 |
!Filename methodsFor:'misc'! |
4533 |
||
4534 |
, aString |
|
4535 |
"this allows filenames to understand how names are concatenated. |
|
14072 | 4536 |
Returns a string consisting of the receiver's name, concatenated |
195 | 4537 |
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
|
4538 |
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
|
4539 |
See also: #withSuffix: which is new and better." |
195 | 4540 |
|
5866 | 4541 |
<resource:#obsolete> |
4542 |
||
2906 | 4543 |
self obsoleteMethodWarning:'use #construct:'. |
308 | 4544 |
^ (nameString , aString asString) |
195 | 4545 |
|
4546 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4547 |
'Makefile' asFilename , '.bak' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4548 |
('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
|
4549 |
'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
|
4550 |
'Makefile' asFilename construct:'.bak' |
195 | 4551 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4552 |
|
14072 | 4553 |
"Modified: / 07-09-1997 / 23:45:36 / cg" |
4554 |
"Modified (comment): / 01-04-2012 / 13:18:21 / cg" |
|
9263 | 4555 |
! |
4556 |
||
4557 |
canonicalize |
|
4558 |
"normalize a filename by removing all empty path components or dots, |
|
4559 |
and by resolving parent directory '..' references. |
|
4560 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4561 |
The code below works for UNIX & MSDOS; |
9263 | 4562 |
other filename classes (i.e. VMS) may want to redefine this method." |
4563 |
||
15811 | 4564 |
nameString := self species canonicalize:nameString. |
9263 | 4565 |
|
4566 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4567 |
'/tmp/bla' asFilename canonicalize. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4568 |
'/tmp/bla/../fasel' asFilename canonicalize. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4569 |
'/tmp/bla/.././/fasel' asFilename canonicalize. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4570 |
'..' asFilename canonicalize. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4571 |
'bla/../fasel' asFilename canonicalize. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4572 |
'//bla/../fasel' asFilename canonicalize. |
9263 | 4573 |
" |
195 | 4574 |
! ! |
4575 |
||
14232 | 4576 |
!Filename methodsFor:'os shell'! |
4577 |
||
4578 |
openExplorer |
|
4579 |
"open a file-explorer on the directory represented by the receiver. |
|
22656 | 4580 |
On osx systems, a finder is opened. |
4581 |
On other systems, a filebrowser is opened" |
|
14232 | 4582 |
|
4583 |
OperatingSystem |
|
22396 | 4584 |
openApplicationForDocument:self pathName |
4585 |
operation:#explore. |
|
4586 |
||
4587 |
" |
|
22656 | 4588 |
Filename currentDirectory openExplorer |
22396 | 4589 |
" |
14232 | 4590 |
|
4591 |
"Created: / 21-07-2012 / 12:28:18 / cg" |
|
22396 | 4592 |
"Modified: / 20-12-2017 / 21:34:41 / stefan" |
14804 | 4593 |
! |
4594 |
||
4595 |
openFinder |
|
4596 |
"open a finder on the directory represented by the receiver. |
|
4597 |
On non-osx systems, an error is raised" |
|
4598 |
||
4599 |
OperatingSystem isOSXlike ifFalse:[ |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4600 |
self warn:'sorry - this operation is only available under osx'. |
14804 | 4601 |
]. |
4602 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4603 |
OperatingSystem executeCommand:'open "',self pathName,'"' |
14804 | 4604 |
! |
4605 |
||
4606 |
openTerminal |
|
16545 | 4607 |
"open a terminal window on the directory represented by the receiver; |
4608 |
on osx, a terminal app is opened, |
|
4609 |
on windows a cmd.exe window, |
|
4610 |
on unix, an xterm is opened." |
|
4611 |
||
4612 |
OperatingSystem isOSXlike ifTrue:[ |
|
20798 | 4613 |
"/ I don't know yet how to tell the terminal to |
20678 | 4614 |
"/ go to a particular directory. |
4615 |
"/ therefore, use the built in terminal |
|
4616 |
VT100TerminalView openShellIn:self pathName. |
|
4617 |
^ self. |
|
4618 |
]. |
|
4619 |
"/ using the code below seems to close the window immediately |
|
4620 |
"/ at least on win7. |
|
4621 |
"/ use out own terminal, to make sure. |
|
4622 |
(OperatingSystem isMSWINDOWSlike |
|
4623 |
and:[OperatingSystem isWin7Like]) ifTrue:[ |
|
20798 | 4624 |
"/ I don't know yet how to tell the terminal to |
20678 | 4625 |
"/ go to a particular directory. |
4626 |
"/ therefore, use the built in terminal |
|
4627 |
VT100TerminalView openShellIn:self pathName. |
|
4628 |
^ self. |
|
16545 | 4629 |
]. |
14804 | 4630 |
|
14941 | 4631 |
[ |
20678 | 4632 |
|cmd| |
4633 |
||
4634 |
OperatingSystem isOSXlike ifTrue:[ |
|
4635 |
cmd := '/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal ' |
|
4636 |
] ifFalse:[ |
|
4637 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
|
4638 |
cmd := #('c:\windows\System32\cmd.exe') |
|
4639 |
] ifFalse:[ |
|
4640 |
"/ VT100TerminalView openShellIn:self pathName |
|
4641 |
cmd := 'xterm' |
|
4642 |
] |
|
4643 |
]. |
|
4644 |
OperatingSystem |
|
4645 |
executeCommand:cmd |
|
4646 |
inDirectory:self pathName |
|
4647 |
showWindow:#default. |
|
14941 | 4648 |
] fork |
20678 | 4649 |
|
4650 |
"Modified: / 18-10-2016 / 16:08:15 / cg" |
|
14232 | 4651 |
! ! |
4652 |
||
615 | 4653 |
!Filename methodsFor:'printing & storing'! |
174 | 4654 |
|
21496 | 4655 |
displayOn:aStream |
4392 | 4656 |
"append a user printed representation of the receiver to aStream. |
4657 |
The format is suitable for a human - not meant to be read back." |
|
174 | 4658 |
|
2906 | 4659 |
aStream nextPutAll:(self class name). |
4660 |
aStream nextPutAll:'('''. |
|
615 | 4661 |
nameString printOn:aStream. |
4662 |
aStream nextPutAll:''')' |
|
2906 | 4663 |
|
21496 | 4664 |
"Created: / 21-02-2017 / 09:02:34 / cg" |
4665 |
! |
|
4666 |
||
4667 |
printOn:aStream |
|
4668 |
"append a user printed representation of the receiver to aStream. |
|
4669 |
The format is suitable for a human - not meant to be read back. |
|
4670 |
Here, I print myself as a string, so I can be easily embedded in bind-with strings." |
|
4671 |
||
4672 |
"/ aStream nextPutAll:(self class name). |
|
4673 |
"/ aStream nextPutAll:'('''. |
|
4674 |
nameString printOn:aStream. |
|
4675 |
"/ aStream nextPutAll:''')' |
|
4676 |
||
4677 |
"Modified (comment): / 21-02-2017 / 09:03:57 / cg" |
|
1 | 4678 |
! |
4679 |
||
615 | 4680 |
storeOn:aStream |
4681 |
"append a printed representation of the receiver to aStream, |
|
4682 |
which allows reconstructing it via readFrom:" |
|
328 | 4683 |
|
615 | 4684 |
aStream nextPut:$(. |
4685 |
nameString storeOn:aStream. |
|
4686 |
aStream nextPutAll:' asFilename)' |
|
1 | 4687 |
! ! |
4688 |
||
7258 | 4689 |
!Filename methodsFor:'private-accessing'! |
1 | 4690 |
|
6227 | 4691 |
getName |
21263 | 4692 |
<resource: #obsolete> |
6227 | 4693 |
"get the raw filename" |
4694 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4695 |
^ nameString |
6227 | 4696 |
! |
4697 |
||
21263 | 4698 |
nameString |
4699 |
"raw access to nameString - req'd for xml-store/reload" |
|
4700 |
||
4701 |
^ nameString |
|
4702 |
! |
|
4703 |
||
4704 |
nameString:aString |
|
4705 |
"raw access to nameString - req'd for xml-store/reload" |
|
4706 |
||
4707 |
nameString := aString |
|
4708 |
! |
|
4709 |
||
68 | 4710 |
setName:aString |
38 | 4711 |
"set the filename" |
4712 |
||
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
4713 |
nameString := aString. |
3666 | 4714 |
|
4715 |
"Modified: / 21.7.1998 / 10:44:18 / cg" |
|
1 | 4716 |
! ! |
4717 |
||
2 | 4718 |
!Filename methodsFor:'queries'! |
4719 |
||
23393 | 4720 |
directories |
4721 |
"return a collection of directories contained in the directory represented by the receiver." |
|
4722 |
||
4723 |
^ OrderedCollection withCollectedContents:[:coll | |
|
4724 |
self directoriesDo:[:eachDirectory | coll add:eachDirectory]] |
|
4725 |
||
4726 |
" |
|
4727 |
'.' asFilename directories. |
|
4728 |
" |
|
4729 |
||
4730 |
"Modified: / 29-05-2007 / 12:02:56 / cg" |
|
4731 |
! |
|
4732 |
||
68 | 4733 |
exists |
92 | 4734 |
"return true, if such a file exists." |
68 | 4735 |
|
2947 | 4736 |
^ OperatingSystem isValidPath:(self osNameForAccess) |
68 | 4737 |
|
85 | 4738 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4739 |
'/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
|
4740 |
'/tmp' asFilename exists |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4741 |
'Makefile' asFilename exists |
85 | 4742 |
" |
77 | 4743 |
! |
4744 |
||
5928 | 4745 |
filenamesMatching:aPattern |
4746 |
"VW compatibility" |
|
4747 |
||
15811 | 4748 |
^ (self filesMatching:aPattern) |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4749 |
collect:[:eachName | self construct:eachName]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4750 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4751 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4752 |
'/etc' asFilename filenamesMatching:'a*;c*' |
5928 | 4753 |
" |
4754 |
||
4755 |
"Created: / 15.4.1997 / 15:40:02 / cg" |
|
4756 |
"Modified: / 3.8.1998 / 21:22:15 / cg" |
|
4757 |
! |
|
4758 |
||
23393 | 4759 |
files |
4760 |
"return a collection of regular files |
|
4761 |
contained in the directory represented by the receiver." |
|
4762 |
||
4763 |
^ OrderedCollection withCollectedContents:[:coll | |
|
4764 |
self filesDo:[:eachFileName | coll add:eachFileName]]. |
|
4765 |
||
4766 |
" |
|
4767 |
'.' asFilename files. |
|
4768 |
" |
|
4769 |
||
4770 |
"Modified: / 29-05-2007 / 12:02:15 / cg" |
|
4771 |
! |
|
4772 |
||
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
4773 |
filesMatching:aPattern |
2550 | 4774 |
"given the receiver, representing a directory; |
4775 |
return a collection of files matching a pattern. |
|
4776 |
The pattern may be a simple matchPattern, or a set of |
|
4777 |
multiple patterns separated by semicolons." |
|
4778 |
||
19821 | 4779 |
^ OrderedCollection withCollectedContents:[:coll | |
4780 |
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
|
4781 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4782 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4783 |
'/etc' asFilename filesMatching:'a*;c*' |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
4784 |
" |
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
4785 |
|
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
4786 |
"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
|
4787 |
"Modified: / 3.8.1998 / 21:22:15 / cg" |
2550 | 4788 |
! |
4789 |
||
19821 | 4790 |
filesMatching:aPattern caseSensitive:caseSensitive do:aBlock |
4791 |
"given the receiver, representing a directory; |
|
4792 |
evaluate aBlock for files which match a pattern. |
|
4793 |
The pattern may be a simple matchPattern, or a set of |
|
4794 |
multiple patterns separated by semicolons." |
|
4795 |
||
4796 |
|matchers| |
|
4797 |
||
4798 |
matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;. |
|
4799 |
self directoryContentsDo:[:name | |
|
4800 |
(matchers contains:[:p | p match:name caseSensitive:caseSensitive]) ifTrue:[ |
|
4801 |
aBlock value:name |
|
4802 |
] |
|
4803 |
]. |
|
4804 |
||
4805 |
" |
|
4806 |
'/etc' asFilename filesMatching:'a*;c*' do:[:f | Transcript showCR:f] |
|
4807 |
" |
|
4808 |
||
4809 |
"Created: / 15.4.1997 / 15:40:02 / cg" |
|
4810 |
"Modified: / 3.8.1998 / 21:22:15 / cg" |
|
4811 |
! |
|
4812 |
||
4813 |
filesMatching:aPattern do:aBlock |
|
4814 |
"given the receiver, representing a directory; |
|
4815 |
evaluate aBlock for files which match a pattern. |
|
4816 |
The pattern may be a simple matchPattern, or a set of |
|
4817 |
multiple patterns separated by semicolons." |
|
4818 |
||
23393 | 4819 |
self filesMatching:aPattern caseSensitive:(self species isCaseSensitive) do:aBlock |
19821 | 4820 |
|
4821 |
" |
|
4822 |
'/etc' asFilename filesMatching:'a*;c*' do:[:f | Transcript showCR:f] |
|
23393 | 4823 |
'/etc' asFilename filesMatching:'a*;c*' |
4824 |
" |
|
4825 |
||
4826 |
"Created: / 15-04-1997 / 15:40:02 / cg" |
|
4827 |
"Modified: / 03-08-1998 / 21:22:15 / cg" |
|
4828 |
"Modified (comment): / 30-09-2018 / 11:01:40 / Claus Gittinger" |
|
4829 |
! |
|
4830 |
||
4831 |
filesMatchingGLOB |
|
4832 |
"Interpreting myself as a GLOB pattern, |
|
4833 |
Return filenames matching me" |
|
4834 |
||
4835 |
^ Array streamContents:[:s | self filesMatchingGLOBDo:[:each | s nextPut:each]]. |
|
4836 |
||
4837 |
" |
|
4838 |
'../../*/A*' asFilename filesMatchingGLOB. |
|
4839 |
" |
|
4840 |
||
4841 |
"Created: / 30-09-2018 / 10:56:42 / Claus Gittinger" |
|
19821 | 4842 |
! |
4843 |
||
2550 | 4844 |
filesMatchingWithoutDotDirs:aPattern |
4845 |
"given the receiver, representing a directory; |
|
4846 |
return a collection of files matching a pattern. |
|
4847 |
Exclude '.' and '..' from the returned list. |
|
4848 |
The pattern may be a simple matchPattern, or a set of |
|
4849 |
multiple patterns separated by semicolons." |
|
4850 |
||
19821 | 4851 |
^ OrderedCollection withCollectedContents:[:coll | |
4852 |
self filesMatchingWithoutDotDirs:aPattern do:[:fn | coll add:fn]] |
|
4853 |
||
4854 |
" |
|
4855 |
Filename currentDirectory filesMatching:'.*' |
|
4856 |
Filename currentDirectory filesMatchingWithoutDotDirs:'*.*' |
|
4857 |
'/etc' asFilename filesMatchingWithoutDotDirs:'*' |
|
4858 |
" |
|
4859 |
||
4860 |
"Created: / 15.4.1997 / 12:52:10 / cg" |
|
4861 |
"Modified: / 3.8.1998 / 21:22:30 / cg" |
|
4862 |
! |
|
4863 |
||
4864 |
filesMatchingWithoutDotDirs:aPattern caseSensitive:caseSensitive do:aBlock |
|
4865 |
"given the receiver, representing a directory; |
|
4866 |
evaluate aBlock for files matching a pattern. |
|
4867 |
Exclude '.' and '..'. |
|
4868 |
The pattern may be a simple matchPattern, or a set of |
|
4869 |
multiple patterns separated by semicolons." |
|
4870 |
||
4871 |
|matchers| |
|
2550 | 4872 |
|
4873 |
matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;. |
|
19821 | 4874 |
|
4875 |
self directoryContentsDo:[:name | |
|
4876 |
(name ~= '.' |
|
4877 |
and:[ name ~= '..' |
|
4878 |
and:[ (matchers contains:[:p | p match:name caseSensitive:caseSensitive]) ]]) |
|
4879 |
ifTrue:[ |
|
4880 |
aBlock value:name |
|
4881 |
] |
|
4882 |
]. |
|
4883 |
||
4884 |
" |
|
4885 |
Filename currentDirectory filesMatching:'M*' |
|
4886 |
'/etc' asFilename filesMatching:'[a-z]*' |
|
4887 |
'../../libbasic' asFilename filesMatching:'[A-D]*.st' |
|
4888 |
" |
|
4889 |
||
4890 |
"Created: / 15.4.1997 / 12:52:10 / cg" |
|
4891 |
"Modified: / 3.8.1998 / 21:22:30 / cg" |
|
4892 |
! |
|
4893 |
||
4894 |
filesMatchingWithoutDotDirs:aPattern do:aBlock |
|
4895 |
"given the receiver, representing a directory; |
|
4896 |
evaluate aBlock for files matching a pattern. |
|
4897 |
Exclude '.' and '..'. |
|
4898 |
The pattern may be a simple matchPattern, or a set of |
|
4899 |
multiple patterns separated by semicolons." |
|
4900 |
||
4901 |
self filesMatchingWithoutDotDirs:aPattern caseSensitive:self species isCaseSensitive do:aBlock |
|
2550 | 4902 |
|
4903 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4904 |
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
|
4905 |
'/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
|
4906 |
'../../libbasic' asFilename filesMatching:'[A-D]*.st' |
2550 | 4907 |
" |
4908 |
||
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
4909 |
"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
|
4910 |
"Modified: / 3.8.1998 / 21:22:30 / cg" |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
4911 |
! |
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
4912 |
|
23393 | 4913 |
filesWithSuffix:suffix |
4914 |
"return a collection of regular files (i.e. not subdirectories) |
|
4915 |
with a given suffix which are contained in the directory |
|
4916 |
represented by the receiver." |
|
4917 |
||
4918 |
^ OrderedCollection withCollectedContents:[:coll | |
|
4919 |
self filesWithSuffix:suffix do:[:eachFileName | coll add:eachFileName]]. |
|
4920 |
||
4921 |
" |
|
4922 |
'.' asFilename filesWithSuffix:'so'. |
|
4923 |
'packages' asFilename filesWithSuffix:'so'. |
|
4924 |
" |
|
4925 |
! |
|
4926 |
||
9206 | 4927 |
fullAlternativePathName |
19821 | 4928 |
"some filesystems (aka: windows) have alternative (short) filenames. |
4929 |
Those systems redefine this method to return it. |
|
4930 |
Otherwise, the same as the regular name is returned here" |
|
4931 |
||
9206 | 4932 |
^ nameString |
4933 |
! |
|
4934 |
||
615 | 4935 |
isExecutable |
4936 |
"return true, if such a file exists and is executable (by Unix's definition). |
|
4937 |
For directories, true is returned if the directory can be entered. |
|
4938 |
See isExecutableProgram for a related check." |
|
4939 |
||
2947 | 4940 |
^ OperatingSystem isExecutable:(self osNameForAccess) |
615 | 4941 |
|
4942 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4943 |
'/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
|
4944 |
'/tmp' asFilename isExecutable |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4945 |
'Makefile' asFilename isExecutable |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4946 |
'/bin/ls' asFilename isExecutable |
356 | 4947 |
" |
4948 |
! |
|
4949 |
||
615 | 4950 |
isExecutableProgram |
4951 |
"return true, if such a file exists and is an executable program. |
|
4952 |
(i.e. for directories, false is returned.)" |
|
356 | 4953 |
|
2922 | 4954 |
|osName| |
4955 |
||
2947 | 4956 |
osName := self osNameForAccess. |
2922 | 4957 |
^ (OperatingSystem isExecutable:osName) |
4958 |
and:[(OperatingSystem isDirectory:osName) not] |
|
356 | 4959 |
|
4960 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4961 |
'/tmp' asFilename isExecutable |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4962 |
'/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
|
4963 |
'/tmp' asFilename isExecutableProgram |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4964 |
'/bin/ls' asFilename isExecutableProgram |
20457 | 4965 |
|
4966 |
'ls' asFilename isExecutableProgram |
|
4967 |
OperatingSystem canExecuteCommand:'ls' |
|
615 | 4968 |
" |
4969 |
! |
|
4970 |
||
2922 | 4971 |
isHidden |
4972 |
"return true, if the receiver represents a hidden file. |
|
4973 |
The definitions of hidden files depends on the OS used; |
|
4974 |
on UNIX, a name starting with a period is considered hidden; |
|
16578 | 4975 |
on MSDOS, the file's hidden attribute is also used. |
2922 | 4976 |
VMS has no concept of hidden files." |
4977 |
||
4978 |
^ false |
|
4979 |
! |
|
4980 |
||
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4981 |
isMountPoint:aPathName |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4982 |
"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
|
4983 |
Warning: |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4984 |
the receiver must be an absolute pathname, |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4985 |
because a realPath is not used/generated for the query (to avoid automounting). |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4986 |
Aka: do not ask: '../../' asFilename isMountPoint; |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4987 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4988 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4989 |
self isAbsolute ifFalse:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4990 |
self error:'this query must be done on an absolute pathname'. |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4991 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4992 |
^ OperatingSystem isMountPoint:(self name) |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4993 |
! |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4994 |
|
615 | 4995 |
isReadable |
4996 |
"return true, if such a file exists and is readable." |
|
4997 |
||
2947 | 4998 |
^ OperatingSystem isReadable:(self osNameForFile) |
615 | 4999 |
|
5000 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5001 |
'/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
|
5002 |
'/tmp' asFilename isReadable |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5003 |
'Makefile' asFilename isReadable |
328 | 5004 |
" |
5005 |
! |
|
5006 |
||
11529 | 5007 |
isSharedLibrary |
5008 |
"return true, if such a file exists and is a shared library." |
|
5009 |
||
5010 |
ObjectFileLoader isNil ifTrue:[ |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5011 |
"we cannot handle shared libraries, so there are no shared libraries" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5012 |
^ false. |
11529 | 5013 |
]. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5014 |
^ (ObjectFileLoader validBinaryExtensions includes:self suffix) |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5015 |
and:[self isRegularFile]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5016 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5017 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5018 |
'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
|
5019 |
'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
|
5020 |
'/tmp' asFilename isSharedLibrary |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5021 |
'/tmp.dll' asFilename isSharedLibrary |
11529 | 5022 |
" |
5023 |
! |
|
5024 |
||
22127 | 5025 |
isValidFilename |
5026 |
"return true, if the name is a valid filename" |
|
5027 |
||
5028 |
|separator| |
|
5029 |
||
5030 |
separator := self separator. |
|
5031 |
||
5032 |
^ nameString notEmptyOrNil |
|
5033 |
and:[(nameString contains:[:eachChar| |
|
5034 |
eachChar ~~ separator |
|
5035 |
and:[self class isBadCharacter:eachChar]]) not]. |
|
5036 |
||
5037 |
" |
|
5038 |
'abc' asFilename isValidFilename |
|
5039 |
'abc/' asFilename isValidFilename |
|
5040 |
('abc' copyWith:Character return) asFilename isValidFilename |
|
5041 |
" |
|
5042 |
||
5043 |
"Created: / 27-07-2017 / 14:23:56 / stefan" |
|
5044 |
! |
|
5045 |
||
615 | 5046 |
isWritable |
5047 |
"return true, if such a file exists and is writable." |
|
5048 |
||
2947 | 5049 |
^ OperatingSystem isWritable:(self osNameForFile) |
615 | 5050 |
|
5051 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5052 |
'/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
|
5053 |
'/tmp' asFilename isWritable |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5054 |
'Makefile' asFilename isWritable |
328 | 5055 |
" |
174 | 5056 |
! |
5057 |
||
15574 | 5058 |
isWritableDirectory |
5059 |
"return true, if such a directory exists and is writable. |
|
5060 |
Don't believe #isWritable, since on an NFS mounted filesystem |
|
5061 |
with UID mapping and attribute cache enabled, there may be false negatives." |
|
5062 |
||
5063 |
self isDirectory ifFalse:[ |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5064 |
^ false. |
15574 | 5065 |
]. |
5066 |
||
5067 |
self isWritable ifFalse:[ |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5068 |
"/ on an NFS mounted filesystem with UID mapping and |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5069 |
"/ attribute cache enabled, |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5070 |
"/ this query may fail, but creation may work actually. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5071 |
"/ check again... |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5072 |
[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5073 |
|tempFile| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5074 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5075 |
tempFile := FileStream newTemporaryIn:self. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5076 |
tempFile close. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5077 |
tempFile fileName remove. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5078 |
] on:OpenError do:[:ex| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5079 |
^ false. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5080 |
]. |
15574 | 5081 |
]. |
5082 |
^ true. |
|
5083 |
||
5084 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5085 |
'/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
|
5086 |
'/tmp' asFilename isWritableDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5087 |
'/etc' asFilename isWritableDirectory |
15574 | 5088 |
'Makefile' asFilename isWritableDirectory |
5089 |
'/net/exeptn/home2/office' asFilename isWritable |
|
5090 |
'/net/exeptn/home2/office' asFilename isWritableDirectory |
|
5091 |
" |
|
5092 |
! |
|
5093 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5094 |
separator |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5095 |
"return the directory-separator character" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5096 |
|
15811 | 5097 |
^ self species separator |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5098 |
|
22403 | 5099 |
" |
5100 |
UnixFilename separator |
|
5101 |
PCFilename separator |
|
5102 |
" |
|
5103 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5104 |
"Modified: 29.2.1996 / 20:52:01 / cg" |
8947 | 5105 |
! |
5106 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
5107 |
species |
15811 | 5108 |
"create only new instances of the concrete OS specific class. |
5109 |
Redefined in AutoDeletedFilename, to not create AutoDeleted instances |
|
5110 |
per default (from directories etc.)" |
|
5111 |
||
5112 |
self == Filename ifTrue:[ |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5113 |
^ ConcreteClass. |
15811 | 5114 |
] ifFalse:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5115 |
^ self class. |
15811 | 5116 |
]. |
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
5117 |
! |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
5118 |
|
8947 | 5119 |
withSpecialExpansions |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5120 |
"return a new filename, expanding any OS specific macros. |
15811 | 5121 |
Here, a ~/ prefix is expanded to the users home dir (as in bash)" |
8947 | 5122 |
|
5123 |
|newName| |
|
5124 |
||
15811 | 5125 |
newName := self species nameWithSpecialExpansions:nameString. |
5126 |
newName = nameString ifTrue:[ |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5127 |
^ self. |
8947 | 5128 |
]. |
15811 | 5129 |
^ self species named:newName. |
8947 | 5130 |
|
5131 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5132 |
'~' asFilename withSpecialExpansions |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5133 |
'~/Desktop' asFilename withSpecialExpansions |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5134 |
'~stefan' asFilename withSpecialExpansions |
15811 | 5135 |
'~stefan/Desktop' asFilename withSpecialExpansions |
8947 | 5136 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5137 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5138 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5139 |
!Filename methodsFor:'queries-contents'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5140 |
|
7291 | 5141 |
mimeTypeFromName |
16578 | 5142 |
"return the mimeType as guessed from the file's name/and or extension. |
7291 | 5143 |
This could be less accurate than mimeTypeOfContents, but avoids |
5144 |
reading the file (is therefore much faster). |
|
5145 |
Also it works with non-existing files. |
|
5146 |
Returns nil for directories and other non-regular files." |
|
5147 |
||
17112 | 5148 |
|mimeTypes| |
5149 |
||
16755 | 5150 |
"/ kludge to avoid making libview a prereq. of libbasic |
17112 | 5151 |
(mimeTypes := Smalltalk at:#MIMETypes) notNil ifTrue:[ |
21693 | 5152 |
^ mimeTypes mimeTypeForFilename:self |
16755 | 5153 |
]. |
5154 |
^ nil |
|
7291 | 5155 |
|
5156 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5157 |
'Makefile' asFilename mimeTypeFromName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5158 |
'.' asFilename mimeTypeFromName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5159 |
'/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
|
5160 |
'/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
|
5161 |
'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
|
5162 |
'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
|
5163 |
'../../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
|
5164 |
'/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
|
5165 |
'/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
|
5166 |
'/x.gz' asFilename mimeTypeFromName |
7291 | 5167 |
" |
21693 | 5168 |
|
5169 |
"Modified: / 11-04-2017 / 09:36:30 / cg" |
|
7291 | 5170 |
! |
5171 |
||
5011 | 5172 |
mimeTypeOfContents |
5173 |
"this tries to guess the mime type of contents of |
|
5174 |
the file. Returns nil, if the file is unreadable, not a plain file |
|
5175 |
or the contents is unknown. |
|
5176 |
This is done using some heuristics, and may need some improvement" |
|
5177 |
||
17111 | 5178 |
|type buffer s size mimeTypes| |
5011 | 5179 |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
5180 |
type := self type. |
11406
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
5181 |
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
|
5182 |
type == #directory ifTrue:[ ^ nil ]. |
11406
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
5183 |
type == #characterSpecial ifTrue:[ ^ nil ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
5184 |
type == #blockSpecial ifTrue:[ ^ nil ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
5185 |
type == #socket ifTrue:[ ^ nil ]. |
5011 | 5186 |
self fileSize == 0 ifTrue:[^ nil]. |
5187 |
||
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
5188 |
s := self readStreamOrNil. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
5189 |
s isNil ifTrue:[^ nil]. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
5190 |
|
5011 | 5191 |
"/ read some data from the file ... |
7685
535a69a7cd69
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7680
diff
changeset
|
5192 |
buffer := String new:2048. |
5011 | 5193 |
|
6943
910f4b17c342
care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6908
diff
changeset
|
5194 |
s errorSignal handle:[:ex | |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5195 |
size := 0. |
6943
910f4b17c342
care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6908
diff
changeset
|
5196 |
] do:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5197 |
size := s nextBytes:buffer size into:buffer. |
6943
910f4b17c342
care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6908
diff
changeset
|
5198 |
]. |
5011 | 5199 |
s close. |
11406
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
5200 |
|
16755 | 5201 |
"/ kludge to avoid making libview a prereq. of libbasic |
17111 | 5202 |
(mimeTypes := Smalltalk at:#MIMETypes) notNil ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5203 |
^ mimeTypes mimeTypeOfData:buffer suffix:self suffix. |
16755 | 5204 |
]. |
5205 |
^ nil |
|
5011 | 5206 |
|
5207 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5208 |
'Makefile' asFilename mimeTypeOfContents |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5209 |
'.' asFilename mimeTypeOfContents |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5210 |
'/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
|
5211 |
'/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
|
5212 |
'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
|
5213 |
'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
|
5214 |
'../../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
|
5215 |
'/bläh' asFilename mimeTypeOfContents |
10153 | 5216 |
'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
|
5217 |
'G:\A\A01.TOP' asFilename mimeTypeOfContents |
10153 | 5218 |
" |
5219 |
||
5220 |
"Modified: / 06-11-2006 / 11:44:58 / cg" |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5221 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5222 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5223 |
!Filename methodsFor:'queries-path & name'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5224 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5225 |
baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5226 |
"return my baseName as a string. |
20413 | 5227 |
- that's the file/directory name without leading parent-dirs. |
2922 | 5228 |
(i.e. '/usr/lib/st/file' asFilename baseName -> 'file' |
5229 |
and '/usr/lib' asFilename baseName -> lib). |
|
7075 | 5230 |
This method does not check if the path is valid. |
5231 |
The code here should work for Unix and MSDOS, but needs to be redefined |
|
5232 |
for VMS (and maybe others as well). |
|
2911 | 5233 |
See also: #pathName, #directoryName and #directoryPathName. |
5234 |
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
|
5235 |
|
2922 | 5236 |
|len index sep endIdx| |
5237 |
||
5238 |
sep := self separator. |
|
5239 |
len := nameString size. |
|
5240 |
((len == 1) and:[(nameString at:1) == sep]) ifTrue:[ |
|
20413 | 5241 |
^ nameString |
2922 | 5242 |
]. |
5243 |
||
5244 |
endIdx := len. |
|
5245 |
len > 1 ifTrue:[ |
|
20413 | 5246 |
(nameString at:len) == sep ifTrue:[endIdx := endIdx - 1]. |
2922 | 5247 |
]. |
5248 |
index := nameString lastIndexOf:sep startingAt:len-1. |
|
5249 |
^ 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
|
5250 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5251 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5252 |
'/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
|
5253 |
'/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
|
5254 |
'.' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5255 |
'..' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5256 |
'../..' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5257 |
'../../libbasic' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5258 |
'../../libpr' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5259 |
'../../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
|
5260 |
'/' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5261 |
'\' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5262 |
'c:\' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5263 |
'\\idefix' asFilename baseName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5264 |
" |
2012 | 5265 |
|
3851 | 5266 |
"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
|
5267 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5268 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5269 |
directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5270 |
"return the directory name part of the file/directory as a new filename. |
20413 | 5271 |
- 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
|
5272 |
the receiver is contained in. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5273 |
(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
|
5274 |
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
|
5275 |
|
15811 | 5276 |
^ self species named:(self directoryName) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5277 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5278 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5279 |
'/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
|
5280 |
'/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
|
5281 |
'/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
|
5282 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5283 |
'.' asFilename directory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5284 |
'..' asFilename directory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5285 |
'../..' asFilename directory |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5286 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5287 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5288 |
"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
|
5289 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5290 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5291 |
directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5292 |
"return the directory name part of the file/directory as a string. |
20413 | 5293 |
- 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
|
5294 |
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
|
5295 |
This method does not check if the path is valid. |
2922 | 5296 |
|
5297 |
(i.e. '/usr/lib/st/file' asFilename directoryName -> '/usr/lib/st' |
|
5298 |
and '/usr/lib' asFilename directoryName -> /usr'). |
|
5299 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5300 |
(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
|
5301 |
a string instead of a Filename instance). |
2922 | 5302 |
|
2012 | 5303 |
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
|
5304 |
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
|
5305 |
|
16389 | 5306 |
|index sep sepString p rest parentDirectoryString| |
2922 | 5307 |
|
5308 |
sep := self separator. |
|
5309 |
sepString := sep asString. |
|
5310 |
(nameString = sepString) ifTrue:[ |
|
20413 | 5311 |
"/ |
5312 |
"/ the trivial '/' case |
|
5313 |
"/ |
|
5314 |
^ sepString |
|
2922 | 5315 |
]. |
5316 |
||
5317 |
"/ |
|
3893 | 5318 |
"/ strip off multiple trailing slashes |
2922 | 5319 |
"/ |
5320 |
p := nameString. |
|
16389 | 5321 |
[p endsWith:sep] whileTrue:[ |
20413 | 5322 |
(p = sepString) ifTrue:[ |
5323 |
^ sepString |
|
5324 |
]. |
|
5325 |
p := p copyButLast:1 |
|
2922 | 5326 |
]. |
5327 |
||
16389 | 5328 |
parentDirectoryString := self class parentDirectoryName. |
5329 |
||
22850 | 5330 |
(p startsWith:(parentDirectoryString,sepString)) ifTrue:[ |
5331 |
^ parentDirectoryString, sepString, p |
|
5332 |
]. |
|
5333 |
||
3886
e6efeb877eda
fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents:
3876
diff
changeset
|
5334 |
"/ strip off trailing components |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
5335 |
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
|
5336 |
index == 0 ifTrue:[ |
20413 | 5337 |
"/ no separator found |
5338 |
p = '.' ifTrue:[ |
|
5339 |
^ parentDirectoryString |
|
5340 |
]. |
|
5341 |
p = '..' ifTrue:[ |
|
5342 |
^ parentDirectoryString, sepString, parentDirectoryString |
|
5343 |
]. |
|
5344 |
^ '.' |
|
2922 | 5345 |
]. |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
5346 |
rest := p copyFrom:(index+1). |
7342
4e9ff418113f
fixed for directory name ending with '/..'
Claus Gittinger <cg@exept.de>
parents:
7332
diff
changeset
|
5347 |
(rest = '.') ifTrue:[ |
20413 | 5348 |
^ p copyTo:index-1. |
7342
4e9ff418113f
fixed for directory name ending with '/..'
Claus Gittinger <cg@exept.de>
parents:
7332
diff
changeset
|
5349 |
]. |
16389 | 5350 |
(rest = parentDirectoryString) ifTrue:[ |
20413 | 5351 |
^ (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
|
5352 |
]. |
3893 | 5353 |
index == 1 ifTrue:[ |
20413 | 5354 |
^ sepString |
3893 | 5355 |
]. |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
5356 |
^ p copyTo:(index - 1) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5357 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5358 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5359 |
'/home' asFilename directoryName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5360 |
'/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
|
5361 |
'/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
|
5362 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5363 |
'/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
|
5364 |
'bitmaps' asFilename directoryName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5365 |
'bitmaps' asFilename directoryPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5366 |
'.' asFilename directoryName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5367 |
'.' asFilename directoryPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5368 |
'..' asFilename directoryName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5369 |
'..' asFilename directoryPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5370 |
'../..' asFilename directoryName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5371 |
'../..' asFilename directoryPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5372 |
'/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
|
5373 |
'/foo/bar/baz/.' asFilename directoryName |
21064 | 5374 |
'c:\' asFilename directoryName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5375 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5376 |
|
3886
e6efeb877eda
fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents:
3876
diff
changeset
|
5377 |
"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
|
5378 |
"Modified: / 21.10.1998 / 22:52:25 / cg" |
3893 | 5379 |
"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
|
5380 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5381 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5382 |
directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5383 |
"return the full directory pathname part of the file/directory as a string. |
20413 | 5384 |
- 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
|
5385 |
the receiver is contained in. |
2012 | 5386 |
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
|
5387 |
|
15811 | 5388 |
^ (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
|
5389 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5390 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5391 |
'/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
|
5392 |
'/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
|
5393 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5394 |
'.' asFilename directoryPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5395 |
'.' asFilename directoryName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5396 |
'.' asFilename directory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5397 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5398 |
'..' asFilename directoryPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5399 |
'..' asFilename directoryName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5400 |
'..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5401 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5402 |
'../..' asFilename directoryPathName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5403 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5404 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5405 |
"Modified: 7.9.1995 / 10:42:13 / claus" |
2012 | 5406 |
"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
|
5407 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5408 |
|
14567 | 5409 |
encodedNameString |
5410 |
"answer the name as passed to OS system calls" |
|
5411 |
||
5412 |
^ OperatingSystem encodePath:nameString |
|
5413 |
! |
|
5414 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5415 |
filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5416 |
"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
|
5417 |
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
|
5418 |
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
|
5419 |
it returns a collection of matching filename objects, |
19440 | 5420 |
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
|
5421 |
match. |
19440 | 5422 |
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
|
5423 |
If there is only one match, the size of the returned collection is exactly 1, |
19752 | 5424 |
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
|
5425 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5426 |
^ self filenameCompletionIn:nil |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5427 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5428 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5429 |
'mak' asFilename filenameCompletion |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5430 |
'Make' asFilename filenameCompletion |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5431 |
'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
|
5432 |
'/u' asFilename filenameCompletion |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5433 |
'../../libpr' asFilename inspect filenameCompletion |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5434 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5435 |
|
1517 | 5436 |
"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
|
5437 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5438 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5439 |
filenameCompletionIn:aDirectory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5440 |
"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
|
5441 |
|
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
5442 |
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
|
5443 |
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
|
5444 |
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
|
5445 |
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
|
5446 |
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
|
5447 |
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
|
5448 |
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
|
5449 |
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
|
5450 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5451 |
|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
|
5452 |
sepString parentString prefix nMatch nm caseless lcBaseName| |
3666 | 5453 |
|
15811 | 5454 |
mySpecies := self species. |
5455 |
||
5456 |
caseless := mySpecies isCaseSensitive not. |
|
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
5457 |
matching := OrderedCollection new. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
5458 |
|
15811 | 5459 |
nm := mySpecies nameWithSpecialExpansions:nameString. |
5460 |
nm := mySpecies canonicalize:nm. |
|
5461 |
||
5462 |
sepString := mySpecies separatorString. |
|
3666 | 5463 |
(nm endsWith:sepString) ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5464 |
"/ two exceptions here: |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5465 |
"/ if there is only one file in the directory, that one must be it. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5466 |
"/ otherwise, return the longest common prefix of all files. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5467 |
self isDirectory ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5468 |
|first longest| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5469 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5470 |
first := nil. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5471 |
OpenError catch:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5472 |
self directoryContentsDo:[:fileName | |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5473 |
((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5474 |
matching add:fileName. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5475 |
first isNil ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5476 |
first := longest := fileName. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5477 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5478 |
"/ more than one file |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5479 |
longest := longest commonPrefixWith:fileName ignoreCase:caseless. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5480 |
longest isEmpty ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5481 |
^ #() |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5482 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5483 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5484 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5485 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5486 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5487 |
longest notNil ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5488 |
nameString := (self constructString:longest). |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5489 |
^ matching |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5490 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5491 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5492 |
^ #() |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5493 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5494 |
|
15811 | 5495 |
parentString := mySpecies parentDirectoryName. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5496 |
baseName := self baseName. |
3666 | 5497 |
baseName ~= nm ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5498 |
prefix := self directoryName. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5499 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5500 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5501 |
self isAbsolute ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5502 |
dir := self directory |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5503 |
] ifFalse:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5504 |
aDirectory isNil ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5505 |
dir := self directory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5506 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5507 |
dir := (aDirectory asFilename construct:nm) directory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5508 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5509 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5510 |
|
3774
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
5511 |
caseless ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5512 |
lcBaseName := baseName asLowercase |
3774
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
5513 |
]. |
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
5514 |
|
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
5515 |
dir class errorReporter openErrorSignal handle:[:ex| |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5516 |
^ #(). |
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
5517 |
] do:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5518 |
dir directoryContents do:[:fileName | |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5519 |
((fileName ~= '.') and:[fileName ~= parentString]) ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5520 |
((caseless and:[fileName asLowercase startsWith:lcBaseName]) |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5521 |
or:[caseless not and:[fileName startsWith:baseName]]) ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5522 |
matching add:fileName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5523 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5524 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5525 |
]. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5526 |
]. |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
5527 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5528 |
(nMatch := matching size) > 1 ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5529 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5530 |
find the longest common prefix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5531 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5532 |
matchLen := baseName size. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5533 |
matchLen > matching first size ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5534 |
try := baseName. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5535 |
allMatching := false |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5536 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5537 |
try := matching first copyTo:matchLen. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5538 |
allMatching := true. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5539 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5540 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5541 |
[allMatching] whileTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5542 |
matching do:[:aName | |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5543 |
((caseless and:[aName asLowercase startsWith:try asLowercase]) |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5544 |
or:[caseless not and:[aName startsWith:try]]) ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5545 |
allMatching := false |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5546 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5547 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5548 |
allMatching ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5549 |
matchLen < matching first size ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5550 |
matchLen := matchLen + 1. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5551 |
try := matching first copyTo:matchLen. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5552 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5553 |
allMatching := false |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5554 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5555 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5556 |
try := matching first copyTo:matchLen - 1. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5557 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5558 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5559 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5560 |
and set my name to the last full match |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5561 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5562 |
nameString := nm := try |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5563 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5564 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5565 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5566 |
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
|
5567 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5568 |
prefix notNil ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5569 |
(prefix endsWith:sepString) ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5570 |
"/ avoid introducing double slashes |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5571 |
prefix := prefix copyButLast:(sepString size). |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5572 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5573 |
matching := matching collect:[:n | prefix , sepString , n]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5574 |
nMatch == 1 ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5575 |
nameString := nm := matching first |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5576 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5577 |
nMatch > 1 ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5578 |
nameString := nm := prefix , sepString , nm |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5579 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5580 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5581 |
] ifFalse:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5582 |
nMatch == 1 ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5583 |
nameString := nm := matching first |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5584 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5585 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5586 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5587 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5588 |
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
|
5589 |
(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
|
5590 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5591 |
^ matching |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5592 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5593 |
" trivial cases: |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5594 |
|
11341
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5595 |
'../' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5596 |
'/' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5597 |
'/usr/' asFilename filenameCompletion -> empty |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5598 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5599 |
'mak' asFilename filenameCompletion |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5600 |
'Make' asFilename filenameCompletion |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5601 |
'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
|
5602 |
'/u' asFilename filenameCompletion |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
5603 |
'../../libpr' asFilename filenameCompletion |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
5604 |
'/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
|
5605 |
|
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5606 |
'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
|
5607 |
'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
|
5608 |
'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
|
5609 |
'c:\' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5610 |
'c:' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5611 |
'\' asFilename filenameCompletion -> empty |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5612 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5613 |
|
10793
0475c364e80a
care for bad (non-filename) arg in fileNameCompletion:
Claus Gittinger <cg@exept.de>
parents:
10780
diff
changeset
|
5614 |
"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
|
5615 |
"Modified: / 17-11-2007 / 14:31:08 / cg" |
2903 | 5616 |
! |
5617 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5618 |
head |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5619 |
"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
|
5620 |
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
|
5621 |
(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
|
5622 |
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
|
5623 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5624 |
^ self directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5625 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5626 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5627 |
Filename currentDirectory head |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5628 |
'Makefile' asFilename head |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5629 |
'/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
|
5630 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5631 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5632 |
"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
|
5633 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5634 |
|
7120 | 5635 |
isAbsolute |
5636 |
"return true, if the receiver represents an absolute pathname |
|
5637 |
(in contrast to one relative to the current directory)." |
|
5638 |
||
19670 | 5639 |
((nameString startsWith:self species separator) or:[nameString startsWith:$~]) ifTrue:[^ true]. |
7120 | 5640 |
^ self isVolumeAbsolute |
5641 |
||
5642 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5643 |
'/foo/bar' asFilename isAbsolute |
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
5644 |
'~/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
|
5645 |
'..' asFilename isAbsolute |
20459 | 5646 |
'..' 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
|
5647 |
'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
|
5648 |
'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
|
5649 |
'SBrowser.st' asFilename isRelative |
7120 | 5650 |
" |
5651 |
! |
|
5652 |
||
21390 | 5653 |
isBackupFilename |
5654 |
"return true, if this name is an for a backup file" |
|
5655 |
||
5656 |
^ nameString last == $~ or:[self hasSuffix:'bak']. |
|
5657 |
||
5658 |
"Created: / 09-02-2017 / 13:57:03 / stefan" |
|
5659 |
! |
|
5660 |
||
7120 | 5661 |
isExplicitRelative |
5662 |
"return true, if this name is an explicit relative name |
|
5663 |
(i.e. starts with './' or '../', to avoid path-prepending)" |
|
5664 |
||
5665 |
^ false |
|
5666 |
! |
|
5667 |
||
5668 |
isImplicit |
|
5669 |
"return true, if the receiver represents a builtin file. |
|
5670 |
The definitions of builtin files depends on the OS used; |
|
5671 |
on UNIX, '.' and '..' are builtin names." |
|
5672 |
||
5673 |
^ false |
|
5674 |
||
5675 |
"Created: 18.9.1997 / 18:04:51 / stefan" |
|
5676 |
! |
|
5677 |
||
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5678 |
isParentDirectoryOf:aFilenameOrString |
16389 | 5679 |
"Answer true, if myself is a parent directory of aFilenameOrString. |
5680 |
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
|
5681 |
not exist and relative and absolute path names are mixed |
18686 | 5682 |
('/' asFilename isParentDirectoryOf:'../noExistent' -> false) |
16389 | 5683 |
|
5684 |
Warning: maybe symbolic links must be resolved which could lead to automounting" |
|
5685 |
||
5686 |
|filenameArg otherNames myNames myName| |
|
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5687 |
|
7236
2b8b8680f5b9
isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents:
7134
diff
changeset
|
5688 |
filenameArg := aFilenameOrString asFilename. |
16389 | 5689 |
|
5690 |
"first do a simple comparison" |
|
5691 |
otherNames := self class canonicalizedNameComponents:filenameArg name. |
|
5692 |
myNames := self class canonicalizedNameComponents:self name. |
|
5693 |
((otherNames startsWith:myNames) and:[myNames first ~= self class parentDirectoryName]) ifTrue:[ |
|
19599 | 5694 |
^ otherNames ~= myNames |
7236
2b8b8680f5b9
isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents:
7134
diff
changeset
|
5695 |
]. |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5696 |
|
16389 | 5697 |
"fall back - try it again with ~ substitution and symbolic links resolved" |
5698 |
otherNames := self class canonicalizedNameComponents:filenameArg pathName. |
|
5699 |
myNames := self class canonicalizedNameComponents:self pathName. |
|
5700 |
(otherNames startsWith:myNames) ifTrue:[ |
|
19599 | 5701 |
^ otherNames ~= myNames |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5702 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5703 |
|
16389 | 5704 |
myName := self class nameFromComponents:myNames. |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5705 |
filenameArg allParentDirectoriesDo:[:parent | |
19599 | 5706 |
parent pathName = myName ifTrue:[^ true]. |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5707 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5708 |
^ false. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5709 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5710 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5711 |
'/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
|
5712 |
'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
|
5713 |
'/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
|
5714 |
'/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
|
5715 |
'/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
|
5716 |
'/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
|
5717 |
'~' 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
|
5718 |
'~' asFilename isParentDirectoryOf:'.' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5719 |
'~' asFilename isParentDirectoryOf:'..' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5720 |
'~' asFilename isParentDirectoryOf:'../smalltalk' |
18686 | 5721 |
'../..' asFilename isParentDirectoryOf:'../nonExistent' |
5722 |
'..' asFilename isParentDirectoryOf:'../../nonExistent' |
|
5723 |
'/' 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
|
5724 |
'/' 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
|
5725 |
" |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5726 |
! |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5727 |
|
7120 | 5728 |
isRelative |
5729 |
"return true, if this name is interpreted relative to some |
|
5730 |
directory (opposite of absolute)" |
|
5731 |
||
5732 |
^ self isAbsolute not |
|
5733 |
||
5734 |
" |
|
5735 |
'./foo/bar' asFilename isRelative |
|
5736 |
'../../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
|
5737 |
'/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
|
5738 |
'bar' asFilename isRelative |
7120 | 5739 |
" |
5740 |
||
5741 |
"Modified: 16.1.1997 / 01:19:14 / cg" |
|
5742 |
! |
|
5743 |
||
5744 |
isRootDirectory |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5745 |
"return true, if I represent the root directory |
7120 | 5746 |
(i.e. I have no parentDir)" |
5747 |
||
5748 |
"/ mhmh - should we use: |
|
5749 |
"/ |
|
5750 |
"/ parentDir := self construct:'..'. |
|
5751 |
"/ (parentDir exists |
|
5752 |
"/ and:[parentDir isDirectory |
|
5753 |
"/ and:[parentDir id ~= self id]]) ifTrue:[ |
|
5754 |
"/ ^ false |
|
5755 |
"/ ]. |
|
5756 |
"/ ^ true |
|
5757 |
"/ |
|
5758 |
||
5759 |
^ self pathName = Filename rootDirectory pathName |
|
5760 |
||
5761 |
"Modified: 23.10.1997 / 00:38:35 / cg" |
|
5762 |
! |
|
5763 |
||
5764 |
isVolumeAbsolute |
|
5765 |
"return true, if the receiver represents an absolute pathname |
|
5766 |
on some disk volume (MSDOS only)" |
|
5767 |
||
5768 |
^ false |
|
5769 |
||
5770 |
"Modified: 7.9.1997 / 23:54:33 / cg" |
|
5771 |
! |
|
5772 |
||
2987
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
5773 |
localPathName |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
5774 |
"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
|
5775 |
but without any volume information. |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
5776 |
Only makes a difference on MSDOS & VMS systems." |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
5777 |
|
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
5778 |
^ self pathName |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
5779 |
! |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
5780 |
|
615 | 5781 |
name |
5782 |
"return the name of the file represented by the receiver as a string. |
|
883 | 5783 |
This may or may not be a relative name (i.e. include ..'s). |
615 | 5784 |
See also: pathName" |
174 | 5785 |
|
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5786 |
"/ self isAbsolute ifTrue:[^ self pathName]. |
615 | 5787 |
^ nameString |
174 | 5788 |
|
5789 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5790 |
'/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
|
5791 |
'/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
|
5792 |
'.' asFilename name |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5793 |
'.' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5794 |
'../..' asFilename name |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5795 |
'../..' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5796 |
'bitmaps' asFilename name |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5797 |
'bitmaps' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5798 |
'/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
|
5799 |
'/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
|
5800 |
'source/..' asFilename name |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5801 |
'source/..' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5802 |
'/tmp/..' asFilename name |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5803 |
'/tmp/..' asFilename pathName |
92 | 5804 |
" |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
5805 |
|
883 | 5806 |
"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
|
5807 |
! |
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
5808 |
|
615 | 5809 |
pathName |
5810 |
"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
|
5811 |
as a string. This will not include ..'s. |
1317 | 5812 |
If the path represented by the receiver does NOT represent a valid path, |
5813 |
no compression will be done (for now; this may change). |
|
5814 |
See also: name" |
|
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
5815 |
|
15811 | 5816 |
^ OperatingSystem pathNameOf:(self species nameWithSpecialExpansions:nameString). |
2 | 5817 |
|
92 | 5818 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5819 |
'/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
|
5820 |
'.' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5821 |
'../..' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5822 |
'../..' asFilename name |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5823 |
'/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
|
5824 |
'/././usr' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5825 |
'~/..' asFilename pathName |
92 | 5826 |
" |
159 | 5827 |
|
1317 | 5828 |
"Modified: 27.4.1996 / 18:19:52 / cg" |
174 | 5829 |
! |
5830 |
||
22403 | 5831 |
pathNameRelativeFrom:anotherDirectoriesFilename |
5832 |
"return the pathname of the receiver, |
|
5833 |
but relative from another directory. |
|
5834 |
I.e. if the receiver is /a/b/c |
|
5835 |
and the argument is /a/x/y, |
|
5836 |
then the relative path to the receiver as seen from the argument is ../../b/c" |
|
5837 |
||
5838 |
|myPath otherDir otherPath rest prefix| |
|
5839 |
||
5840 |
myPath := self pathName. |
|
5841 |
otherDir := anotherDirectoriesFilename asFilename. |
|
5842 |
prefix := ''. |
|
5843 |
[ |
|
5844 |
otherPath := otherDir pathName. |
|
5845 |
"/ if I am below: |
|
5846 |
(myPath startsWith:otherPath) ifTrue:[ |
|
5847 |
rest := (myPath copyFrom:otherPath size+1). |
|
5848 |
rest isEmpty ifTrue:[^ prefix,'.' ]. |
|
5849 |
(rest startsWith:self separator) ifTrue:[^ prefix,(rest copyFrom:2) ]. |
|
5850 |
^ prefix,rest |
|
5851 |
]. |
|
5852 |
prefix := prefix,'..',self separator. |
|
5853 |
otherDir := otherDir directory. |
|
5854 |
] loop |
|
5855 |
||
5856 |
" |
|
5857 |
self assert:('/a' asFilename pathNameRelativeFrom:'/') = 'a' |
|
5858 |
self assert:('/a/b' asFilename pathNameRelativeFrom:'/') = 'a/b' |
|
5859 |
||
5860 |
self assert:('/a' asFilename pathNameRelativeFrom:'/a') = '.' |
|
5861 |
self assert:('/a/b' asFilename pathNameRelativeFrom:'/a') = 'b' |
|
5862 |
self assert:('/a/b/c' asFilename pathNameRelativeFrom:'/a') = 'b/c' |
|
5863 |
||
5864 |
self assert:('/a/' asFilename pathNameRelativeFrom:'/a') = '.' |
|
5865 |
self assert:('/a/b/' asFilename pathNameRelativeFrom:'/a') = 'b' |
|
5866 |
self assert:('/a/b/c/' asFilename pathNameRelativeFrom:'/a') = 'b/c' |
|
5867 |
||
5868 |
self assert:('/a' asFilename pathNameRelativeFrom:'/a/') = '.' |
|
5869 |
self assert:('/a/b' asFilename pathNameRelativeFrom:'/a/') = 'b' |
|
5870 |
self assert:('/a/b/c' asFilename pathNameRelativeFrom:'/a/') = ''b/c'' |
|
5871 |
||
5872 |
self assert:('/a/' asFilename pathNameRelativeFrom:'/a/') = '.' |
|
5873 |
self assert:('/a/b/' asFilename pathNameRelativeFrom:'/a/') = 'b' |
|
5874 |
self assert:('/a/b/c/' asFilename pathNameRelativeFrom:'/a/') = 'b/c' |
|
5875 |
||
5876 |
self assert:('/a' asFilename pathNameRelativeFrom:'/b') = '../a' |
|
5877 |
self assert:('/a/b/' asFilename pathNameRelativeFrom:'/b') = '../a/b' |
|
5878 |
self assert:('/a/b/c/' asFilename pathNameRelativeFrom:'/b') = '../a/b/c' |
|
5879 |
||
5880 |
self assert:('/a/b/' asFilename pathNameRelativeFrom:'/a') = 'b' |
|
5881 |
self assert:('/a/b/c/' asFilename pathNameRelativeFrom:'/a') = 'b/c' |
|
5882 |
||
5883 |
self assert:('/a/b/c/d' asFilename pathNameRelativeFrom:'/a/x/y/z') = '../../../b/c/d' |
|
5884 |
" |
|
5885 |
! |
|
5886 |
||
11658 | 5887 |
physicalFilename |
5888 |
"return the fileName representing the physical file as represented by the receiver, |
|
20413 | 5889 |
If the receiver represents a symbolic link, that's the fileName of the |
19440 | 5890 |
final target. Otherwise, its the receiver's pathName itself. |
11658 | 5891 |
If any file along the symbolic path does not exist (i.e. is a broken link), |
5892 |
nil is returned." |
|
5893 |
||
5894 |
|pathOrNil| |
|
5895 |
||
5896 |
pathOrNil := self physicalPathName. |
|
5897 |
pathOrNil isNil ifTrue:[ |
|
20413 | 5898 |
^ nil |
11658 | 5899 |
]. |
5900 |
^ pathOrNil asFilename |
|
5901 |
||
5902 |
" |
|
20708 | 5903 |
'/foo/bar' asFilename physicalFilename |
11658 | 5904 |
" |
5905 |
! |
|
5906 |
||
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5907 |
physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5908 |
"return the full pathname of the physical file represented by the receiver, |
20413 | 5909 |
If the receiver represents a symbolic link, that's the fileName of the |
19440 | 5910 |
final target. Otherwise, its the receiver's pathName itself. |
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5911 |
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
|
5912 |
nil is returned." |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5913 |
|
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
5914 |
|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
|
5915 |
|
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
5916 |
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
|
5917 |
info isNil ifTrue:[ |
20413 | 5918 |
" I do not exist" |
5919 |
^ nil. |
|
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5920 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
5921 |
info isSymbolicLink ifFalse:[ |
20413 | 5922 |
^ 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
|
5923 |
]. |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
5924 |
|
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5925 |
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
|
5926 |
[ |
20413 | 5927 |
path := info path. |
5928 |
path isNil ifTrue:[ |
|
5929 |
"/ cannot happen |
|
5930 |
^ nil |
|
5931 |
]. |
|
5932 |
path asFilename isAbsolute ifTrue:[ |
|
5933 |
t := path asFilename |
|
5934 |
] ifFalse:[ |
|
5935 |
t := (self species named:t directoryName) construct:path. |
|
5936 |
]. |
|
5937 |
info := t linkInfo. |
|
5938 |
info isNil ifTrue:[ |
|
5939 |
"t does not exist" |
|
5940 |
^ nil |
|
5941 |
]. |
|
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
5942 |
] 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
|
5943 |
|
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5944 |
^ t pathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5945 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5946 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5947 |
'/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
|
5948 |
'.' asFilename physicalPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5949 |
'../..' asFilename physicalPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5950 |
'/usr/tmp' asFilename physicalPathName |
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5951 |
" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5952 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5953 |
"Modified: 21.12.1996 / 15:29:50 / cg" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5954 |
! |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5955 |
|
615 | 5956 |
tail |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5957 |
"the file's name without directory prefix as a string. |
615 | 5958 |
An alias for baseName, for ST-80 compatiblity." |
174 | 5959 |
|
615 | 5960 |
^ self baseName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5961 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5962 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5963 |
Filename currentDirectory tail |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5964 |
'Makefile' asFilename tail |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5965 |
'/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
|
5966 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5967 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5968 |
"Modified: 29.2.1996 / 20:19:50 / cg" |
2629 | 5969 |
! |
5970 |
||
7307
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5971 |
tail:nComponents |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5972 |
"return the last n components of myself. |
20413 | 5973 |
- 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
|
5974 |
(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
|
5975 |
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
|
5976 |
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
|
5977 |
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
|
5978 |
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
|
5979 |
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
|
5980 |
|
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5981 |
|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
|
5982 |
|
15811 | 5983 |
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
|
5984 |
components := self components. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5985 |
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
|
5986 |
start < 1 ifTrue:[ |
20413 | 5987 |
start := 1. |
7307
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5988 |
]. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5989 |
start = 1 ifTrue:[ |
20413 | 5990 |
tail := '' |
7307
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5991 |
] ifFalse:[ |
20413 | 5992 |
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
|
5993 |
]. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5994 |
start+1 to:components size do:[:i| |
20413 | 5995 |
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
|
5996 |
]. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5997 |
^ tail. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5998 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5999 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6000 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6001 |
'/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
|
6002 |
'/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
|
6003 |
'/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
|
6004 |
'/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
|
6005 |
'.' asFilename tail:3 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6006 |
'..' asFilename tail:3 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6007 |
'../..' asFilename tail:2 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6008 |
'../../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
|
6009 |
'../../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
|
6010 |
'../../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
|
6011 |
'../../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
|
6012 |
'/' asFilename tail:2 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6013 |
'\' asFilename tail:2 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6014 |
'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
|
6015 |
'\\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
|
6016 |
" |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6017 |
! |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
6018 |
|
2629 | 6019 |
volume |
6020 |
"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
|
6021 |
This is only used with MSDOS and VMS filenames |
2906 | 6022 |
- by default (and on unix), an empty string is returned" |
6023 |
||
2629 | 6024 |
^ '' |
2906 | 6025 |
|
6026 |
"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
|
6027 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6028 |
|
7120 | 6029 |
!Filename methodsFor:'queries-type'! |
6030 |
||
6031 |
isDirectory |
|
6032 |
"return true, if the receiver represents an existing, |
|
6033 |
readable directories pathname." |
|
6034 |
||
6035 |
^ OperatingSystem isDirectory:(self osNameForAccess) |
|
6036 |
||
6037 |
" |
|
6038 |
'/foo/bar' asFilename isDirectory |
|
6039 |
'/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
|
6040 |
'Makefile' asFilename isDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6041 |
'c:\' asFilename isDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6042 |
'd:\' asFilename isDirectory |
7120 | 6043 |
" |
6044 |
||
6045 |
"Modified: / 21.9.1998 / 15:53:10 / cg" |
|
6046 |
! |
|
6047 |
||
6048 |
isNonEmptyDirectory |
|
6049 |
"return true, if the receiver represents an existing, |
|
6050 |
readable directories pathname, and the directory is not empty." |
|
6051 |
||
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
6052 |
FileStream openErrorSignal |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6053 |
handle:[:ex| ] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6054 |
do:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6055 |
self directoryContentsDo:[:pathString|^ true]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6056 |
]. |
7120 | 6057 |
^ false. |
6058 |
||
6059 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6060 |
'/foo/bar' asFilename isNonEmptyDirectory |
7120 | 6061 |
'/tmp' asFilename isNonEmptyDirectory |
6062 |
'/tmp/empty' asFilename makeDirectory; isNonEmptyDirectory. |
|
6063 |
'/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
|
6064 |
'Makefile' asFilename isNonEmptyDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6065 |
'c:\' asFilename isNonEmptyDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6066 |
'd:\' asFilename isNonEmptyDirectory |
7120 | 6067 |
" |
6068 |
||
6069 |
"Modified: / 21.9.1998 / 15:53:10 / cg" |
|
6070 |
! |
|
6071 |
||
8836 | 6072 |
isRegularFile |
6073 |
"return true, if the receiver represents a plain, regular file" |
|
6074 |
||
6075 |
^ self type == #regular |
|
6076 |
||
6077 |
" |
|
6078 |
'/foo/bar' asFilename isRegularFile |
|
6079 |
'/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
|
6080 |
'Makefile' asFilename isRegularFile |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6081 |
'c:\' asFilename isRegularFile |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6082 |
'd:\' asFilename isRegularFile |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6083 |
'/dev/null' asFilename isRegularFile |
8836 | 6084 |
" |
6085 |
! |
|
6086 |
||
7120 | 6087 |
isSpecialFile |
6088 |
"return true, if the receiver represents a socket, named pipe, fifo |
|
6089 |
or device special file (i.e. anything non regular and non-directory)" |
|
6090 |
||
6091 |
|t| |
|
6092 |
||
6093 |
t := self type. |
|
6094 |
^ (t ~= #directory and:[t ~~ #regular and:[t ~~ #symbolicLink]]) |
|
6095 |
||
6096 |
" |
|
6097 |
'/foo/bar' asFilename isSpecialFile |
|
6098 |
'/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
|
6099 |
'Makefile' asFilename isSpecialFile |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6100 |
'c:\' asFilename isSpecialFile |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6101 |
'd:\' asFilename isSpecialFile |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6102 |
'/dev/null' asFilename isSpecialFile |
7120 | 6103 |
" |
6104 |
! |
|
6105 |
||
6106 |
isSymbolicLink |
|
6107 |
"return true, if the file represented by the receiver is a symbolic |
|
22127 | 6108 |
link. Notice that not all OS's support symbolic links; |
6109 |
those that do not will always return false." |
|
7120 | 6110 |
|
6111 |
^ OperatingSystem isSymbolicLink:(self osNameForFile) |
|
6112 |
||
6113 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6114 |
'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
|
6115 |
'Makefile' asFilename isSymbolicLink |
7120 | 6116 |
" |
22127 | 6117 |
|
6118 |
"Modified (comment): / 27-07-2017 / 16:03:43 / stefan" |
|
7120 | 6119 |
! ! |
6120 |
||
6529 | 6121 |
!Filename methodsFor:'reading-directories'! |
6122 |
||
6123 |
directoryContents |
|
6124 |
"return the contents of the directory as a collection of strings. |
|
6125 |
This excludes any entries for '.' or '..'. |
|
6126 |
Returns nil for non-existing directories; however, this behavior |
|
6127 |
may be changed in the near future, to raise an exception instead. |
|
6128 |
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
|
6129 |
Notice: |
19821 | 6130 |
this returns the file-names as strings; |
6131 |
see also #directoryContentsAsFilenames, which returns fileName instances." |
|
6132 |
||
6133 |
^ OrderedCollection withCollectedContents:[:coll | |
|
6134 |
self directoryContentsDo:[:each | coll add:each]] |
|
6529 | 6135 |
|
6136 |
" |
|
6137 |
'.' asFilename directoryContents |
|
6138 |
'/XXXdoesNotExist' asFilename directoryContents |
|
6139 |
" |
|
6140 |
||
6141 |
"Modified: / 18.9.1997 / 18:42:23 / stefan" |
|
6142 |
"Modified: / 3.8.1998 / 21:36:21 / cg" |
|
6143 |
! |
|
6144 |
||
6145 |
directoryContentsAsFilenames |
|
6146 |
"return the contents of the directory as a collection of filenames. |
|
6147 |
This excludes any entries for '.' or '..'. |
|
6148 |
Returns nil for non-existing directories; however, this behavior |
|
6149 |
may be changed in the near future, to raise an exception instead. |
|
6150 |
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
|
6151 |
Notice: |
19821 | 6152 |
this returns the file-names as fileName instances; |
6153 |
see also #directoryContents, which returns strings." |
|
6154 |
||
6155 |
^ OrderedCollection withCollectedContents:[:coll | |
|
6156 |
self directoryContentsAsFilenamesDo:[:each | coll add:each]] |
|
6529 | 6157 |
|
6158 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6159 |
'.' asFilename directoryContentsAsFilenames |
6529 | 6160 |
'/XXXdoesNotExist' asFilename directoryContentsAsFilenames |
6161 |
" |
|
6162 |
! |
|
6163 |
||
6164 |
fullDirectoryContents |
|
6165 |
"return the full contents of the directory as a collection of strings. |
|
6166 |
This is much like #directoryContents, but includes an entry for the |
|
6167 |
parent directory, if there is one. |
|
6168 |
Returns nil for non-existing directories; however, this behavior |
|
6169 |
may be changed in the near future, to raise an exception instead. |
|
6170 |
So users of this method better test for existing directory before." |
|
6171 |
||
6172 |
|files| |
|
6173 |
||
12910 | 6174 |
"here we get the files without '.' and '..'" |
6529 | 6175 |
files := self directoryContents. |
6176 |
files isNil ifTrue:[ |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6177 |
"/ mhmh - that one does not exist |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6178 |
^ files |
6529 | 6179 |
]. |
6180 |
||
12910 | 6181 |
files addFirst:'..'. |
6529 | 6182 |
^ files |
6183 |
||
6184 |
" |
|
6185 |
'.' asFilename fullDirectoryContents |
|
6186 |
'/XXXdoesNotExist' asFilename fullDirectoryContents |
|
6187 |
'd:\FET' asFilename fullDirectoryContents |
|
6188 |
" |
|
6189 |
||
6190 |
"Modified: / 21.9.1998 / 15:33:07 / cg" |
|
6191 |
! |
|
6192 |
||
23332 | 6193 |
isEmptyDirectory |
6194 |
"answer true, if this is an empty directory. |
|
6195 |
Raise an exception, if this is not a directory." |
|
6196 |
||
6197 |
self directoryContentsDo:[:each | ^ false]. |
|
6198 |
^ true |
|
6199 |
||
6200 |
" |
|
6201 |
'.' asFilename isEmptyDirectory |
|
6202 |
'Make.proto' asFilename isEmptyDirectory |
|
6203 |
'/XXXdoesNotExist' asFilename isEmptyDirectory |
|
6204 |
" |
|
6205 |
||
6206 |
"Created: / 12-09-2018 / 14:29:12 / Stefan Vogel" |
|
6207 |
! |
|
6208 |
||
6529 | 6209 |
recursiveDirectoryContents |
6210 |
"return the contents of the directory and all subdirectories |
|
6211 |
as a collection of strings. |
|
6212 |
This excludes any entries for '.' or '..'. |
|
6213 |
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
|
6214 |
Notice: |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6215 |
this returns the file-names as strings; |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6216 |
see also #recursiveDirectoryContentsAsFilenames, which returns fileName instances. |
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6217 |
|
6529 | 6218 |
Warning: this may take a long time to execute." |
6219 |
||
6220 |
|fileNames dirNames| |
|
6221 |
||
6222 |
fileNames := OrderedCollection new. |
|
6223 |
dirNames := OrderedCollection new. |
|
6224 |
self directoryContents do:[:f | |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6225 |
(self construct:f) isDirectory ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6226 |
dirNames add:f |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6227 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6228 |
fileNames add:f |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6229 |
] |
6529 | 6230 |
]. |
6231 |
||
6232 |
dirNames do:[:dN | |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6233 |
|dd subFiles| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6234 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6235 |
dd := dN asFilename. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6236 |
subFiles := (self construct:dN) recursiveDirectoryContents. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6237 |
fileNames addAll:(subFiles collect:[:f | dd constructString:f]) |
6529 | 6238 |
]. |
6239 |
^ fileNames. |
|
6240 |
||
6241 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6242 |
'.' asFilename recursiveDirectoryContents |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6243 |
'../../clients' asFilename recursiveDirectoryContents |
6529 | 6244 |
" |
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6245 |
! |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6246 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6247 |
recursiveDirectoryContentsAsFilenames |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6248 |
"return the contents of the directory and all subdirectories |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6249 |
as a collection of filenames. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6250 |
This excludes any entries for '.' or '..'. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6251 |
Returns nil for non-existing directories; however, this behavior |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6252 |
may be changed in the near future, to raise an exception instead. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6253 |
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
|
6254 |
Notice: |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6255 |
this returns the file-names as fileName instances; |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6256 |
see also #recursiveDirectoryContents, which returns strings. |
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6257 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6258 |
Warning: this may take a long time to execute." |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6259 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6260 |
|names| |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6261 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6262 |
names := self recursiveDirectoryContents. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6263 |
names isNil ifTrue:[^ nil]. |
12910 | 6264 |
^ names collect:[:entry | self construct:entry]. |
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6265 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6266 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6267 |
'.' asFilename recursiveDirectoryContentsAsFilenames |
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6268 |
'/XXXdoesNotExist' asFilename recursiveDirectoryContentsAsFilenames |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6269 |
" |
6529 | 6270 |
! ! |
6271 |
||
6272 |
!Filename methodsFor:'reading-files'! |
|
6273 |
||
22685 | 6274 |
binaryContents |
6275 |
"an alias. |
|
6276 |
return the binary contents of the file (as a byteArray); |
|
6277 |
Raises an error, if the file is unreadable/non-existing." |
|
6278 |
||
6279 |
^ self binaryContentsOfEntireFile |
|
6280 |
! |
|
6281 |
||
6529 | 6282 |
binaryContentsOfEntireFile |
6283 |
"return the binary contents of the file (as a byteArray); |
|
7680 | 6284 |
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
|
6285 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6286 |
^ self |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6287 |
readingFileDo:[:s | |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6288 |
|nBytes bytes n result| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6289 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6290 |
s binary. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6291 |
nBytes := self fileSize. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6292 |
(nBytes notNil and:[ nBytes ~~ 0 ]) ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6293 |
bytes := ByteArray uninitializedNew:nBytes. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6294 |
n := s nextBytes:nBytes into:bytes startingAt:1. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6295 |
n == nBytes ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6296 |
result := bytes |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6297 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6298 |
result := bytes copyTo:n |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6299 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6300 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6301 |
result := s contentsOfEntireFile |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6302 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6303 |
result |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6304 |
] |
6529 | 6305 |
|
6306 |
" |
|
6307 |
'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
|
6308 |
'foobar' asFilename binaryContentsOfEntireFile |
6529 | 6309 |
" |
14446
479f02b4c705
changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
14306
diff
changeset
|
6310 |
|
479f02b4c705
changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
14306
diff
changeset
|
6311 |
"Modified: / 27-10-2012 / 19:42:07 / cg" |
6529 | 6312 |
! |
6313 |
||
6314 |
contents |
|
20156 | 6315 |
"Return the contents of the file as a collection of lines. |
6316 |
Raise an error if the file is unreadable/non-existing. |
|
6529 | 6317 |
See also #contentsOfEntireFile, which returns a string for textFiles. |
6318 |
CAVEAT: bad naming - but req'd for VW compatibility." |
|
6319 |
||
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
6320 |
^ self readingFileDo:[:s | s contents]. |
6529 | 6321 |
|
6322 |
" |
|
6323 |
'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
|
6324 |
'foobar' asFilename contents |
6529 | 6325 |
" |
6326 |
||
6327 |
"Modified: / 2.7.1996 / 12:49:45 / stefan" |
|
6328 |
"Created: / 11.7.1996 / 14:09:11 / cg" |
|
6329 |
"Modified: / 15.10.1998 / 11:41:45 / cg" |
|
6330 |
! |
|
6331 |
||
10780 | 6332 |
contentsAsString |
6333 |
"to compensate for the bad naming, use this to make things explicit. |
|
6334 |
See also #contents, which returns the lines as stringCollection for textFiles." |
|
6335 |
||
11397
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
6336 |
^ self contentsOfEntireFile |
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
6337 |
|
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
6338 |
" |
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
6339 |
'Makefile' asFilename contentsAsString |
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
6340 |
'foobar' asFilename contentsAsString |
10780 | 6341 |
" |
6342 |
||
6343 |
"Modified: / 02-07-1996 / 12:49:45 / stefan" |
|
6344 |
"Created: / 08-11-2007 / 13:29:59 / cg" |
|
6345 |
! |
|
6346 |
||
6529 | 6347 |
contentsOfEntireFile |
6348 |
"return the contents of the file as a string; |
|
7680 | 6349 |
Raises an error, if the file is unreadable/non-existing. |
6529 | 6350 |
See also #contents, which returns the lines as stringCollection for textFiles. |
6351 |
CAVEAT: bad naming - but req'd for VW compatibility." |
|
6352 |
||
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
6353 |
^ self readingFileDo:[:s | s contentsOfEntireFile]. |
6529 | 6354 |
|
6355 |
" |
|
6356 |
'Makefile' asFilename contentsOfEntireFile |
|
19043 | 6357 |
'smalltalk.rc' asFilename contentsOfEntireFile |
6529 | 6358 |
'foobar' asFilename contentsOfEntireFile |
6359 |
" |
|
6360 |
||
6361 |
"Modified: / 2.7.1996 / 12:49:45 / stefan" |
|
6362 |
"Modified: / 15.10.1998 / 11:42:05 / cg" |
|
6363 |
! |
|
6364 |
||
6365 |
readingFileDo:aBlock |
|
20156 | 6366 |
"Create a read stream on the receiver file, evaluate aBlock, passing that stream as arg, |
6367 |
and return the block's value. |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
6368 |
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
|
6369 |
(old behavior, will vanish:)the block is evaluated with a nil argument. |
6529 | 6370 |
Ensures that the stream is closed." |
6371 |
||
22497 | 6372 |
|stream| |
6373 |
||
6374 |
stream := self readStream. |
|
6375 |
^ [ |
|
6376 |
aBlock value:stream |
|
6529 | 6377 |
] ensure:[ |
20156 | 6378 |
stream notNil ifTrue:[stream close] |
6529 | 6379 |
]. |
6380 |
||
6381 |
" |
|
6382 |
read the first line from some file: |
|
6383 |
||
6384 |
|rslt| |
|
6385 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6386 |
rslt := |
20156 | 6387 |
'/etc/passwd' asFilename |
6388 |
readingFileDo:[:s | |
|
6389 |
s nextLine |
|
6390 |
]. |
|
6529 | 6391 |
Transcript showCR:rslt. |
6392 |
" |
|
6393 |
||
6394 |
" |
|
6395 |
find all used shells in /etc/passwd and count their usage: |
|
6396 |
||
6397 |
|rslt| |
|
6398 |
||
6399 |
rslt := |
|
20156 | 6400 |
'/etc/passwd' asFilename |
6401 |
readingFileDo: |
|
6402 |
[:s | |
|
6403 |
|shells| |
|
6404 |
||
6405 |
shells := Bag new. |
|
6406 |
s linesDo: |
|
6407 |
[:line | |
|
6408 |
|parts| |
|
6409 |
||
6410 |
parts := line asCollectionOfSubstringsSeparatedBy:$:. |
|
6411 |
shells add:(parts seventh). |
|
6412 |
]. |
|
6413 |
shells contents |
|
6414 |
]. |
|
6529 | 6415 |
Transcript showCR:rslt. |
6416 |
" |
|
22497 | 6417 |
|
6418 |
"Modified: / 12-01-2018 / 18:21:32 / stefan" |
|
6771 | 6419 |
! |
6420 |
||
6421 |
readingLinesDo:aBlock |
|
20158 | 6422 |
"Create a read stream on the receiver file and |
6771 | 6423 |
evaluate aBlock for each line read from the stream. |
6424 |
If the file cannot be opened, an error is raised. |
|
6425 |
Ensures that the stream is closed." |
|
6426 |
||
6427 |
self readingFileDo:[:stream | |
|
20158 | 6428 |
stream linesDo:aBlock |
6771 | 6429 |
]. |
6430 |
||
6431 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6432 |
'/etc/passwd' asFilename |
20158 | 6433 |
readingLinesDo:[:eachLine | |
6434 |
Transcript showCR:eachLine. |
|
6435 |
]. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6436 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6437 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6438 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6439 |
'/etc/xxxxx' asFilename |
20158 | 6440 |
readingLinesDo:[:eachLine | |
6441 |
Transcript showCR:eachLine. |
|
6442 |
]. |
|
6771 | 6443 |
" |
6529 | 6444 |
! ! |
6445 |
||
2922 | 6446 |
!Filename methodsFor:'special accessing'! |
6447 |
||
6448 |
osName |
|
6449 |
"special - return the OS's name for the receiver." |
|
6450 |
||
6451 |
self isDirectory ifTrue:[ |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6452 |
^ self osNameForDirectory |
2922 | 6453 |
]. |
6454 |
^ self osNameForFile |
|
6455 |
! |
|
6456 |
||
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
6457 |
osNameForAccess |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
6458 |
"internal - return the OS's name for the receiver to |
3665 | 6459 |
access its fileInfo. |
6460 |
This may be redefined for systems, where a special suffix must be |
|
6461 |
added in order to access directories (or others) as a file. |
|
6462 |
(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
|
6463 |
|
7064 | 6464 |
^ self osNameForFile |
3665 | 6465 |
|
6466 |
"Modified: / 21.7.1998 / 10:40:40 / cg" |
|
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
6467 |
! |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
6468 |
|
2922 | 6469 |
osNameForDirectory |
3753 | 6470 |
"internal - return the OS's name for the receiver to |
2922 | 6471 |
access it as a directory." |
6472 |
||
14218 | 6473 |
^ self osNameForFile |
3753 | 6474 |
|
6475 |
"Modified: / 12.8.1998 / 14:44:32 / cg" |
|
2922 | 6476 |
! |
6477 |
||
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
6478 |
osNameForDirectoryContents |
3753 | 6479 |
"internal - return the OS's name for the receiver to |
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
6480 |
access it as a directory when reading its contents." |
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
6481 |
|
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
6482 |
^ self osNameForDirectory |
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
6483 |
|
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
6484 |
"Created: / 3.8.1998 / 21:36:06 / cg" |
3753 | 6485 |
"Modified: / 12.8.1998 / 14:44:34 / cg" |
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
6486 |
! |
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
6487 |
|
2922 | 6488 |
osNameForFile |
6489 |
"internal - return the OS's name for the receiver to |
|
6490 |
access it as a file." |
|
6491 |
||
19670 | 6492 |
(nameString startsWith:$~) ifFalse:[ |
6493 |
^ nameString. |
|
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
6494 |
]. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
6495 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6496 |
^ self species nameWithSpecialExpansions:nameString. |
2922 | 6497 |
! ! |
6498 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6499 |
!Filename methodsFor:'suffixes'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6500 |
|
11748 | 6501 |
addSuffix:aSuffix |
19440 | 6502 |
"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
|
6503 |
The new suffix is simply appended to the name, |
14306
f41ca29d9b54
comment/format in: #addSuffix:
Stefan Vogel <sv@exept.de>
parents:
14232
diff
changeset
|
6504 |
regardless whether there is already an existing suffix. |
f41ca29d9b54
comment/format in: #addSuffix:
Stefan Vogel <sv@exept.de>
parents:
14232
diff
changeset
|
6505 |
See also #withSuffix:" |
11748 | 6506 |
|
6507 |
|prefixName| |
|
6508 |
||
6509 |
prefixName := self name. |
|
6510 |
aSuffix isEmptyOrNil ifTrue:[ |
|
19599 | 6511 |
^ self species named:prefixName |
11748 | 6512 |
]. |
6513 |
||
15811 | 6514 |
^ self species named: |
19599 | 6515 |
(prefixName |
6516 |
, self species suffixSeparator asString |
|
6517 |
, aSuffix asString) |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6518 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6519 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6520 |
'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
|
6521 |
'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
|
6522 |
'.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
|
6523 |
'.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
|
6524 |
'.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
|
6525 |
'.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
|
6526 |
'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
|
6527 |
'.' asFilename addSuffix:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6528 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6529 |
'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
|
6530 |
'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
|
6531 |
'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
|
6532 |
'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
|
6533 |
'.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
|
6534 |
'.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
|
6535 |
'.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
|
6536 |
'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
|
6537 |
'.' asFilename addSuffix:'o' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6538 |
'/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
|
6539 |
'/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
|
6540 |
'/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
|
6541 |
'/foo/bar.c/baz' asFilename addSuffix:'st' |
11748 | 6542 |
" |
6543 |
! |
|
6544 |
||
2906 | 6545 |
hasSuffix:aSuffixString |
6546 |
"return true if my suffix is the same as aString. |
|
6547 |
This cares for systems, where case is ignored in filenames" |
|
6548 |
||
6549 |
|mySuffix| |
|
6550 |
||
6551 |
mySuffix := self suffix. |
|
15811 | 6552 |
self species isCaseSensitive ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6553 |
^ mySuffix = aSuffixString |
2906 | 6554 |
]. |
6555 |
^ mySuffix asLowercase = aSuffixString asLowercase |
|
6556 |
||
6557 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6558 |
'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
|
6559 |
'abc.ST' asFilename hasSuffix:'st' |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
6560 |
'.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
|
6561 |
'.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
|
6562 |
'.foorc.sav' asFilename hasSuffix:'sav' |
2906 | 6563 |
" |
6564 |
||
6565 |
"Modified: 7.9.1997 / 02:55:25 / cg" |
|
6566 |
! |
|
6567 |
||
10155 | 6568 |
nameWithoutSuffix |
19440 | 6569 |
"return the receiver's name without the suffix. |
10155 | 6570 |
If the name has no suffix, the original name is returned." |
6571 |
||
6572 |
|nm idx idxFromEnd| |
|
6573 |
||
6574 |
nm := self baseName. |
|
15811 | 6575 |
idx := nm lastIndexOf:(self species suffixSeparator). |
10155 | 6576 |
(idx == 0) ifTrue:[^ nameString]. |
6577 |
"/ be careful: if the name consists only of suffix (i.e '.foo'), |
|
6578 |
"/ the suffix is considered empty. |
|
6579 |
(idx == 1) ifTrue:[^ nameString]. |
|
6580 |
||
6581 |
idxFromEnd := nm size - idx. |
|
6582 |
idx := nameString size - idxFromEnd. |
|
6583 |
||
6584 |
^ nameString copyTo:(idx - 1) |
|
6585 |
||
6586 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6587 |
'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
|
6588 |
'abc' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6589 |
'/abc' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6590 |
'/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
|
6591 |
'./abc' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6592 |
'./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
|
6593 |
'./.abc' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6594 |
'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
|
6595 |
'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
|
6596 |
'.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
|
6597 |
'.b.' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6598 |
'.b' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6599 |
'/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
|
6600 |
'/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
|
6601 |
'/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
|
6602 |
'/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
|
6603 |
'/foo/bar/baz/foo.c/bar.c' asFilename nameWithoutSuffix |
10155 | 6604 |
" |
6605 |
||
6606 |
"Modified: / 07-09-1995 / 11:15:42 / claus" |
|
6607 |
"Created: / 07-11-2006 / 13:55:18 / cg" |
|
6608 |
! |
|
6609 |
||
9453 | 6610 |
prefix |
6611 |
"return my prefix. |
|
6612 |
The suffix is the namepart after the final period character, |
|
6613 |
or the empty string, if the name does not contain a period." |
|
6614 |
||
6615 |
^ self prefixAndSuffix at:1 |
|
6616 |
||
6617 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6618 |
'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
|
6619 |
'abc' asFilename prefix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6620 |
'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
|
6621 |
'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
|
6622 |
'a.' asFilename prefix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6623 |
'.a' asFilename prefix |
9453 | 6624 |
" |
6625 |
||
6626 |
"Modified: / 07-09-1995 / 11:09:03 / claus" |
|
6627 |
"Created: / 13-07-2006 / 10:27:19 / fm" |
|
6628 |
! |
|
6629 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6630 |
prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6631 |
"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
|
6632 |
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
|
6633 |
the prefix everything before, except for the period. |
1517 | 6634 |
The directory name part is stripped off (i.e. the returned prefix |
16578 | 6635 |
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
|
6636 |
(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
|
6637 |
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
|
6638 |
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
|
6639 |
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
|
6640 |
'.foorc'. |
1517 | 6641 |
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
|
6642 |
Notice: |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6643 |
there is currently no known system which uses other than |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6644 |
the period character as suffixCharacter." |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6645 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6646 |
|nm idx| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6647 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6648 |
nm := self baseName. |
15811 | 6649 |
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
|
6650 |
"/ 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
|
6651 |
"/ the suffix is considered empty. |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
6652 |
((idx == 1) or:[ idx == 0 ]) ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6653 |
^ Array with:nm with:'' |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6654 |
]. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6655 |
^ Array |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6656 |
with:(nm copyTo:idx-1) |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6657 |
with:(nm copyFrom:idx+1) |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6658 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6659 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6660 |
'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
|
6661 |
'abc' asFilename prefixAndSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6662 |
'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
|
6663 |
'/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
|
6664 |
'a.' asFilename prefixAndSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6665 |
'.a' asFilename prefixAndSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6666 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6667 |
|parts| |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6668 |
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
|
6669 |
((parts at:1) , '.o') asFilename |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6670 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6671 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6672 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1517 | 6673 |
"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
|
6674 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6675 |
|
2906 | 6676 |
suffix |
6677 |
"return my suffix. |
|
6678 |
The suffix is the namepart after the final period character, |
|
6679 |
or the empty string, if the name does not contain a period." |
|
6680 |
||
6681 |
^ self prefixAndSuffix at:2 |
|
6682 |
||
6683 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6684 |
'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
|
6685 |
'abc' asFilename suffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6686 |
'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
|
6687 |
'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
|
6688 |
'a.' asFilename suffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6689 |
'.a' asFilename suffix |
2906 | 6690 |
" |
6691 |
||
6692 |
"Modified: 7.9.1995 / 11:09:03 / claus" |
|
6693 |
! |
|
6694 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6695 |
withSuffix:aSuffix |
19440 | 6696 |
"return a new filename for the receiver's name with a different suffix. |
6256 | 6697 |
If the name already has a suffix, the new suffix replaces it; |
1993 | 6698 |
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
|
6699 |
|
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
6700 |
|prefixName| |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
6701 |
|
10155 | 6702 |
prefixName := self nameWithoutSuffix. |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
6703 |
aSuffix isEmptyOrNil ifTrue:[ |
19599 | 6704 |
^ self species named:prefixName |
6262 | 6705 |
]. |
6706 |
||
15811 | 6707 |
^ self species named: |
19599 | 6708 |
(prefixName |
6709 |
, self class suffixSeparator asString |
|
6710 |
, aSuffix asString) |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6711 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6712 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6713 |
'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
|
6714 |
'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
|
6715 |
'.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
|
6716 |
'.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
|
6717 |
'.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
|
6718 |
'.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
|
6719 |
'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
|
6720 |
'.' asFilename withSuffix:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6721 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6722 |
'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
|
6723 |
'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
|
6724 |
'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
|
6725 |
'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
|
6726 |
'.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
|
6727 |
'.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
|
6728 |
'.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
|
6729 |
'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
|
6730 |
'.' asFilename withSuffix:'o' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6731 |
'/foo/bar/baz.st' asFilename withSuffix:'c' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6732 |
'/foo/bar/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
|
6733 |
'/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
|
6734 |
'/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
|
6735 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6736 |
|
10155 | 6737 |
"Modified: / 07-09-1995 / 11:15:42 / claus" |
6738 |
"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
|
6739 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6740 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6741 |
withoutSuffix |
19440 | 6742 |
"return a new filename for the receiver's name without the suffix. |
10155 | 6743 |
If the name has no suffix, a filename representing the same file as the receiver is returned." |
6744 |
||
6745 |
|n| |
|
6746 |
||
6747 |
n := self nameWithoutSuffix. |
|
6748 |
n = nameString ifTrue:[^ self]. |
|
15811 | 6749 |
^ self species named:n |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6750 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6751 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6752 |
'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
|
6753 |
'abc' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6754 |
'/abc' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6755 |
'/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
|
6756 |
'./abc' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6757 |
'./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
|
6758 |
'./.abc' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6759 |
'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
|
6760 |
'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
|
6761 |
'.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
|
6762 |
'.b.' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6763 |
'.b' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6764 |
'/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
|
6765 |
'/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
|
6766 |
'/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
|
6767 |
'/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
|
6768 |
'/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
|
6769 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6770 |
|
10155 | 6771 |
"Modified: / 07-09-1995 / 11:15:42 / claus" |
6772 |
"Modified: / 07-11-2006 / 13:57:45 / cg" |
|
174 | 6773 |
! ! |
6774 |
||
5597 | 6775 |
!Filename methodsFor:'testing'! |
6776 |
||
6777 |
isFilename |
|
6778 |
"return true, if the receiver is some kind of filename; |
|
6779 |
false is returned here - the method is redefined from Object." |
|
6780 |
||
6781 |
^true |
|
6782 |
||
6783 |
||
6784 |
! ! |
|
6785 |
||
10271 | 6786 |
!Filename methodsFor:'writing-files'! |
6787 |
||
14512 | 6788 |
appendingFileDo:aBlock |
6789 |
"create a append-stream on the receiver file, evaluate aBlock, passing that stream as arg, |
|
19088 | 6790 |
and return the block's value. |
14512 | 6791 |
If the file cannot be opened, an exception is raised. |
6792 |
Ensures that the stream is closed." |
|
6793 |
||
6794 |
|stream result| |
|
6795 |
||
6796 |
[ |
|
22448 | 6797 |
stream := self appendStream. |
6798 |
result := aBlock value:stream |
|
14512 | 6799 |
] ensure:[ |
22448 | 6800 |
stream close |
14512 | 6801 |
]. |
6802 |
^ result |
|
6803 |
||
6804 |
" |
|
14513 | 6805 |
'ttt' asFilename appendingFileDo:[:s | |
22448 | 6806 |
s nextPutLine:'hello'. |
6807 |
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
|
6808 |
] |
14512 | 6809 |
" |
6810 |
||
6811 |
"Created: / 09-11-2012 / 10:07:41 / sr" |
|
6812 |
! |
|
6813 |
||
23253 | 6814 |
contents:aStringOrByteArrayOrCollectionOfLines |
10271 | 6815 |
"create (or overwrite) a file given its contents as a collection of lines. |
6816 |
Raises an error, if the file is unwritable." |
|
6817 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6818 |
^ self |
23253 | 6819 |
writingFileDo:[:s | |
6820 |
aStringOrByteArrayOrCollectionOfLines isNonByteCollection ifTrue:[ |
|
6821 |
"a StringCollection or a collection of lines" |
|
6822 |
aStringOrByteArrayOrCollectionOfLines do:[:each | s nextPutLine:(each ? '')] |
|
6823 |
] ifFalse:[ |
|
6824 |
"something string-like" |
|
6825 |
aStringOrByteArrayOrCollectionOfLines isString ifFalse:[ |
|
6826 |
s binary |
|
6827 |
]. |
|
6828 |
s nextPutAll:aStringOrByteArrayOrCollectionOfLines |
|
6829 |
] |
|
6830 |
]. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6831 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6832 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6833 |
'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
|
6834 |
'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
|
6835 |
'foo3' asFilename contents:#[1 2 3 4 5] |
10271 | 6836 |
" |
6837 |
||
6838 |
"Created: / 11-12-2006 / 14:11:21 / cg" |
|
10779 | 6839 |
"Modified: / 08-11-2007 / 13:28:41 / cg" |
23253 | 6840 |
"Modified (format): / 01-08-2018 / 18:11:58 / Claus Gittinger" |
10271 | 6841 |
! |
6842 |
||
6843 |
writingFileDo:aBlock |
|
6844 |
"create a write-stream on the receiver file, evaluate aBlock, passing that stream as arg, |
|
19088 | 6845 |
and return the block's value. |
10271 | 6846 |
If the file cannot be opened, an exception is raised. |
6847 |
Ensures that the stream is closed." |
|
6848 |
||
6849 |
|stream result| |
|
6850 |
||
6851 |
[ |
|
22448 | 6852 |
stream := self writeStream. |
6853 |
result := aBlock value:stream |
|
10271 | 6854 |
] ensure:[ |
22448 | 6855 |
stream close |
10271 | 6856 |
]. |
6857 |
^ result |
|
6858 |
||
6859 |
" |
|
6860 |
'ttt' asFilename writingFileDo:[:s | |
|
22448 | 6861 |
s nextPutLine:'hello'. |
6862 |
s nextPutLine:'world'. |
|
10271 | 6863 |
] |
6864 |
" |
|
6865 |
||
6866 |
"Created: / 11-12-2006 / 14:09:39 / cg" |
|
6867 |
! ! |
|
6868 |
||
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
6869 |
!Filename class methodsFor:'documentation'! |
630 | 6870 |
|
6871 |
version |
|
18490 | 6872 |
^ '$Header$' |
12318 | 6873 |
! |
6874 |
||
6875 |
version_CVS |
|
18490 | 6876 |
^ '$Header$' |
630 | 6877 |
! ! |
6771 | 6878 |
|
14628 | 6879 |
|
2906 | 6880 |
Filename initialize! |