author | Claus Gittinger <cg@exept.de> |
Wed, 15 Feb 2017 22:29:42 +0100 | |
changeset 21455 | a657a28cab85 |
parent 21441 | ff5dc8186e55 |
child 21496 | 5ee730b45687 |
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 |
|
46 |
Instances of Filename do not nescessarily represent valid or existing |
|
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 |
|
1318 | 66 |
Beside lots of protocol to query for a files 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. |
2911 | 69 |
Especially the path-construction methods (i.e. #construct:) are highly |
1318 | 70 |
recommended in order to avoid having OS details (like directory separators |
71 |
being slash or backslash) spreaded in your application. |
|
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 |
||
3959 | 422 |
findDefaultDirectory |
423 |
"same as #defaultDirectory for ST80 compatibility" |
|
424 |
||
425 |
^ self defaultDirectory |
|
426 |
||
427 |
"Created: 20.6.1997 / 17:00:29 / cg" |
|
428 |
! |
|
429 |
||
430 |
fromComponents:aCollectionOfDirectoryNames |
|
431 |
"create & return a new filename from components given in |
|
432 |
aCollectionOfDirectoryNames. If the first component is the name of the |
|
433 |
root directory (i.e. '/') an absolute path-filename is returned." |
|
434 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
435 |
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
|
436 |
^ ConcreteClass fromComponents:aCollectionOfDirectoryNames |
3959 | 437 |
]. |
438 |
||
6802 | 439 |
^ self named:(self nameFromComponents:aCollectionOfDirectoryNames) |
3959 | 440 |
|
441 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
442 |
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
|
443 |
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
|
444 |
UnixFilename fromComponents:#('/' 'foo' 'bar' 'baz') |
8754 | 445 |
OpenVMSFilename fromComponents:#('foo' 'bar' 'baz') |
446 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
447 |
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
|
448 |
Filename fromComponents:#('/') |
3959 | 449 |
|
450 |
Filename fromComponents: |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
451 |
(Filename components:('.' asFilename pathName)) |
3959 | 452 |
|
453 |
Filename fromComponents: |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
454 |
(Filename components:('.' asFilename name)) |
3959 | 455 |
" |
456 |
||
457 |
"Modified: 8.9.1997 / 00:23:16 / cg" |
|
458 |
! |
|
459 |
||
460 |
fromUser |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
461 |
"show a box to enter a filename. |
3959 | 462 |
Return a filename instance or nil (if cancel was pressed)." |
463 |
||
464 |
|name| |
|
465 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
466 |
name := Dialog |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
467 |
requestFileName:'filename:' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
468 |
default:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
469 |
fromDirectory:(FileSelectionBox lastFileSelectionDirectory). |
8738 | 470 |
|
471 |
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
|
472 |
^ self named:name |
3978
b2babde0857b
use remembered last filenames directory (in #fromUser)
Claus Gittinger <cg@exept.de>
parents:
3959
diff
changeset
|
473 |
]. |
3959 | 474 |
^ nil |
475 |
||
476 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
477 |
Filename fromUser |
3959 | 478 |
" |
479 |
||
480 |
"Modified: 19.4.1996 / 13:57:44 / cg" |
|
481 |
! |
|
482 |
||
483 |
homeDirectory |
|
484 |
"return your homeDirectory. |
|
485 |
Some OperatingSystems do not support this - on those, the defaultDirectory |
|
17113 | 486 |
(which is the currentDirectory) is returned. |
487 |
Notice: services under windows also do not have a home directory." |
|
3959 | 488 |
|
489 |
|s| |
|
490 |
||
491 |
s := OperatingSystem getHomeDirectory. |
|
492 |
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
|
493 |
^ self defaultDirectory |
3959 | 494 |
]. |
495 |
^ self named:s |
|
496 |
||
497 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
498 |
Filename homeDirectory |
3959 | 499 |
" |
500 |
||
501 |
"Modified: 8.9.1997 / 00:25:23 / cg" |
|
502 |
! |
|
503 |
||
504 |
named:aString |
|
505 |
"return a filename for a directory named aString. |
|
506 |
This is the same as 'aString asFilename'." |
|
507 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
508 |
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
|
509 |
^ ConcreteClass named:aString |
3959 | 510 |
]. |
8738 | 511 |
^ self basicNew setName:aString |
3959 | 512 |
|
513 |
" |
|
514 |
Filename named:'/tmp/fooBar' |
|
515 |
" |
|
516 |
||
517 |
"Modified: 7.9.1997 / 23:30:06 / cg" |
|
518 |
! |
|
519 |
||
520 |
newTemporary |
|
521 |
"return a new unique filename - use this for temporary files. |
|
522 |
The filenames returned are '/tmp/stxtmp_xx_nn' where xx is our |
|
523 |
unix process id, and nn is a unique number, incremented with every |
|
524 |
call to this method. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
525 |
If any of the environment variables ST_TMPDIR or TMPDIR is set, |
4757 | 526 |
its value defines the temp directory. |
527 |
Notice, that no file is created by this - only a unique name |
|
15459 | 528 |
is generated. |
529 |
||
16787 | 530 |
DO NOT USE THIS FOR PLAIN FILES - IT IS UNSECURE use FileStream>>#newTemporary |
531 |
(the insecurity is due to a small chance for some other program to open/create |
|
532 |
the file, as only a name is generated here. However, chances are small as the name |
|
533 |
is reasonably random - but for security relevant applications, this may be relevant) |
|
534 |
" |
|
3959 | 535 |
|
9912 | 536 |
^ self newTemporaryIn:(self tempDirectory) |
3959 | 537 |
|
538 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
539 |
Filename newTemporary |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
540 |
Filename newTemporary |
3959 | 541 |
" |
542 |
||
543 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
|
544 |
"Modified: 7.3.1996 / 14:51:33 / cg" |
|
545 |
! |
|
546 |
||
9912 | 547 |
newTemporaryDirectory |
548 |
"return a new unique temporary directory - use this for temporary files. |
|
549 |
The directories returned are '/tmp/stxtmp_xx_nn' where xx is our |
|
550 |
unix process id, and nn is a unique number, incremented with every |
|
551 |
call to this method. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
552 |
If any of the environment variables ST_TMPDIR or TMPDIR is set, |
9912 | 553 |
its value defines the temp directory." |
554 |
||
555 |
^ self newTemporaryDirectoryIn:(self tempDirectory) |
|
556 |
! |
|
557 |
||
558 |
newTemporaryDirectoryIn:aDirectoryOrNil |
|
559 |
"return a new unique temporary directory in another directory, or the current dir. |
|
560 |
Use this for temporary files. |
|
561 |
The directories returned are '/tmp/stxtmp_xx_nn' where xx is our |
|
562 |
unix process id, and nn is a unique number, incremented with every |
|
563 |
call to this method. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
564 |
If any of the environment variables ST_TMPDIR or TMPDIR is set, |
9912 | 565 |
its value defines the temp directory." |
566 |
||
567 |
|tempdir| |
|
568 |
||
15811 | 569 |
tempdir := self newTemporaryIn:aDirectoryOrNil. |
9912 | 570 |
tempdir exists ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
571 |
tempdir recursiveRemove. |
9912 | 572 |
]. |
573 |
tempdir makeDirectory. |
|
574 |
^ tempdir |
|
575 |
! |
|
576 |
||
577 |
newTemporaryIn:aDirectoryOrNil |
|
3959 | 578 |
"return a new unique filename - use this for temporary files. |
579 |
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
|
580 |
where xx is our unix process id, and nn is a unique number, incremented |
3959 | 581 |
with every call to this method. |
582 |
Notice: only a unique filename object is created and returned - no physical |
|
583 |
file is created by this method (i.e. you have to send #writeStream or |
|
584 |
whatever to it in order to really create something). |
|
15459 | 585 |
See also: #newTemporary which looks for a good temp directory. |
586 |
||
587 |
DO NOT USE THIS FOR PLAIN FILES - IT IS UNSECURE use FileStream>>#newTemporaryIn:" |
|
3959 | 588 |
|
12617 | 589 |
^ self newTemporaryIn:aDirectoryOrNil nameTemplate:(self tempFileNameTemplate) |
3959 | 590 |
|
591 |
"temp files in '/tmp': |
|
592 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
593 |
Filename newTemporary |
19665 | 594 |
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
|
595 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
596 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
597 |
"temp files somewhere |
3959 | 598 |
(not recommended - use above since it can be controlled via shell variables): |
599 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
600 |
UnixFilename newTemporaryIn:'/tmp' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
601 |
UnixFilename newTemporaryIn:'/tmp' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
602 |
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
|
603 |
UnixFilename newTemporaryIn:'/' |
3959 | 604 |
" |
605 |
||
606 |
"a local temp file: |
|
607 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
608 |
Filename newTemporaryIn:'' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
609 |
Filename newTemporaryIn:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
610 |
Filename newTemporaryIn:'.' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
611 |
Filename newTemporaryIn:('source' asFilename) |
3959 | 612 |
" |
613 |
||
614 |
"Modified: / 7.9.1995 / 10:48:31 / claus" |
|
615 |
"Modified: / 11.8.1998 / 22:51:43 / cg" |
|
616 |
! |
|
617 |
||
9912 | 618 |
newTemporaryIn:aDirectoryOrNil nameTemplate:template |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
619 |
"return a new unique filename - use this for temporary files. |
9912 | 620 |
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
|
621 |
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
|
622 |
with every call to this method respectively. |
19665 | 623 |
If the template does not contain %-meta characters, and the file already exists, |
624 |
a sequence of _1, _2,... is appended to the name. This is dangerous, as it does not prevent race |
|
625 |
conditions (if two such files are created at the same time). |
|
626 |
||
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
627 |
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
|
628 |
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
|
629 |
whatever to it in order to really create something). |
15459 | 630 |
See also: #newTemporary which looks for a good temp directory. |
631 |
||
632 |
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
|
633 |
|
19665 | 634 |
|newTempFilename oldNameString nextSeqNr| |
8738 | 635 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
636 |
self isAbstract ifTrue:[ |
19665 | 637 |
^ ConcreteClass newTemporaryIn:aDirectoryOrNil nameTemplate:template |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
638 |
]. |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
639 |
|
8738 | 640 |
"although the above allows things to be redefined in concrete classes, |
641 |
the following should work on all systems ..." |
|
642 |
||
643 |
[ |
|
19665 | 644 |
|nameString fn| |
645 |
||
646 |
"Use random numbers in order to improve the security |
|
647 |
by making the generated names less predictable" |
|
648 |
nameString := template bindWith:(OperatingSystem getProcessId) with:(RandomGenerator nextLettersOrDigits:4). |
|
649 |
(oldNameString = nameString) ifTrue:[ |
|
650 |
"/ ouch - the given template seems to not generate unique file names. |
|
651 |
"/ append a sequence number |
|
652 |
nextSeqNr := (nextSeqNr ? 0) + 1. |
|
653 |
fn := nameString asFilename. |
|
654 |
nameString := fn withoutSuffix name,'_',nextSeqNr asString,'.' , fn suffix. |
|
655 |
]. |
|
656 |
||
657 |
aDirectoryOrNil isNil ifTrue:[ |
|
658 |
newTempFilename := self named:nameString |
|
659 |
] ifFalse:[ |
|
660 |
newTempFilename := aDirectoryOrNil asFilename construct:nameString |
|
661 |
]. |
|
662 |
oldNameString := nameString. |
|
8738 | 663 |
] doWhile:[ |
19665 | 664 |
"care for existing leftOver tempFiles |
665 |
from a previous boot of the OS |
|
666 |
i.e. my pid could be the same as when executed |
|
667 |
the last time before system reboot ...)" |
|
668 |
||
669 |
newTempFilename exists |
|
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
670 |
]. |
8738 | 671 |
^ newTempFilename |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
672 |
|
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
673 |
"temp files in '/tmp': |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
674 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
675 |
Filename newTemporary |
19665 | 676 |
Filename newTemporaryIn:nil nameTemplate:'out_%1_%2.txt' |
677 |
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
|
678 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
679 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
680 |
"temp files somewhere |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
681 |
(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
|
682 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
683 |
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
|
684 |
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
|
685 |
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
|
686 |
UnixFilename newTemporaryIn:'/' nameTemplate:'foo%1_%2' |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
687 |
" |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
688 |
|
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
689 |
"a local temp file: |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
690 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
691 |
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
|
692 |
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
|
693 |
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
|
694 |
Filename newTemporaryIn:('source' asFilename) nameTemplate:'foo%1_%2' |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
695 |
" |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
696 |
|
12918
a9de9243a951
changed: #newTemporaryIn:nameTemplate:
Claus Gittinger <cg@exept.de>
parents:
12910
diff
changeset
|
697 |
"Modified: / 07-09-1995 / 10:48:31 / claus" |
a9de9243a951
changed: #newTemporaryIn:nameTemplate:
Claus Gittinger <cg@exept.de>
parents:
12910
diff
changeset
|
698 |
"Modified: / 07-05-2010 / 11:46:05 / cg" |
6893
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
699 |
! |
9aa286d3a644
added newTemporary with template
Claus Gittinger <cg@exept.de>
parents:
6839
diff
changeset
|
700 |
|
4199 | 701 |
nullDevice |
702 |
"return the filename of the nullDevice (if available). |
|
703 |
returns nil, if the OperatingSystem does not support this." |
|
704 |
||
705 |
|s| |
|
706 |
||
8754 | 707 |
s := self nullFilename. |
4199 | 708 |
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
|
709 |
^ nil |
4199 | 710 |
]. |
711 |
^ self named:s |
|
712 |
||
713 |
" |
|
8754 | 714 |
Filename nullDevice |
715 |
UnixFilename nullDevice |
|
716 |
PCFilename nullDevice |
|
4199 | 717 |
" |
718 |
||
719 |
"Created: / 19.5.1999 / 12:24:26 / cg" |
|
720 |
! |
|
721 |
||
6256 | 722 |
remoteHost:remoteHostString rootComponents:aCollectionOfDirectoryNames |
723 |
"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
|
724 |
aCollectionOfDirectoryNames on a host named remoteHostString. |
6256 | 725 |
An absolute network-filename is returned." |
726 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
727 |
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
|
728 |
^ ConcreteClass remoteHost:remoteHostString |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
729 |
rootComponents:aCollectionOfDirectoryNames |
6256 | 730 |
]. |
731 |
||
10390 | 732 |
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
|
733 |
self error:'remote hosts are not supported by OS' |
10390 | 734 |
]. |
735 |
||
736 |
^ self rootComponents:aCollectionOfDirectoryNames |
|
737 |
||
738 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
739 |
'file:///tmp/test' asURI asFilename |
10390 | 740 |
" |
6256 | 741 |
! |
742 |
||
743 |
rootComponents:aCollectionOfDirectoryNames |
|
744 |
"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
|
745 |
aCollectionOfDirectoryNames. |
6256 | 746 |
An absolute path-filename is returned." |
747 |
||
748 |
|sep s| |
|
749 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
750 |
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
|
751 |
^ ConcreteClass rootComponents:aCollectionOfDirectoryNames |
6256 | 752 |
]. |
753 |
||
754 |
"/ fallBack - works on Unix & MSDOS |
|
755 |
||
8243 | 756 |
sep := self separatorString. |
18272 | 757 |
s := CharacterWriteStream new. |
6256 | 758 |
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
|
759 |
component ~= sep ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
760 |
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
|
761 |
] |
6256 | 762 |
]. |
763 |
s := s contents. |
|
764 |
s size == 0 ifTrue:[s := sep]. |
|
765 |
^ self named:s |
|
766 |
||
767 |
" |
|
8754 | 768 |
Filename rootComponents:#('/' 'foo' 'bar' 'baz') |
769 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
770 |
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
|
771 |
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
|
772 |
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
|
773 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
774 |
Filename rootComponents:#('/') |
6256 | 775 |
|
776 |
Filename rootComponents: |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
777 |
(Filename components:('.' asFilename pathName)) |
6256 | 778 |
|
779 |
Filename rootComponents: |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
780 |
(Filename components:('.' asFilename name)) |
6256 | 781 |
" |
782 |
||
783 |
"Modified: 8.9.1997 / 00:23:16 / cg" |
|
784 |
! |
|
785 |
||
3959 | 786 |
rootDirectory |
787 |
"return a filename for the root directory" |
|
788 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
789 |
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
|
790 |
^ ConcreteClass rootDirectory |
3959 | 791 |
]. |
792 |
||
793 |
"/ fallBack - works on Unix & MSDOS (but not on VMS) |
|
794 |
||
8243 | 795 |
^ self named:(self separatorString) |
3959 | 796 |
|
797 |
" |
|
798 |
Filename rootDirectory |
|
799 |
" |
|
800 |
||
801 |
"Modified: 8.9.1997 / 00:24:15 / cg" |
|
802 |
! |
|
803 |
||
804 |
rootDirectoryOnVolume:aVolumeName |
|
805 |
"return a filename for the root directory on some volume" |
|
806 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
807 |
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
|
808 |
^ ConcreteClass rootDirectoryOnVolume:aVolumeName |
3959 | 809 |
]. |
810 |
||
811 |
"/ fallBack - works on Unix (not on MSDOS or VMS) |
|
812 |
||
813 |
^ self rootDirectory |
|
814 |
||
815 |
" |
|
816 |
Filename rootDirectoryOnVolume:'/phys/idefix' |
|
817 |
Filename rootDirectoryOnVolume:'d:' |
|
818 |
" |
|
819 |
||
820 |
"Modified: / 5.10.1998 / 12:45:39 / cg" |
|
821 |
! |
|
822 |
||
823 |
tempDirectory |
|
824 |
"return the temp directory as a filename. |
|
825 |
If any of the environment variables STX_TMPDIR, ST_TMPDIR, |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
826 |
TMPDIR or TEMPDIR is set, its value defines the name, |
3959 | 827 |
otherwise, '/tmp' is used. (at least on unix ...). |
828 |
||
829 |
Notice: do not hardcode '/tmp' into your programs - things may be |
|
19599 | 830 |
different on other operating systems. Also, the user may want to set the |
831 |
TMPDIR environment variable to have her temp files somewhere else." |
|
3959 | 832 |
|
833 |
|tempDir| |
|
834 |
||
9806 | 835 |
TempDirectory isNil ifTrue:[ |
19599 | 836 |
tempDir := self named:(self defaultTempDirectoryName pathName). |
837 |
tempDir exists ifFalse:[ |
|
838 |
tempDir |
|
839 |
makeDirectory; |
|
840 |
addAccessRights:#(readUser readGroup readOthers |
|
841 |
writeUser writeGroup writeOthers |
|
842 |
executeUser executeGroup executeOthers |
|
843 |
removeOnlyByOwner). |
|
844 |
]. |
|
845 |
TempDirectory := DefaultTempDirectory := tempDir construct:'stx_tmp'. |
|
3959 | 846 |
]. |
10551
4924bf1ce2e3
#tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents:
10546
diff
changeset
|
847 |
|
4924bf1ce2e3
#tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents:
10546
diff
changeset
|
848 |
"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
|
849 |
by a cleanup (cron) job. |
19114 | 850 |
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
|
851 |
|
4924bf1ce2e3
#tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents:
10546
diff
changeset
|
852 |
TempDirectory exists ifFalse:[ |
19599 | 853 |
TempDirectory |
854 |
makeDirectory; |
|
855 |
addAccessRights:#(readUser readGroup readOthers |
|
856 |
writeUser writeGroup writeOthers |
|
857 |
executeUser executeGroup executeOthers |
|
858 |
removeOnlyByOwner). |
|
10551
4924bf1ce2e3
#tempDirectory - make sure, that it exists
Stefan Vogel <sv@exept.de>
parents:
10546
diff
changeset
|
859 |
]. |
9806 | 860 |
^ TempDirectory |
3959 | 861 |
|
862 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
863 |
Filename tempDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
864 |
Filename tempDirectory pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
865 |
Filename tempDirectory exists |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
866 |
Filename tempDirectory isWritable |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
867 |
(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
|
868 |
(Filename tempDirectory construct:'foo') remove |
3959 | 869 |
" |
870 |
||
9806 | 871 |
"Created: / 07-03-1996 / 14:51:18 / cg" |
13781 | 872 |
"Modified: / 07-10-2011 / 18:39:25 / cg" |
11757
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
873 |
! |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
874 |
|
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
875 |
tempDirectory:aFilename |
17048 | 876 |
"set the default temporary directory. |
877 |
This allows overwriting the automatically determined tmpDirectory |
|
878 |
by a knowledgable stand alone startup program. |
|
19114 | 879 |
Do not use elsewhere (and only if absolutely required)" |
11757
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
880 |
|
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
881 |
|temp| |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
882 |
|
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
883 |
aFilename isNil ifTrue:[ |
19599 | 884 |
TempDirectory := nil. |
885 |
^ self. |
|
11757
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
886 |
]. |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
887 |
|
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
888 |
temp := aFilename asFilename. |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
889 |
self assert:temp isDirectory. |
a2ce2d0ab680
new Filename class>>#tempFilename
Stefan Vogel <sv@exept.de>
parents:
11748
diff
changeset
|
890 |
TempDirectory := temp. |
16382 | 891 |
! |
892 |
||
893 |
trashDirectoryOrNil |
|
894 |
"if the underlying OS uses/supports a trash folder, |
|
895 |
return it. Otherwise return nil. |
|
896 |
Asks the OS for the pathname; for example, on OSX, '~/.Trash' is returned." |
|
897 |
||
898 |
|s| |
|
899 |
||
900 |
s := OperatingSystem getTrashDirectory. |
|
901 |
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
|
902 |
^ nil |
16382 | 903 |
]. |
904 |
^ self named:s |
|
905 |
||
906 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
907 |
Filename desktopDirectory |
16382 | 908 |
" |
909 |
||
910 |
"Created: / 16-05-2007 / 13:18:34 / cg" |
|
16648 | 911 |
! |
912 |
||
913 |
usersPrivateSmalltalkDirectory |
|
914 |
^ Filename homeDirectory / '.smalltalk' |
|
915 |
||
916 |
" |
|
917 |
Filename usersPrivateSmalltalkDirectory |
|
918 |
" |
|
3959 | 919 |
! ! |
920 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
921 |
!Filename class methodsFor:'defaults'! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
922 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
923 |
concreteClass |
6256 | 924 |
"different subclasses of Filename are used for different |
925 |
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
|
926 |
|
2906 | 927 |
^ ConcreteClass ? self |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
928 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
929 |
"Created: 14.2.1997 / 16:36:13 / cg" |
2906 | 930 |
"Modified: 7.9.1997 / 23:29:20 / cg" |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
931 |
! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
932 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
933 |
defaultClass |
6256 | 934 |
"different subclasses of Filename are used for different |
935 |
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
|
936 |
|
2906 | 937 |
^ ConcreteClass |
938 |
||
939 |
"Modified: 8.9.1997 / 00:36:01 / cg" |
|
7836 | 940 |
! |
941 |
||
942 |
defaultTempDirectoryName |
|
943 |
"return the default temp directory as a filename. |
|
944 |
This is used, if no special preferences were defined in |
|
945 |
any of the TEMP-environment variables (see tempDirectory)." |
|
946 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
947 |
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
|
948 |
^ ConcreteClass defaultTempDirectoryName |
7836 | 949 |
]. |
950 |
||
10994
1a3776d0b845
always return a fileName from defaultTempDirectoryName
fm
parents:
10969
diff
changeset
|
951 |
^ '/tmp' asFilename |
7836 | 952 |
|
953 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
954 |
Filename defaultTempDirectoryName |
7836 | 955 |
" |
956 |
||
957 |
"Modified: 7.9.1995 / 10:48:31 / claus" |
|
958 |
"Created: 7.3.1996 / 14:51:18 / cg" |
|
959 |
"Modified: 8.9.1997 / 00:24:53 / cg" |
|
19599 | 960 |
! |
961 |
||
962 |
defaultVolumeName |
|
963 |
^ '/' |
|
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
964 |
! ! |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
965 |
|
2922 | 966 |
!Filename class methodsFor:'misc'! |
967 |
||
3077 | 968 |
filterSeps:aFilenameString |
969 |
"ST80 compatibility: |
|
970 |
filter out (invalid) separators in aFilenameString. |
|
971 |
We recommend using #makeLegalFilename" |
|
972 |
||
16762 | 973 |
^ aFilenameString copyReplaceAll:(Character space) with:$_ ifNone:aFilenameString. |
3077 | 974 |
|
975 |
"Created: / 1.11.1997 / 12:39:50 / cg" |
|
3658 | 976 |
"Modified: / 18.7.1998 / 22:53:24 / cg" |
3077 | 977 |
! |
978 |
||
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
979 |
nameWithSpecialExpansions:aString |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
980 |
"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
|
981 |
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
|
982 |
|
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
983 |
|dir user cutIdx idx userInfo| |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
984 |
|
19670 | 985 |
(aString startsWith:$~) ifFalse:[ |
986 |
^ aString. |
|
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
987 |
]. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
988 |
|
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
989 |
aString size > 1 ifTrue:[ |
19670 | 990 |
idx := aString indexOf:self separator. |
991 |
idx == 0 ifTrue:[ |
|
992 |
"aString is '~user'" |
|
993 |
user := aString copyFrom:2. |
|
994 |
cutIdx := aString size + 1. |
|
995 |
] ifFalse:[ |
|
996 |
"aString is '~user/something'" |
|
997 |
user := aString copyFrom:2 to:(idx - 1). |
|
998 |
cutIdx := idx. |
|
999 |
]. |
|
1000 |
user notEmpty ifTrue:[ |
|
1001 |
userInfo := OperatingSystem userInfoOf:user. |
|
1002 |
userInfo notNil ifTrue:[ |
|
1003 |
dir := userInfo at:#dir ifAbsent:nil. |
|
1004 |
]. |
|
1005 |
dir isNil ifTrue:[ |
|
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1006 |
"/ ('Filename [info]: unknown user: ' , user) infoPrintCR. |
19670 | 1007 |
^ aString |
1008 |
]. |
|
1009 |
]. |
|
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1010 |
]. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1011 |
dir isNil ifTrue:[ |
19670 | 1012 |
"aString is '~' or '~/'" |
1013 |
dir := OperatingSystem getHomeDirectory. |
|
1014 |
cutIdx := 2. |
|
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1015 |
]. |
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 , (aString copyFrom:cutIdx) |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1018 |
|
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1019 |
" |
20709 | 1020 |
Filename nameWithSpecialExpansions:'~' |
1021 |
Filename nameWithSpecialExpansions:'~\work' |
|
1022 |
Filename nameWithSpecialExpansions:'~stefan' |
|
1023 |
Filename nameWithSpecialExpansions:'~stefan\work' |
|
1024 |
Filename nameWithSpecialExpansions:'~foo' |
|
1025 |
Filename nameWithSpecialExpansions:'~foo\bar' |
|
1026 |
" |
|
1027 |
||
1028 |
" |
|
1029 |
UnixFilename nameWithSpecialExpansions:'~' |
|
1030 |
UnixFilename nameWithSpecialExpansions:'~/work' |
|
1031 |
UnixFilename nameWithSpecialExpansions:'~stefan' |
|
1032 |
UnixFilename nameWithSpecialExpansions:'~stefan/work' |
|
1033 |
UnixFilename nameWithSpecialExpansions:'~foo' |
|
1034 |
UnixFilename nameWithSpecialExpansions:'~foo/bar' |
|
1035 |
" |
|
1036 |
||
1037 |
" |
|
1038 |
PCFilename nameWithSpecialExpansions:'~' |
|
1039 |
PCFilename nameWithSpecialExpansions:'~\work' |
|
1040 |
PCFilename nameWithSpecialExpansions:'~stefan' |
|
1041 |
PCFilename nameWithSpecialExpansions:'~stefan\work' |
|
1042 |
PCFilename nameWithSpecialExpansions:'~foo' |
|
1043 |
PCFilename nameWithSpecialExpansions:'~foo\bar' |
|
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 |
! |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
1046 |
|
16999 | 1047 |
possiblyQuotedPathname:aPath |
1048 |
"return a filename path usable as command line argument, |
|
1049 |
by quoting in double quotes if there are any embedded special characters. |
|
1050 |
On Unix systems, special characters might also be prefixed by a backslash character." |
|
1051 |
||
19670 | 1052 |
(aPath startsWith:$") ifFalse:[ |
1053 |
(aPath includes:Character space) ifTrue:[ |
|
1054 |
^ '"',aPath,'"' |
|
1055 |
]. |
|
16999 | 1056 |
]. |
1057 |
^ aPath |
|
1058 |
||
1059 |
||
1060 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1061 |
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
|
1062 |
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
|
1063 |
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
|
1064 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1065 |
! |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1066 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1067 |
suggest:aFilenameString |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1068 |
"return a fileNamestring based on the argument, |
3077 | 1069 |
which is legal on the current platform." |
1070 |
||
1071 |
^ self canonicalize:aFilenameString |
|
1072 |
||
1073 |
"Created: / 1.11.1997 / 12:42:39 / cg" |
|
2922 | 1074 |
! ! |
1075 |
||
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
1076 |
!Filename class methodsFor:'queries'! |
2 | 1077 |
|
10663
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1078 |
currentDirectoryName |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1079 |
"return a filename for the current directory" |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1080 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1081 |
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
|
1082 |
^ ConcreteClass currentDirectoryName |
10663
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1083 |
]. |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1084 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1085 |
"/ 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
|
1086 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1087 |
^ '.' |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1088 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1089 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1090 |
Filename currentDirectoryName |
10663
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1091 |
" |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1092 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1093 |
"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
|
1094 |
"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
|
1095 |
! |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1096 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1097 |
defaultDirectoryName |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1098 |
"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
|
1099 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1100 |
^ self defaultDirectory name |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1101 |
|
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1102 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1103 |
Filename defaultDirectoryName |
10663
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1104 |
" |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1105 |
! |
b95f903be43e
Make temp dir accessible to all users
Stefan Vogel <sv@exept.de>
parents:
10583
diff
changeset
|
1106 |
|
2963 | 1107 |
directorySuffix |
1108 |
"Return the OS dependent directory suffix string, or nil if there is none. |
|
1109 |
The default is nil here, redefined for VMS" |
|
1110 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1111 |
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
|
1112 |
^ ConcreteClass directorySuffix |
2963 | 1113 |
]. |
1114 |
||
1115 |
^ nil |
|
1116 |
! |
|
1117 |
||
1523 | 1118 |
errorReporter |
1119 |
"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
|
1120 |
|
1523 | 1121 |
^ FileStream |
1122 |
||
1123 |
"Created: 2.7.1996 / 12:30:25 / stefan" |
|
1124 |
! |
|
1125 |
||
440 | 1126 |
filenameCompletionFor:aString directory:inDirectory directoriesOnly:directoriesOnly filesOnly:filesOnly ifMultiple:aBlock |
1127 |
"perform filename completion on aString in some directory; |
|
1128 |
return the longest matching filename prefix as a string. |
|
1318 | 1129 |
The boolean directoriesOnly and filesOnly control respectively, |
1130 |
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
|
1131 |
If multiple files match, the exception block aBlock is evaluated with a |
1318 | 1132 |
filename representing the directory (where the match was done) as argument. |
440 | 1133 |
(this may be different from the inDirectory argument, if aString is absolute |
1134 |
or starts with ../)" |
|
1135 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1136 |
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
|
1137 |
^ ConcreteClass |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1138 |
filenameCompletionFor:aString |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1139 |
directory:inDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1140 |
directoriesOnly:directoriesOnly |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1141 |
filesOnly:filesOnly |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1142 |
ifMultiple:aBlock |
2906 | 1143 |
]. |
6839
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1144 |
^ 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
|
1145 |
! |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1146 |
|
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1147 |
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
|
1148 |
"perform filename completion on aString in some directory; |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1149 |
return the longest matching filename prefix as a string. |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1150 |
The boolean directoriesOnly and filesOnly control respectively, |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1151 |
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
|
1152 |
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
|
1153 |
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
|
1154 |
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
|
1155 |
(list of matched filenames) as arguments. |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1156 |
(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
|
1157 |
or starts with ../)" |
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1158 |
|
d5bc53f68bab
can evaluate block for matchList on filename completition
penk
parents:
6826
diff
changeset
|
1159 |
|s f matchSet nMatch name dir isAbsolute sep| |
2906 | 1160 |
|
5642
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1161 |
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
|
1162 |
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
|
1163 |
^ '' |
440 | 1164 |
]. |
1165 |
||
5642
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1166 |
sep := self separator. |
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1167 |
|
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1168 |
"/ 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
|
1169 |
|
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1170 |
f := self named:aString. |
3854
a13d0d489365
care for absolute fileNames in fileNameCompletion.
Claus Gittinger <cg@exept.de>
parents:
3852
diff
changeset
|
1171 |
isAbsolute := f isAbsolute. |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
1172 |
matchSet := f filenameCompletionIn:inDirectory. "/ BAD DESIGN: has side effect on f |
440 | 1173 |
dir := f directory. |
1174 |
||
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
1175 |
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
|
1176 |
|f isDir| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1177 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1178 |
isAbsolute ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1179 |
f := aFilename asFilename |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1180 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1181 |
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
|
1182 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1183 |
isDir := f isDirectory. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1184 |
directoriesOnly ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1185 |
isDir |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1186 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1187 |
filesOnly ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1188 |
isDir not |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1189 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1190 |
true |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1191 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1192 |
] |
440 | 1193 |
]. |
1194 |
||
6803 | 1195 |
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
|
1196 |
(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
|
1197 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1198 |
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
|
1199 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1200 |
aMultipleBlock notNil ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1201 |
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
|
1202 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1203 |
aBlock value:f |
440 | 1204 |
]. |
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
1205 |
|
440 | 1206 |
" |
1207 |
even with more than one possible completion, |
|
1208 |
f's name is now the common prefix |
|
1209 |
" |
|
1210 |
name := f asString. |
|
4323
8b3752e1b060
add trailing filename separator if match is a directory
Claus Gittinger <cg@exept.de>
parents:
4246
diff
changeset
|
1211 |
|
8b3752e1b060
add trailing filename separator if match is a directory
Claus Gittinger <cg@exept.de>
parents:
4246
diff
changeset
|
1212 |
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
|
1213 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1214 |
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
|
1215 |
" |
3752 | 1216 |
"/ 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
|
1217 |
false "directoriesOnly" ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1218 |
(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
|
1219 |
(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
|
1220 |
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
|
1221 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1222 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1223 |
] |
440 | 1224 |
]. |
1225 |
||
5642
87ad71e66acb
fileNameCompletion now does exactly that;
Claus Gittinger <cg@exept.de>
parents:
5602
diff
changeset
|
1226 |
s := name. |
440 | 1227 |
|
1228 |
"/ special: if there was no change, and the string represented |
|
1229 |
"/ 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
|
1230 |
((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
|
1231 |
(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
|
1232 |
(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
|
1233 |
^ s , sep asString |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1234 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1235 |
]. |
440 | 1236 |
]. |
1237 |
||
1238 |
^ s |
|
1318 | 1239 |
|
4131
f370ebc75bf9
fixed filenameCompletion for caseless systems (win32)
Claus Gittinger <cg@exept.de>
parents:
3978
diff
changeset
|
1240 |
"Modified: / 30.4.1999 / 09:40:13 / cg" |
615 | 1241 |
! |
1242 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1243 |
filesMatching:aPattern |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1244 |
"return a collection of strings, representing the names |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1245 |
of files matching aPattern. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1246 |
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
|
1247 |
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
|
1248 |
The returned strings are the expanded names, in the same form |
2550 | 1249 |
as given in pattern. |
1250 |
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
|
1251 |
|
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1252 |
|basePattern dir d files| |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1253 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1254 |
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
|
1255 |
^ ConcreteClass filesMatching:aPattern |
2906 | 1256 |
]. |
1257 |
||
1258 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
|
1259 |
||
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1260 |
dir := aPattern asFilename directoryName. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1261 |
basePattern := aPattern asFilename baseName. |
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1262 |
d := dir asFilename. |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
1263 |
files := dir asFilename filesMatchingWithoutDotDirs:basePattern. |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1264 |
dir = '.' ifTrue:[^ files]. |
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1265 |
^ files collect:[:base | d constructString:base]. |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1266 |
|
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1267 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1268 |
Filename filesMatching:'*' |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1269 |
Filename filesMatching:'/*' |
2547
4467d25fe057
filesMatching class method returns names as given
Claus Gittinger <cg@exept.de>
parents:
2503
diff
changeset
|
1270 |
Filename filesMatching:'/usr/local/*' |
2168
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1271 |
" |
649e90de1312
added filesMatching: in class protocol;
Claus Gittinger <cg@exept.de>
parents:
2013
diff
changeset
|
1272 |
|
2906 | 1273 |
"Modified: 8.9.1997 / 00:32:31 / cg" |
615 | 1274 |
! |
1275 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1276 |
isAbstract |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1277 |
"return true, if this is not a concrete class" |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1278 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1279 |
^ self == Filename |
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1280 |
! |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1281 |
|
2903 | 1282 |
isBadCharacter:aCharacter |
1283 |
"return true, if aCharacter is unallowed in a filename." |
|
1284 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1285 |
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
|
1286 |
^ ConcreteClass isBadCharacter:aCharacter |
2906 | 1287 |
]. |
1288 |
||
8095
bfbd1309a4a6
Use #codePoint instead of deprecated #asciiValue
Stefan Vogel <sv@exept.de>
parents:
8036
diff
changeset
|
1289 |
^ aCharacter isControlCharacter |
2903 | 1290 |
! |
1291 |
||
1292 |
isCaseSensitive |
|
1293 |
"return true, if filenames are case sensitive. |
|
19821 | 1294 |
We ask the OS about this, to be independent here. |
1295 |
This is not really correct, as the sensitivity may depend on |
|
1296 |
the paricular mounted file system (NFS, for example). |
|
1297 |
So we need a query on the instance side" |
|
2903 | 1298 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1299 |
self isAbstract ifTrue:[ |
19821 | 1300 |
^ ConcreteClass isCaseSensitive |
2906 | 1301 |
]. |
1302 |
||
2903 | 1303 |
^ OperatingSystem caseSensitiveFilenames |
2906 | 1304 |
|
1305 |
"Modified: 8.9.1997 / 00:33:32 / cg" |
|
2903 | 1306 |
! |
1307 |
||
615 | 1308 |
localNameStringFrom:aString |
1309 |
"ST-80 compatibility. |
|
1310 |
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
|
1311 |
GUESS: |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1312 |
does it strip off any volume characters and make a path relative ?" |
2922 | 1313 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1314 |
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
|
1315 |
^ ConcreteClass localNameStringFrom:aString |
2906 | 1316 |
]. |
1317 |
||
15227 | 1318 |
^ aString withoutPrefix:self separatorString |
615 | 1319 |
|
1320 |
"Modified: 7.9.1995 / 10:44:56 / claus" |
|
2906 | 1321 |
"Modified: 8.9.1997 / 00:33:51 / cg" |
615 | 1322 |
! |
1323 |
||
2908 | 1324 |
maxComponentLength |
1325 |
"return the maximum number of characters a filename component may |
|
1326 |
be in size. This depends on the OperatingSystem." |
|
1327 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1328 |
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
|
1329 |
^ ConcreteClass maxComponentLength |
2908 | 1330 |
]. |
1331 |
^ OperatingSystem maxFileNameLength |
|
1332 |
! |
|
1333 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1334 |
maxLength |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1335 |
"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
|
1336 |
This depends on the OperatingSystem." |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1337 |
|
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1338 |
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
|
1339 |
^ ConcreteClass maxLength |
2908 | 1340 |
]. |
1341 |
^ OperatingSystem maxPathLength |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1342 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1343 |
"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
|
1344 |
"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
|
1345 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
1346 |
|
3171 | 1347 |
nullFilename |
1348 |
"Return the OS dependent filename for /dev/null, or nil if there is none. |
|
1349 |
The default is nil here" |
|
1350 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1351 |
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
|
1352 |
^ ConcreteClass nullFilename |
3171 | 1353 |
]. |
1354 |
||
8754 | 1355 |
^ OperatingSystem getNullDevice |
3171 | 1356 |
|
1357 |
"Created: / 12.1.1998 / 12:15:30 / stefan" |
|
1358 |
! |
|
1359 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1360 |
parentDirectoryName |
615 | 1361 |
"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
|
1362 |
This is '..' for unix and dos-like systems. |
615 | 1363 |
(there may be more in the future." |
1364 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1365 |
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
|
1366 |
^ ConcreteClass parentDirectoryName |
2906 | 1367 |
]. |
1368 |
||
1369 |
^ OperatingSystem parentDirectoryName |
|
1370 |
||
1371 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1372 |
Filename parentDirectoryName |
2906 | 1373 |
" |
1374 |
||
1375 |
"Modified: 8.9.1997 / 00:34:39 / cg" |
|
615 | 1376 |
! |
1377 |
||
1378 |
separator |
|
1379 |
"return the file/directory separator. |
|
15246 | 1380 |
This is to be redefined in concrete classes." |
1381 |
||
1382 |
^ ConcreteClass separator |
|
8243 | 1383 |
|
1384 |
" |
|
8754 | 1385 |
Filename separator |
1386 |
PCFilename separator |
|
8243 | 1387 |
" |
2906 | 1388 |
|
1389 |
"Modified: 8.9.1997 / 00:20:28 / cg" |
|
615 | 1390 |
! |
1391 |
||
8243 | 1392 |
separatorString |
1393 |
"return the file/directory separator as a string." |
|
1394 |
||
1395 |
^ self separator asString |
|
1396 |
||
1397 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1398 |
Filename separatorString |
8243 | 1399 |
" |
1400 |
! |
|
1401 |
||
615 | 1402 |
suffixSeparator |
1403 |
"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
|
1404 |
Usually, this is $. for unix-like and msdos systems |
1318 | 1405 |
(there is currently no known system, where this differs)" |
615 | 1406 |
|
1407 |
^ $. |
|
1408 |
||
1409 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1410 |
Filename suffixSeparator |
615 | 1411 |
" |
1412 |
||
1413 |
"Modified: 7.9.1995 / 11:10:43 / claus" |
|
1318 | 1414 |
"Modified: 30.4.1996 / 12:14:25 / cg" |
615 | 1415 |
! |
1416 |
||
2906 | 1417 |
tempFileNameTemplate |
1418 |
"return a template for temporary files. |
|
1419 |
This is expanded with the current processID and a sequenceNumber |
|
1420 |
to generate a unique filename." |
|
1421 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1422 |
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
|
1423 |
^ ConcreteClass tempFileNameTemplate |
2906 | 1424 |
]. |
1425 |
||
1426 |
^ 'stxtmp_%1_%2' |
|
1427 |
||
1428 |
"Created: 8.9.1997 / 00:01:46 / cg" |
|
1429 |
"Modified: 8.9.1997 / 00:35:02 / cg" |
|
1430 |
! |
|
1431 |
||
615 | 1432 |
volumes |
1433 |
"ST-80 compatibility. |
|
2896 | 1434 |
GUESS: does it return the available drives on MSDOS systems ? |
1435 |
Q: what does this do on Unix systems ? (used in FileNavigator-goody)." |
|
1436 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1437 |
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
|
1438 |
^ ConcreteClass volumes |
2906 | 1439 |
]. |
1440 |
||
2896 | 1441 |
^ OperatingSystem getDriveList |
615 | 1442 |
|
8679 | 1443 |
" |
1444 |
Filename volumes |
|
1445 |
" |
|
615 | 1446 |
! ! |
1447 |
||
6383 | 1448 |
!Filename class methodsFor:'utilities'! |
1449 |
||
16389 | 1450 |
canonicalize:aPathString |
1451 |
"convert the argument, aPathString to a good format. |
|
1452 |
This should eliminate useless directory components (i.e. '././') |
|
1453 |
and useless tree walks (i.e. '../foo/..')." |
|
1454 |
||
1455 |
^ self nameFromComponents:(self canonicalizedNameComponents:aPathString) |
|
1456 |
||
1457 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1458 |
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
|
1459 |
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
|
1460 |
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
|
1461 |
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
|
1462 |
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
|
1463 |
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
|
1464 |
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
|
1465 |
Filename canonicalize:'cg/../../..' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1466 |
Filename canonicalize:'./' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1467 |
Filename canonicalize:'/home/.' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1468 |
Filename canonicalize:'/home/../..' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1469 |
Filename canonicalize:'//foo' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1470 |
Filename canonicalize:'///foo' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1471 |
Filename canonicalize:'//foo//bar' |
16389 | 1472 |
" |
1473 |
! |
|
1474 |
||
1475 |
canonicalizedNameComponents:aPathString |
|
1476 |
"convert the argument, aPathString to a good format. |
|
1477 |
This should eliminate useless directory components (i.e. '././') |
|
1478 |
and useless tree walks (i.e. '../foo/..'). |
|
1479 |
||
1480 |
Answer a sequenceable collection of name components." |
|
1481 |
||
1482 |
|comps newComps rootName dotDot dot| |
|
1483 |
||
1484 |
dotDot := self parentDirectoryName. |
|
1485 |
dot := self currentDirectoryName. |
|
1486 |
rootName := self separatorString. |
|
1487 |
||
1488 |
comps := self components:aPathString. |
|
1489 |
newComps := OrderedCollection new:comps size. |
|
1490 |
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
|
1491 |
eachComponent ~= dot ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1492 |
eachComponent = dotDot ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1493 |
(newComps isEmpty |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1494 |
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
|
1495 |
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
|
1496 |
newComps add:eachComponent |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1497 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1498 |
newComps removeLast |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1499 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1500 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1501 |
newComps add:eachComponent |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1502 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1503 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1504 |
]. |
16389 | 1505 |
"/ add current Directory if empty |
1506 |
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
|
1507 |
newComps add:dot. |
16389 | 1508 |
]. |
1509 |
^ newComps |
|
1510 |
||
1511 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1512 |
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
|
1513 |
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
|
1514 |
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
|
1515 |
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
|
1516 |
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
|
1517 |
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
|
1518 |
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
|
1519 |
Filename canonicalizedNameComponents:'cg/../../..' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1520 |
Filename canonicalizedNameComponents:'/' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1521 |
Filename canonicalizedNameComponents:'./' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1522 |
Filename canonicalizedNameComponents:'/.' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1523 |
Filename canonicalizedNameComponents:'/home/.' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1524 |
Filename canonicalizedNameComponents:'/home' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1525 |
Filename canonicalizedNameComponents:'/home/../..' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1526 |
Filename canonicalizedNameComponents:'//foo' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1527 |
Filename canonicalizedNameComponents:'///foo' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1528 |
Filename canonicalizedNameComponents:'//foo//bar' |
16389 | 1529 |
" |
1530 |
! |
|
1531 |
||
1532 |
components:aString |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1533 |
"separate the pathName given by aString into |
16578 | 1534 |
a collection containing the directory components and the file's name as |
16389 | 1535 |
the final component. |
1536 |
If the argument names an absolute path, the first component will be the |
|
1537 |
name of the root directory (i.e. '/')." |
|
1538 |
||
1539 |
|sep f vol rest components| |
|
1540 |
||
1541 |
self isAbstract ifTrue:[ |
|
19821 | 1542 |
^ ConcreteClass components:aString |
16389 | 1543 |
]. |
1544 |
||
1545 |
"/ the following works on Unix & MSDOS (but not on openVMS) |
|
1546 |
"/ However, MSDOS drive-letters and network drives are |
|
1547 |
"/ not correctly handled here. |
|
1548 |
||
1549 |
sep := self separator. |
|
1550 |
f := aString asFilename. |
|
1551 |
vol := f volume. |
|
1552 |
vol size ~~ 0 ifTrue:[ |
|
19821 | 1553 |
rest := f localPathName. |
16389 | 1554 |
] ifFalse:[ |
19821 | 1555 |
rest := aString |
16389 | 1556 |
]. |
1557 |
||
1558 |
components := rest asCollectionOfSubstringsSeparatedBy:sep. |
|
1559 |
(rest startsWith:sep) ifTrue:[ |
|
19821 | 1560 |
"first was a separator - root directory - restore" |
1561 |
(rest size > 1 and:[rest second = sep and:[vol isEmptyOrNil]]) ifTrue:[ |
|
1562 |
"keep \\ for windows network paths" |
|
1563 |
components at:1 put:(String with:sep with:sep). |
|
1564 |
] ifFalse:[ |
|
1565 |
components at:1 put:sep asString. |
|
1566 |
]. |
|
16389 | 1567 |
]. |
1568 |
||
1569 |
"/ prepend volume to first component (the root directory) |
|
1570 |
vol size ~~ 0 ifTrue:[ |
|
20694 | 1571 |
vol last = $: ifTrue:[ |
1572 |
vol := vol, (components at:1). |
|
1573 |
]. |
|
1574 |
components at:1 put:vol. |
|
1575 |
]. |
|
1576 |
components := components select:[:each| each notEmpty]. |
|
1577 |
||
16389 | 1578 |
^ components |
1579 |
||
1580 |
" |
|
19821 | 1581 |
Unix: |
1582 |
UnixFilename components:'/foo/bar/baz' |
|
1583 |
UnixFilename components:'/' |
|
1584 |
UnixFilename components:'//' |
|
1585 |
UnixFilename components:'foo/bar/baz' |
|
1586 |
UnixFilename components:'foo/bar' |
|
1587 |
UnixFilename components:'foo' |
|
1588 |
UnixFilename components:'/foo' |
|
1589 |
UnixFilename components:'//foo' |
|
1590 |
UnixFilename components:'' |
|
1591 |
||
1592 |
Windows: |
|
1593 |
PCFilename components:'\' |
|
1594 |
PCFilename components:'\foo' |
|
1595 |
PCFilename components:'\foo\' |
|
1596 |
PCFilename components:'\foo\bar' |
|
1597 |
PCFilename components:'\foo\bar\' |
|
1598 |
PCFilename components:'c:' |
|
1599 |
PCFilename components:'c:\' |
|
1600 |
PCFilename components:'c:\foo' |
|
1601 |
PCFilename components:'c:\foo\' |
|
1602 |
PCFilename components:'c:\foo\bar' |
|
1603 |
PCFilename components:'c:\foo\bar\' |
|
1604 |
PCFilename components:'\\idefix' |
|
1605 |
PCFilename components:'\\idefix\home' |
|
1606 |
PCFilename components:'\\idefix\home\bar' |
|
16389 | 1607 |
" |
1608 |
||
1609 |
"Modified: / 24.9.1998 / 19:10:52 / cg" |
|
1610 |
! |
|
1611 |
||
19821 | 1612 |
filesMatchingGLOB:pattern |
1613 |
"does a GLOB filename expansion. |
|
1614 |
Generates and returns a possibly empty list of files which match |
|
1615 |
the given glob pattern" |
|
1616 |
||
1617 |
^ OrderedCollection withCollectedContents:[:coll | |
|
1618 |
pattern asFilename filesMatchingGLOBDo:[:each | coll add:each] |
|
1619 |
] |
|
1620 |
||
1621 |
" |
|
1622 |
Filename filesMatchingGLOB:'./A*' |
|
1623 |
Filename filesMatchingGLOB:'/etc/A*' |
|
1624 |
Filename filesMatchingGLOB:'/*/A*' |
|
1625 |
'.' asFilename filesMatchingGLOB:'A*' |
|
1626 |
" |
|
1627 |
! |
|
1628 |
||
6802 | 1629 |
nameFromComponents:aCollectionOfDirectoryNames |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1630 |
"return a filenameString from components given in aCollectionOfDirectoryNames. |
6802 | 1631 |
If the first component is the name of the root directory (i.e. '/'), |
1632 |
an absolute path-string is returned." |
|
1633 |
||
1634 |
|sep s| |
|
1635 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
1636 |
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
|
1637 |
^ ConcreteClass nameFromComponents:aCollectionOfDirectoryNames |
6802 | 1638 |
]. |
1639 |
||
1640 |
"/ fallBack - works on Unix & MSDOS |
|
1641 |
||
8243 | 1642 |
sep := self separatorString. |
6802 | 1643 |
s := ''. |
1644 |
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
|
1645 |
index == 1 ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1646 |
s := component. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1647 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1648 |
(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
|
1649 |
s := s , component |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1650 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1651 |
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
|
1652 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1653 |
]. |
6802 | 1654 |
]. |
1655 |
^ s |
|
1656 |
||
1657 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1658 |
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
|
1659 |
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
|
1660 |
Filename nameFromComponents:#('/') |
7074 | 1661 |
|
1662 |
|comps| |
|
1663 |
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
|
1664 |
Filename nameFromComponents:comps |
7074 | 1665 |
|
1666 |
|comps| |
|
1667 |
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
|
1668 |
Filename nameFromComponents:comps |
7074 | 1669 |
|
1670 |
|comps| |
|
1671 |
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
|
1672 |
Filename nameFromComponents:comps |
7074 | 1673 |
|
1674 |
|comps| |
|
1675 |
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
|
1676 |
Filename nameFromComponents:comps |
7074 | 1677 |
|
1678 |
|comps| |
|
1679 |
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
|
1680 |
Filename nameFromComponents:comps |
7074 | 1681 |
|
1682 |
|comps| |
|
1683 |
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
|
1684 |
Filename nameFromComponents:comps |
7074 | 1685 |
|
1686 |
|comps| |
|
1687 |
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
|
1688 |
Filename nameFromComponents:comps |
6802 | 1689 |
" |
1690 |
||
1691 |
"Modified: 8.9.1997 / 00:23:16 / cg" |
|
1692 |
! |
|
1693 |
||
6383 | 1694 |
readingFile:aPathName do:aBlock |
20158 | 1695 |
"Create a read stream on a file, evaluate aBlock, passing that stream, |
1696 |
and return the block's value. |
|
6383 | 1697 |
Ensures that the stream is closed." |
1698 |
||
6529 | 1699 |
^ aPathName asFilename readingFileDo:aBlock. |
1700 |
||
1701 |
" |
|
1702 |
read the first line from some file: |
|
1703 |
||
1704 |
|rslt| |
|
1705 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1706 |
rslt := |
20158 | 1707 |
Filename |
1708 |
readingFile:'/etc/passwd' |
|
1709 |
do:[:s | |
|
1710 |
s nextLine |
|
1711 |
]. |
|
6529 | 1712 |
Transcript showCR:rslt. |
1713 |
" |
|
1714 |
||
1715 |
" |
|
1716 |
find all used shells in /etc/passwd and count their usage: |
|
1717 |
||
6383 | 1718 |
|rslt| |
1719 |
||
6529 | 1720 |
rslt := |
20158 | 1721 |
Filename |
1722 |
readingFile:'/etc/passwd' |
|
1723 |
do: |
|
1724 |
[:s | |
|
1725 |
|shells| |
|
1726 |
||
1727 |
shells := Bag new. |
|
1728 |
s linesDo: |
|
1729 |
[:line | |
|
1730 |
|parts| |
|
1731 |
||
1732 |
parts := line asCollectionOfSubstringsSeparatedBy:$:. |
|
1733 |
shells add:(parts seventh). |
|
1734 |
]. |
|
1735 |
shells contents |
|
1736 |
]. |
|
6529 | 1737 |
Transcript showCR:rslt. |
1738 |
" |
|
6383 | 1739 |
! ! |
1740 |
||
7261 | 1741 |
!Filename methodsFor:'Compatibility-VW5.4'! |
6139 | 1742 |
|
1743 |
asLogicalFileSpecification |
|
1744 |
^ self |
|
1745 |
||
1746 |
"Created: / 30.10.2001 / 17:31:10 / cg" |
|
6447 | 1747 |
! |
1748 |
||
10583 | 1749 |
canBeWritten |
1750 |
"same as isWritable - for ST-80 compatibility" |
|
1751 |
||
1752 |
^ self isWritable |
|
1753 |
||
1754 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1755 |
'/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
|
1756 |
'/tmp' asFilename canBeWritten |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1757 |
'Makefile' asFilename canBeWritten |
10583 | 1758 |
" |
1759 |
! |
|
1760 |
||
7596 | 1761 |
definitelyExists |
1762 |
"for now - a kludge" |
|
1763 |
||
1764 |
^ self exists |
|
1765 |
! |
|
1766 |
||
6447 | 1767 |
extension |
6454 | 1768 |
"return the receiver's extension; |
1769 |
that is the characters from and including |
|
1770 |
the last period or nil, if there is none." |
|
1771 |
||
1772 |
|string idx| |
|
1773 |
||
1774 |
string := self asString. |
|
1775 |
idx := string lastIndexOf:$.. |
|
1776 |
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
|
1777 |
^ string copyFrom:idx |
6454 | 1778 |
]. |
1779 |
^ nil |
|
1780 |
||
1781 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1782 |
'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
|
1783 |
'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
|
1784 |
'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
|
1785 |
'foo.' asFilename extension |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1786 |
'foo' asFilename extension |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1787 |
'.login' asFilename extension |
6454 | 1788 |
" |
6139 | 1789 |
! ! |
1790 |
||
615 | 1791 |
!Filename methodsFor:'comparing'! |
1792 |
||
16255 | 1793 |
< aFilename |
1794 |
"compare file names - used for sorting" |
|
1795 |
||
1796 |
^ self asString < aFilename asString |
|
1797 |
! |
|
1798 |
||
615 | 1799 |
= aFilename |
1800 |
"return true, if the argument represents the same filename" |
|
1801 |
||
1802 |
|str| |
|
1803 |
||
1804 |
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
|
1805 |
str := aFilename asString. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1806 |
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
|
1807 |
^ nameString = str |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1808 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1809 |
^ nameString sameAs:str |
615 | 1810 |
]. |
1811 |
^ false |
|
1812 |
! |
|
1813 |
||
5877 | 1814 |
contentsIsPrefixOf:aFilename |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1815 |
"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
|
1816 |
is the same as or a prefix of the contents of the file represented by the argument, aFilename. |
16578 | 1817 |
This compares the files' actual contents; not the filenames." |
3868 | 1818 |
|
8771 | 1819 |
|f2 s1 s2 bufferSize buffer1 buffer2 n| |
1820 |
||
1821 |
bufferSize := 8192 * 4. |
|
4979 | 1822 |
|
1823 |
f2 := aFilename asFilename. |
|
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1824 |
self fileSize > f2 fileSize ifTrue:[^ false]. |
3868 | 1825 |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1826 |
[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1827 |
s1 := self readStream. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1828 |
s2 := f2 readStream. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1829 |
s1 binary. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1830 |
s2 binary. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1831 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1832 |
buffer1 := ByteArray new:bufferSize. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1833 |
buffer2 := ByteArray new:bufferSize. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1834 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1835 |
[s1 atEnd] whileFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1836 |
n := s1 nextBytes:bufferSize into:buffer1 startingAt:1. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1837 |
n == 0 ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1838 |
"/ receiver shorter. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1839 |
^ true |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1840 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1841 |
(s2 nextBytes:n into:buffer2 startingAt:1) ~~ n ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1842 |
"/ aFilename shorter |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1843 |
^ false |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1844 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1845 |
buffer1 ~= buffer2 ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1846 |
^ false |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1847 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1848 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1849 |
"/ receiver shorter or same size. |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
1850 |
] ensure:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1851 |
s1 notNil ifTrue:[s1 close]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1852 |
s2 notNil ifTrue:[s2 close]. |
3868 | 1853 |
]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1854 |
^ true |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1855 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1856 |
" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1857 |
|s| |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1858 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1859 |
s := 'testFile1' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1860 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1861 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1862 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1863 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1864 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1865 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1866 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1867 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1868 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1869 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1870 |
|
5877 | 1871 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifFalse:[self halt]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1872 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1873 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1874 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1875 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1876 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1877 |
s nextPutAll:'44444'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1878 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1879 |
|
5877 | 1880 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifFalse:[self halt]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1881 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1882 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1883 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1884 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1885 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1886 |
|
5877 | 1887 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifTrue:[self halt]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1888 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1889 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1890 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1891 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1892 |
s nextPutAll:'33334'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1893 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1894 |
|
5877 | 1895 |
('testFile1' asFilename contentsIsPrefixOf:'testFile2' ) ifTrue:[self halt]. |
1896 |
||
1897 |
" |
|
1898 |
! |
|
1899 |
||
1900 |
contentsStartsWithContentsOf:aFilename |
|
1901 |
"return true if the contents of the file represented by aFilename |
|
1902 |
is the same as or a prefix of the contents of the file represented by the receiver. |
|
16578 | 1903 |
This compares the files' actual contents; not the filenames." |
5877 | 1904 |
|
1905 |
^ aFilename asFilename contentsIsPrefixOf:self |
|
1906 |
||
1907 |
" |
|
1908 |
|s| |
|
1909 |
||
1910 |
s := 'testFile1' asFilename writeStream. |
|
1911 |
s nextPutAll:'11111'. |
|
1912 |
s nextPutAll:'22222'. |
|
1913 |
s nextPutAll:'33333'. |
|
1914 |
s close. |
|
1915 |
||
1916 |
s := 'testFile2' asFilename writeStream. |
|
1917 |
s nextPutAll:'11111'. |
|
1918 |
s nextPutAll:'22222'. |
|
1919 |
s nextPutAll:'33333'. |
|
1920 |
s close. |
|
1921 |
||
1922 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifFalse:[self halt]. |
|
1923 |
||
1924 |
s := 'testFile2' asFilename writeStream. |
|
1925 |
s nextPutAll:'11111'. |
|
1926 |
s nextPutAll:'22222'. |
|
1927 |
s nextPutAll:'33333'. |
|
1928 |
s nextPutAll:'44444'. |
|
1929 |
s close. |
|
1930 |
||
1931 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifFalse:[self halt]. |
|
1932 |
||
1933 |
s := 'testFile2' asFilename writeStream. |
|
1934 |
s nextPutAll:'11111'. |
|
1935 |
s nextPutAll:'22222'. |
|
1936 |
s close. |
|
1937 |
||
1938 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifTrue:[self halt]. |
|
1939 |
||
1940 |
s := 'testFile2' asFilename writeStream. |
|
1941 |
s nextPutAll:'11111'. |
|
1942 |
s nextPutAll:'22222'. |
|
1943 |
s nextPutAll:'33334'. |
|
1944 |
s close. |
|
1945 |
||
1946 |
('testFile2' asFilename contentsStartsWithContentsOf:'testFile1' ) ifTrue:[self halt]. |
|
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1947 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1948 |
" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1949 |
! |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1950 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1951 |
hash |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1952 |
"return an integer useful as a hash-key" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1953 |
|
15811 | 1954 |
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
|
1955 |
"/ 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
|
1956 |
"/ 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
|
1957 |
"/ 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
|
1958 |
^ nameString asUppercase hash |
11424
c169cc34afe9
fixed hash for case-insensitive files
Claus Gittinger <cg@exept.de>
parents:
11406
diff
changeset
|
1959 |
]. |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1960 |
^ nameString hash |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1961 |
! |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1962 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1963 |
sameContentsAs:aFilename |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1964 |
"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
|
1965 |
same contents as the file represented by the argument, aFilename. |
16578 | 1966 |
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
|
1967 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1968 |
|f2| |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1969 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1970 |
f2 := aFilename asFilename. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1971 |
f2 fileSize = self fileSize ifFalse:[^ false]. |
5877 | 1972 |
^ self contentsIsPrefixOf:f2. |
3868 | 1973 |
|
1974 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
1975 |
'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
|
1976 |
'Make.proto' asFilename sameContentsAs:'Make.proto' |
3868 | 1977 |
" |
5876
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1978 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1979 |
" |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1980 |
|s| |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1981 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1982 |
s := 'testFile1' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1983 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1984 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1985 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1986 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1987 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1988 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1989 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1990 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1991 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1992 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1993 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1994 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifFalse:[self halt]. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1995 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1996 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1997 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1998 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
1999 |
s nextPutAll:'33333'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2000 |
s nextPutAll:'44444'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2001 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2002 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2003 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifTrue:[self halt]. |
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 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2006 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2007 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2008 |
s close. |
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 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifTrue:[self halt]. |
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 |
s := 'testFile2' asFilename writeStream. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2013 |
s nextPutAll:'11111'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2014 |
s nextPutAll:'22222'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2015 |
s nextPutAll:'33334'. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2016 |
s close. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2017 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2018 |
('testFile1' asFilename sameContentsAs:'testFile2' ) ifTrue:[self halt]. |
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2019 |
|
e38638bad111
added #contentsIsPartOf (prefix contents check)
Claus Gittinger <cg@exept.de>
parents:
5866
diff
changeset
|
2020 |
" |
615 | 2021 |
! ! |
2022 |
||
2023 |
!Filename methodsFor:'converting'! |
|
2024 |
||
2025 |
asAbsoluteFilename |
|
2026 |
"return the receiver converted to a filename with |
|
2027 |
an absolute pathname." |
|
2028 |
||
15811 | 2029 |
^ self species named:self pathName |
7332 | 2030 |
|
2031 |
" |
|
2032 |
'.' asFilename |
|
2033 |
'.' asFilename asAbsoluteFilename |
|
9173 | 2034 |
'c:' asFilename asAbsoluteFilename |
7332 | 2035 |
" |
615 | 2036 |
! |
2037 |
||
10769 | 2038 |
asAutoDeletedFilename |
13653
6821135a2e1a
comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents:
13424
diff
changeset
|
2039 |
"will automatically delete myself, when no longer referenced" |
6821135a2e1a
comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents:
13424
diff
changeset
|
2040 |
|
11784 | 2041 |
^ AutoDeletedFilename basicNew setName:self name |
13653
6821135a2e1a
comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents:
13424
diff
changeset
|
2042 |
|
6821135a2e1a
comment/format in: #asAutoDeletedFilename
Claus Gittinger <cg@exept.de>
parents:
13424
diff
changeset
|
2043 |
"Modified (comment): / 07-09-2011 / 12:20:59 / cg" |
10769 | 2044 |
! |
2045 |
||
21390 | 2046 |
asBackupFilename |
2047 |
"return the receiver converted to a backup filename." |
|
2048 |
||
2049 |
"/ ^ self species named:(nameString, '~'). |
|
2050 |
"/ ^ self species named:(self directoryName, '/~', self baseName). |
|
2051 |
||
2052 |
^ self addSuffix:'bak' |
|
2053 |
||
2054 |
" |
|
2055 |
'bla' asFilename asBackupFilename |
|
2056 |
'/home/user/directory/bla' asFilename asBackupFilename |
|
2057 |
'directory/bla' asFilename asBackupFilename |
|
2058 |
" |
|
2059 |
||
2060 |
"Created: / 09-02-2017 / 12:57:28 / stefan" |
|
2061 |
! |
|
2062 |
||
6802 | 2063 |
asCanonicalizedFilename |
2064 |
"return the receiver converted to a filename without intermediate ..'s and .'s |
|
2065 |
(similar to an absolute pathname, but symlinks are not resolved)." |
|
2066 |
||
15811 | 2067 |
^ self species named:(self species canonicalize:nameString) |
7074 | 2068 |
|
2069 |
" |
|
2070 |
'c:\test\work' asFilename asCanonicalizedFilename |
|
2071 |
'/test/work' asFilename asCanonicalizedFilename |
|
2072 |
" |
|
6802 | 2073 |
! |
2074 |
||
615 | 2075 |
asFilename |
20413 | 2076 |
"return the receiver converted to a filename; here, that's the receiver itself." |
2077 |
||
2078 |
"That's pretty easy here :-)" |
|
615 | 2079 |
^ self |
1970 | 2080 |
|
2081 |
"Modified: 12.11.1996 / 12:40:03 / cg" |
|
615 | 2082 |
! |
2083 |
||
21390 | 2084 |
asNonBackupFilename |
2085 |
"return the receiver converted to a backup filename." |
|
2086 |
||
2087 |
nameString last == $~ ifTrue:[ |
|
2088 |
^ self class named:(nameString copyButLast:1). |
|
2089 |
]. |
|
2090 |
(self hasSuffix:'bak') ifTrue:[ |
|
2091 |
^ self withoutSuffix |
|
2092 |
]. |
|
2093 |
^ self. |
|
2094 |
||
2095 |
" |
|
2096 |
'bla.bak' asFilename asNonBackupFilename |
|
2097 |
'/home/user/directory/bla.bak' asFilename asNonBackupFilename |
|
2098 |
'directory/bla.bak' asFilename asNonBackupFilename |
|
2099 |
'directory/bla~' asFilename asNonBackupFilename |
|
2100 |
" |
|
2101 |
||
2102 |
"Created: / 09-02-2017 / 14:01:47 / stefan" |
|
2103 |
! |
|
2104 |
||
615 | 2105 |
asString |
2106 |
"return the receiver converted to a string" |
|
2107 |
||
2108 |
^ nameString |
|
2109 |
! |
|
2110 |
||
6256 | 2111 |
asURI |
15001 | 2112 |
"return the receiver converted to a file URI" |
6256 | 2113 |
|
2114 |
^ FileURI fromFilename:self. |
|
2115 |
! |
|
2116 |
||
15001 | 2117 |
asURL |
2118 |
"return an URL-object from myself" |
|
2119 |
||
2120 |
^ URL fromString:self pathName. |
|
2121 |
! |
|
2122 |
||
19665 | 2123 |
asUniqueFilename |
2124 |
"I a file by my name already exists, return a new filename with a unique string appended. |
|
2125 |
here, a somewhat naive strategy is performed, by trying _1, _2,... until a new name is generated." |
|
2126 |
||
2127 |
|fn baseFn nextSeqNr| |
|
2128 |
||
2129 |
fn := baseFn := self. |
|
2130 |
nextSeqNr := 0. |
|
2131 |
[ fn exists ] whileTrue:[ |
|
20453 | 2132 |
|newFn suff| |
19665 | 2133 |
|
2134 |
nextSeqNr := (nextSeqNr ? 0) + 1. |
|
20453 | 2135 |
suff := baseFn suffix. |
2136 |
suff notEmpty ifTrue:[ suff := '.',suff ]. |
|
2137 |
fn := self class named:((baseFn withoutSuffix name,'_',nextSeqNr asString),suff). |
|
19665 | 2138 |
]. |
2139 |
^ fn |
|
2140 |
||
2141 |
" |
|
2142 |
'aaa.txt' asFilename contents:'bla'. |
|
20453 | 2143 |
'aaa.1.2.3.apk.txt' asFilename asUniqueFilename contents:'bla2'. |
19665 | 2144 |
'aaa.txt' asFilename asUniqueFilename contents:'bla3'. |
2145 |
'aaa.txt' asFilename asUniqueFilename contents:'bla4'. |
|
2146 |
#('aaa.txt' 'aaa_1.txt' 'aaa_2.txt' 'aaa_3.txt') do:[:f | f asFilename delete]. |
|
2147 |
" |
|
2148 |
! |
|
2149 |
||
5890 | 2150 |
components |
19440 | 2151 |
"return the receiver's filename components - that is the name of each directory |
5890 | 2152 |
along the pathName (that DOES include the root directory)" |
2153 |
||
15811 | 2154 |
^ self species components:self name |
5890 | 2155 |
|
2156 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2157 |
'.' asFilename asAbsoluteFilename components |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2158 |
'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
|
2159 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2160 |
! |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2161 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2162 |
makeLegalFilename |
19440 | 2163 |
"convert the receiver's name to be a legal filename. |
1970 | 2164 |
This removes/replaces invalid characters and/or compresses |
2165 |
the name as required by the OS. |
|
615 | 2166 |
The implementation may change in the future to be more |
2167 |
OS specific." |
|
2168 |
||
2169 |
" |
|
2170 |
actually, in Unix spaces are allowed - but it makes life |
|
2171 |
so hard; therefore, replace them by underscores ... |
|
2172 |
" |
|
16761 | 2173 |
nameString := nameString copyReplaceAll:(Character space) with:$_ ifNone:nameString. |
615 | 2174 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2175 |
need more - especially on SYS5.3 type systems, |
615 | 2176 |
we may want to contract the fileName to 14 characters. |
2177 |
" |
|
2178 |
^ self |
|
2179 |
||
2180 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2181 |
'hello world' asFilename makeLegalFilename |
615 | 2182 |
" |
1970 | 2183 |
|
3658 | 2184 |
"Modified: / 20.7.1998 / 13:16:51 / cg" |
2707
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2185 |
! |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2186 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2187 |
withEncoding:encodingSymbol |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2188 |
"dummy for now - for ST80 compatibility" |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2189 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2190 |
^ self |
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2191 |
|
280456505357
added #findDefaultDirectory and #withEncoding:
Claus Gittinger <cg@exept.de>
parents:
2630
diff
changeset
|
2192 |
"Created: 20.6.1997 / 17:01:28 / cg" |
2 | 2193 |
! ! |
2194 |
||
18272 | 2195 |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2196 |
!Filename methodsFor:'enumerating-contents'! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2197 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2198 |
allDirectoriesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2199 |
"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
|
2200 |
The block is invoked with a filename-arguments. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2201 |
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
|
2202 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2203 |
This excludes entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2204 |
NoOp for non-existing directories; however, this behavior |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2205 |
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
|
2206 |
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
|
2207 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2208 |
self recursiveDirectoryContentsDo:[:eachFileOrDirectoryName | |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2209 |
|eachFileOrDirectory| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2210 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2211 |
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
|
2212 |
eachFileOrDirectory isDirectory ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2213 |
aBlock value:eachFileOrDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2214 |
] |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2215 |
]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2216 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2217 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2218 |
'.' asFilename allDirectoriesDo:[:fn | Transcript showCR:fn name]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2219 |
'.' asFilename directoriesDo:[:fn | Transcript showCR:fn name]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2220 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2221 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2222 |
|
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2223 |
allParentDirectoriesDo:aBlock |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2224 |
"evaluate aBlock for all (recursive) directories along the parent directory path. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2225 |
The block is invoked with a filename-arguments." |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2226 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2227 |
|parent here| |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2228 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2229 |
here := self. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2230 |
parent := here directory. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2231 |
[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
|
2232 |
aBlock value:parent. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2233 |
here := parent. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2234 |
parent := here directory. |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2235 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2236 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2237 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2238 |
'.' asFilename allParentDirectoriesDo:[:fn | Transcript showCR:fn pathName]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2239 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2240 |
! |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
2241 |
|
9362 | 2242 |
directories |
2243 |
"return a collection of directories contained in the directory represented by the receiver." |
|
2244 |
||
19821 | 2245 |
^ OrderedCollection withCollectedContents:[:coll | |
2246 |
self directoriesDo:[:eachDirectory | coll add:eachDirectory]] |
|
9362 | 2247 |
|
2248 |
" |
|
2249 |
'.' asFilename directories. |
|
2250 |
" |
|
10557 | 2251 |
|
2252 |
"Modified: / 29-05-2007 / 12:02:56 / cg" |
|
9362 | 2253 |
! |
2254 |
||
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2255 |
directoriesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2256 |
"evaluate aBlock for directories contained in the directory represented by the receiver. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2257 |
The block is invoked with a filename-arguments. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2258 |
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
|
2259 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2260 |
This excludes entries for '.' or '..'. |
18686 | 2261 |
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
|
2262 |
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
|
2263 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2264 |
self directoryContentsAsFilenamesDo:[:eachFileOrDirectory | |
19599 | 2265 |
eachFileOrDirectory isDirectory ifTrue:[ |
2266 |
aBlock value:eachFileOrDirectory |
|
2267 |
] |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2268 |
]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2269 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2270 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2271 |
'.' asFilename directoriesDo:[:fn | Transcript showCR:fn baseName]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2272 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2273 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2274 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2275 |
directoryContentsAsFilenamesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2276 |
"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
|
2277 |
The block is invoked with a filename-argument. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2278 |
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
|
2279 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2280 |
This excludes entries for '.' or '..'. |
17310 | 2281 |
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
|
2282 |
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
|
2283 |
Notice: this enumerates fileName objects; see also |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2284 |
#directoryContentsDo:, which enumerates strings." |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2285 |
|
6776
11df52e55905
better loop (dont preread all items in ..asFilenamesDo:)
penk
parents:
6773
diff
changeset
|
2286 |
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
|
2287 |
aBlock value:(self construct:entry). |
6776
11df52e55905
better loop (dont preread all items in ..asFilenamesDo:)
penk
parents:
6773
diff
changeset
|
2288 |
] |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2289 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2290 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2291 |
'.' asFilename directoryContentsAsFilenamesDo:[:fn | Transcript showCR:fn pathName]. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2292 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2293 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2294 |
"Modified: / 18.9.1997 / 18:42:23 / stefan" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2295 |
"Modified: / 23.12.1999 / 20:56:35 / cg" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2296 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2297 |
|
7464 | 2298 |
directoryContentsDo:aBlock |
2299 |
"evaluate aBlock for each file in the directory represented by the receiver. |
|
2300 |
The block is invoked with a string as argument. |
|
2301 |
The enumerations order is undefined - i.e. usually NOT sorted by |
|
2302 |
filenames (but by creation time - on some systems). |
|
2303 |
This excludes entries for '.' or '..'. |
|
17310 | 2304 |
An OpenError exception is raised it the directory does not exist or is not readable. |
7464 | 2305 |
So users of this method better test for existing directory before. |
2306 |
Notice: this enumerates strings; see also |
|
2307 |
#directoryContentsAsFilenamesDo:, which enumerates fileName objects." |
|
2308 |
||
20533 | 2309 |
|s files| |
17310 | 2310 |
|
2311 |
s := DirectoryStream directoryNamed:self osNameForDirectoryContents. |
|
2312 |
"check for nil, in order to allow to proceed from an OpenError" |
|
2313 |
s notNil ifTrue:[ |
|
20533 | 2314 |
"/ the old code did a recursive call with the stream open. |
2315 |
"/ for very very deep hierarchies, this lead to having too many file streams open for |
|
2316 |
"/ some operating systems. |
|
2317 |
"/ (and therefore to a blocked system, sooner or later, when running out of open files) |
|
2318 |
"/ new code reads the directory first, then does the recursion. |
|
2319 |
||
2320 |
"/ [ |
|
2321 |
"/ [s atEnd] whileFalse:[ |
|
2322 |
"/ |fn| |
|
2323 |
"/ |
|
2324 |
"/ fn := s nextLine. |
|
2325 |
"/ (fn notNil and:[fn ~= '.' and:[fn ~= '..']]) ifTrue:[ |
|
2326 |
"/ aBlock value:fn |
|
2327 |
"/ ]. |
|
2328 |
"/ ]. |
|
2329 |
"/ ] ensure:[ |
|
2330 |
"/ s close. |
|
2331 |
"/ ]. |
|
2332 |
files := OrderedCollection new. |
|
2333 |
||
19821 | 2334 |
[ |
2335 |
[s atEnd] whileFalse:[ |
|
2336 |
|fn| |
|
2337 |
||
2338 |
fn := s nextLine. |
|
2339 |
(fn notNil and:[fn ~= '.' and:[fn ~= '..']]) ifTrue:[ |
|
20533 | 2340 |
files add:fn |
19821 | 2341 |
]. |
2342 |
]. |
|
2343 |
] ensure:[ |
|
2344 |
s close. |
|
20533 | 2345 |
]. |
2346 |
files do:aBlock |
|
7464 | 2347 |
]. |
2348 |
||
2349 |
" |
|
2350 |
'.' asFilename directoryContentsDo:[:fn | Transcript showCR:fn]. |
|
7473 | 2351 |
'doeSnotExIST' asFilename directoryContentsDo:[:fn | Transcript showCR:fn]. |
17310 | 2352 |
[ |
19821 | 2353 |
'doeSnotExIST' asFilename directoryContentsDo:[:fn | Transcript showCR:fn]. |
17310 | 2354 |
] on:OpenError do:[:ex| ex proceed] |
7464 | 2355 |
" |
2356 |
||
2357 |
"Modified: / 18.9.1997 / 18:42:23 / stefan" |
|
2358 |
"Modified: / 23.12.1999 / 20:56:35 / cg" |
|
2359 |
! |
|
2360 |
||
9382 | 2361 |
files |
19599 | 2362 |
"return a collection of regular files |
18734 | 2363 |
contained in the directory represented by the receiver." |
9382 | 2364 |
|
19821 | 2365 |
^ OrderedCollection withCollectedContents:[:coll | |
2366 |
self filesDo:[:eachFileName | coll add:eachFileName]]. |
|
9382 | 2367 |
|
2368 |
" |
|
2369 |
'.' asFilename files. |
|
2370 |
" |
|
10557 | 2371 |
|
2372 |
"Modified: / 29-05-2007 / 12:02:15 / cg" |
|
9382 | 2373 |
! |
2374 |
||
9806 | 2375 |
filesDo:aBlock |
18734 | 2376 |
"evaluate aBlock for all regular files (i.e. subdirs are ignored) |
2377 |
contained in the directory represented by the receiver." |
|
9806 | 2378 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2379 |
^ self directoryContentsAsFilenamesDo:[:eachFileOrDirectory | |
19599 | 2380 |
eachFileOrDirectory isRegularFile ifTrue:[ |
2381 |
aBlock value: eachFileOrDirectory |
|
2382 |
]. |
|
17310 | 2383 |
]. |
9806 | 2384 |
|
2385 |
" |
|
2386 |
'.' asFilename filesDo:[:f | Transcript showCR:f]. |
|
2387 |
" |
|
2388 |
||
2389 |
"Created: / 29-08-2006 / 11:03:15 / cg" |
|
10557 | 2390 |
"Modified: / 29-05-2007 / 12:02:46 / cg" |
9806 | 2391 |
! |
2392 |
||
19821 | 2393 |
filesMatchingGLOB:pattern do:aBlock |
2394 |
"Interpreting pattern as a GLOB pattern, |
|
2395 |
evaluate aBlock for each file in me, which matches. |
|
2396 |
Returns the number of matches." |
|
2397 |
||
2398 |
self assert:(pattern asFilename isAbsolute not). |
|
2399 |
^ self filesMatchingGLOBComponents:(Filename components:pattern) do:aBlock |
|
2400 |
||
2401 |
" |
|
2402 |
'..' asFilename filesMatchingGLOB:'A*' do:[:fn | Transcript showCR:fn]. |
|
2403 |
'../..' asFilename filesMatchingGLOB:'lib*/*.st' do:[:fn | Transcript showCR:fn]. |
|
2404 |
" |
|
2405 |
! |
|
2406 |
||
2407 |
filesMatchingGLOBComponents:patternComponents do:aBlock |
|
2408 |
"patternComponents is a component-collection with possible GLOB patterns. |
|
2409 |
Evaluate aBlock for each file in me, which matches. |
|
2410 |
Returns the number of matches" |
|
2411 |
||
2412 |
|dirPath subComponents count| |
|
2413 |
||
2414 |
dirPath := patternComponents first. |
|
2415 |
subComponents := patternComponents copyFrom:2. |
|
2416 |
||
2417 |
dirPath includesMatchCharacters ifFalse:[ |
|
2418 |
| sub | |
|
2419 |
||
2420 |
sub := (self / dirPath). |
|
2421 |
subComponents isEmpty ifTrue:[ |
|
2422 |
"/ I am a leaf |
|
2423 |
sub exists ifTrue:[ |
|
2424 |
aBlock value:sub. |
|
2425 |
^ 1. |
|
2426 |
]. |
|
2427 |
^ 0 |
|
2428 |
] ifFalse:[ |
|
2429 |
^ sub filesMatchingGLOBComponents:subComponents do:aBlock |
|
2430 |
]. |
|
2431 |
] ifTrue:[ |
|
2432 |
count := 0. |
|
2433 |
subComponents isEmpty ifTrue:[ |
|
2434 |
"/ I am a leaf |
|
2435 |
self isDirectory ifTrue:[ |
|
2436 |
self filesMatching:dirPath do:[:eachMatchingFile | |
|
2437 |
aBlock value:(self / eachMatchingFile). |
|
2438 |
count := count + 1. |
|
2439 |
] |
|
2440 |
] |
|
2441 |
] ifFalse:[ |
|
2442 |
self filesMatching:dirPath do:[:eachMatchingSubDir | |
|
2443 |
|sub| |
|
2444 |
sub := (self / eachMatchingSubDir). |
|
2445 |
sub isDirectory ifTrue:[ |
|
2446 |
count := count + (sub filesMatchingGLOBComponents:subComponents do:aBlock) |
|
2447 |
]. |
|
2448 |
]. |
|
2449 |
]. |
|
2450 |
^ count |
|
2451 |
]. |
|
2452 |
||
2453 |
" |
|
2454 |
'/etc/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2455 |
'../A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2456 |
'../../lib*/*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2457 |
" |
|
2458 |
! |
|
2459 |
||
2460 |
filesMatchingGLOBDo:aBlock |
|
2461 |
"Interpreting myself as a GLOB pattern, |
|
2462 |
evaluate aBlock for each file which matches." |
|
2463 |
||
2464 |
|parts dirPath subComponents count top| |
|
2465 |
||
2466 |
parts := self components. |
|
2467 |
dirPath := parts first. |
|
2468 |
subComponents := parts copyFrom:2. |
|
2469 |
||
2470 |
OpenError handle:[:ex | |
|
2471 |
('%1 [info]: failed to open %2: %3' |
|
2472 |
bindWith:self class name |
|
2473 |
with:ex pathName |
|
2474 |
with:ex description) infoPrintCR. |
|
2475 |
self breakPoint:#cg. |
|
2476 |
ex proceed. |
|
2477 |
] do:[ |
|
2478 |
top := dirPath asFilename. |
|
2479 |
||
2480 |
dirPath includesMatchCharacters ifFalse:[ |
|
2481 |
top isAbsolute ifFalse:[ |
|
2482 |
top := Filename currentDirectory construct:dirPath. |
|
2483 |
]. |
|
2484 |
^ top filesMatchingGLOBComponents:subComponents do:aBlock |
|
2485 |
]. |
|
2486 |
||
2487 |
top isAbsolute ifFalse:[ |
|
2488 |
top := Filename currentDirectory. |
|
2489 |
]. |
|
2490 |
count := 0. |
|
2491 |
top filesMatching:dirPath do:[:sub | |
|
2492 |
count := count + ((self / sub) filesMatchingGLOBComponents:subComponents do:aBlock) |
|
2493 |
]. |
|
2494 |
^ count |
|
2495 |
]. |
|
2496 |
||
2497 |
" |
|
2498 |
'/etc/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2499 |
'/etc/a*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2500 |
'../A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2501 |
'../../lib*/*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2502 |
'../../lib*/[A-D]*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2503 |
'../../*/[A-D]*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2504 |
'../../*/*/[A-D]*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2505 |
'../../*java*/*/[A-D]*.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2506 |
'../../*java*/*/Ary.st' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2507 |
'/*/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2508 |
'*/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2509 |
'../*/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2510 |
'./*/A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2511 |
'./*/*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2512 |
'././A*' asFilename filesMatchingGLOBDo:[:fn | Transcript showCR:fn]. |
|
2513 |
" |
|
2514 |
! |
|
2515 |
||
18734 | 2516 |
filesWithSuffix:suffix |
2517 |
"return a collection of regular files (i.e. not subdirectories) |
|
19599 | 2518 |
with a given suffix which are contained in the directory |
18734 | 2519 |
represented by the receiver." |
2520 |
||
19821 | 2521 |
^ OrderedCollection withCollectedContents:[:coll | |
2522 |
self filesWithSuffix:suffix do:[:eachFileName | coll add:eachFileName]]. |
|
18734 | 2523 |
|
2524 |
" |
|
2525 |
'.' asFilename filesWithSuffix:'so'. |
|
19821 | 2526 |
'packages' asFilename filesWithSuffix:'so'. |
18734 | 2527 |
" |
2528 |
! |
|
2529 |
||
2530 |
filesWithSuffix:suffix do:aBlock |
|
2531 |
"evaluate aBlock for all regular files with a given suffix |
|
2532 |
contained in the directory represented by the receiver. |
|
2533 |
(i.e. subdirs are ignored)" |
|
2534 |
||
2535 |
^ self directoryContentsAsFilenamesDo:[:eachFileOrDirectory | |
|
19599 | 2536 |
(eachFileOrDirectory hasSuffix:suffix) ifTrue:[ |
2537 |
eachFileOrDirectory isRegularFile ifTrue:[ |
|
2538 |
aBlock value: eachFileOrDirectory |
|
2539 |
]. |
|
2540 |
]. |
|
18734 | 2541 |
]. |
2542 |
||
2543 |
" |
|
2544 |
'.' asFilename filesWithSuffix:'so' do:[:f | Transcript showCR:f]. |
|
2545 |
" |
|
2546 |
! |
|
2547 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2548 |
recursiveDirectoryContentsAsFilenamesDo:aBlock |
13191
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2549 |
"evaluate aBlock for all files and directories found under the receiver. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2550 |
The block is invoked with the filenames as argument. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2551 |
The walk is bread-first. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2552 |
This excludes any entries for '.' or '..'. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2553 |
Subdirectory files are included with a relative pathname. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2554 |
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
|
2555 |
|
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2556 |
self recursiveDirectoryContentsDo:[:relFn | |
19664 | 2557 |
aBlock value:(self construct:relFn) |
13191
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2558 |
]. |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2559 |
|
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2560 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2561 |
'.' asFilename recursiveDirectoryContentsAsFilenamesDo:[:f | Transcript showCR:f] |
13191
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2562 |
" |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2563 |
|
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2564 |
"Modified: / 12-09-2010 / 15:43:22 / cg" |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2565 |
! |
10ffa6ac5505
added: #recursiveDirectoryContentsAsFilenamesDo:
Claus Gittinger <cg@exept.de>
parents:
13139
diff
changeset
|
2566 |
|
20686 | 2567 |
recursiveDirectoryContentsAsFilenamesDo:aBlock filterForVisitingDirectories:filterOrNil |
2568 |
"evaluate aBlock for all files and directories found under the receiver. |
|
2569 |
The block is invoked with the filenames as argument. |
|
2570 |
The walk is bread-first. |
|
2571 |
This excludes any entries for '.' or '..'. |
|
2572 |
Subdirectory files are included with a relative pathname. |
|
2573 |
If filterOrNil is nonNil, it is passed every directory about to be walked into; |
|
2574 |
if it returns false, that directory is not entered. |
|
2575 |
Warning: this may take a long time to execute |
|
2576 |
(especially with deep and/or remote fileSystems)." |
|
2577 |
||
2578 |
self |
|
2579 |
recursiveDirectoryContentsDo:[:relFn | |
|
2580 |
aBlock value:(self construct:relFn) |
|
2581 |
] |
|
2582 |
filterForVisitingDirectories:filterOrNil. |
|
2583 |
||
2584 |
" |
|
2585 |
'.' asFilename recursiveDirectoryContentsAsFilenamesDo:[:f | Transcript showCR:f] |
|
2586 |
" |
|
2587 |
||
2588 |
"Modified: / 12-09-2010 / 15:43:22 / cg" |
|
2589 |
! |
|
2590 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2591 |
recursiveDirectoryContentsDo:aBlock |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2592 |
"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
|
2593 |
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
|
2594 |
The walk is bread-first. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2595 |
This excludes any entries for '.' or '..'. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2596 |
Subdirectory files are included with a relative pathname. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2597 |
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
|
2598 |
|
19664 | 2599 |
self |
2600 |
recursiveDirectoryContentsWithPrefix:'' |
|
2601 |
filesDo:aBlock |
|
2602 |
directoriesDo:aBlock |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2603 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2604 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2605 |
'.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2606 |
" |
13057
4f7fa62156ac
comment/format in: #recursiveDirectoryContentsDo:
Claus Gittinger <cg@exept.de>
parents:
12975
diff
changeset
|
2607 |
|
4f7fa62156ac
comment/format in: #recursiveDirectoryContentsDo:
Claus Gittinger <cg@exept.de>
parents:
12975
diff
changeset
|
2608 |
"Modified: / 12-09-2010 / 15:43:22 / cg" |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2609 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2610 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2611 |
recursiveDirectoryContentsDo:aBlock directoryPrefix:aPrefix |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2612 |
"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
|
2613 |
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
|
2614 |
The walk is breadth-first. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2615 |
This excludes any entries for '.' or '..'. |
19664 | 2616 |
The argument to aBlock is a pathname relative to aPrefix. |
19114 | 2617 |
A proceedable exception is raised forn non-accessible directories. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2618 |
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
|
2619 |
|
19664 | 2620 |
self |
2621 |
recursiveDirectoryContentsWithPrefix:aPrefix |
|
2622 |
filesDo:aBlock |
|
2623 |
directoriesDo:aBlock |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2624 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2625 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2626 |
'.' 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
|
2627 |
'/etc' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2628 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2629 |
! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2630 |
|
20686 | 2631 |
recursiveDirectoryContentsDo:aBlock filterForVisitingDirectories:filterOrNil |
2632 |
"evaluate aBlock for all files and directories found under the receiver. |
|
2633 |
The block is invoked with the relative filenames as string-argument. |
|
2634 |
The walk is bread-first. |
|
2635 |
This excludes any entries for '.' or '..'. |
|
2636 |
Subdirectory files are included with a relative pathname. |
|
2637 |
If filterOrNil is nonNil, it is passed every directory about to be walked into; |
|
2638 |
if it returns false, that directory is not entered. |
|
2639 |
Warning: this may take a long time to execute |
|
2640 |
(especially with deep and/or remote fileSystems)." |
|
2641 |
||
2642 |
self |
|
2643 |
recursiveDirectoryContentsWithPrefix:'' |
|
2644 |
filesDo:aBlock |
|
2645 |
directoriesDo:aBlock |
|
2646 |
filterForVisitingDirectories:filterOrNil |
|
2647 |
||
2648 |
" |
|
2649 |
'.' asFilename recursiveDirectoryContentsDo:[:f | Transcript showCR:f] |
|
2650 |
" |
|
2651 |
||
2652 |
"Modified: / 12-09-2010 / 15:43:22 / cg" |
|
2653 |
! |
|
2654 |
||
19664 | 2655 |
recursiveDirectoryContentsWithPrefix:aPrefix filesDo:fileBlock directoriesDo:dirBlock |
2656 |
"evaluate aBlock for all files and directories found under the receiver. |
|
2657 |
The blocks are invoked with a relative pathname as string-argument. |
|
2658 |
The walk is breadth-first (first files, then directories). |
|
2659 |
This excludes any entries for '.' or '..'. |
|
2660 |
A proceedable exception is raised for non-accessible directories. |
|
20686 | 2661 |
Warning: this may take a long time to execute |
2662 |
(especially with deep and/or remote fileSystems)." |
|
2663 |
||
2664 |
self |
|
2665 |
recursiveDirectoryContentsWithPrefix:aPrefix |
|
2666 |
filesDo:fileBlock |
|
2667 |
directoriesDo:dirBlock |
|
2668 |
filterForVisitingDirectories:nil |
|
2669 |
||
2670 |
" |
|
2671 |
'.' asFilename |
|
2672 |
recursiveDirectoryContentsWithPrefix:'bla' |
|
2673 |
filesDo:[:f | Transcript show:'file: '; showCR:f] |
|
2674 |
directoriesDo:[:f | Transcript show:'dir: '; showCR:f] |
|
2675 |
" |
|
2676 |
! |
|
2677 |
||
2678 |
recursiveDirectoryContentsWithPrefix:aPrefix filesDo:fileBlock directoriesDo:dirBlock filterForVisitingDirectories:filterOrNil |
|
2679 |
"evaluate aBlock for all files and directories found under the receiver. |
|
2680 |
The blocks are invoked with a relative pathname as string-argument. |
|
2681 |
The walk is breadth-first (first files, then directories). |
|
2682 |
This excludes any entries for '.' or '..'. |
|
2683 |
A proceedable exception is raised for non-accessible directories. |
|
2684 |
If filterOrNil is nonNil, it is passed every directory about to be walked into; |
|
2685 |
if it returns false, that directory is not entered. |
|
2686 |
Warning: this may take a long time to execute |
|
2687 |
(especially with deep and/or remote fileSystems). |
|
2688 |
" |
|
19664 | 2689 |
|
2690 |
|fileNames dirNames p| |
|
2691 |
||
2692 |
"/ first collect files and dirs |
|
2693 |
fileNames := OrderedCollection new. |
|
2694 |
dirNames := OrderedCollection new. |
|
2695 |
||
2696 |
self directoryContentsDo:[:f | |t| |
|
2697 |
t := self construct:f. |
|
2698 |
t isDirectory ifTrue:[ |
|
20686 | 2699 |
(filterOrNil isNil or:[filterOrNil value:t]) ifTrue:[ |
2700 |
dirBlock notNil ifTrue:[ |
|
2701 |
t isSymbolicLink ifFalse:[ |
|
2702 |
dirNames add:f |
|
2703 |
] |
|
19664 | 2704 |
] |
2705 |
] |
|
2706 |
] ifFalse:[ |
|
2707 |
fileBlock notNil ifTrue:[ |
|
2708 |
fileNames add:f |
|
2709 |
] |
|
2710 |
] |
|
2711 |
]. |
|
2712 |
||
2713 |
aPrefix size > 0 ifTrue:[ |
|
2714 |
p := aPrefix , self separator |
|
2715 |
] ifFalse:[ |
|
2716 |
p := '' |
|
2717 |
]. |
|
2718 |
||
2719 |
fileBlock notNil ifTrue:[ |
|
2720 |
fileNames do:[:aFile | fileBlock value:(p , aFile)]. |
|
2721 |
]. |
|
2722 |
dirBlock notNil ifTrue:[ |
|
2723 |
dirNames do:[:dN | |
|
20686 | 2724 |
|subDir| |
2725 |
||
2726 |
subDir := (self construct:dN). |
|
2727 |
(filterOrNil isNil or:[filterOrNil value:subDir]) ifTrue:[ |
|
2728 |
dirBlock value:(p , dN). |
|
2729 |
subDir |
|
2730 |
recursiveDirectoryContentsWithPrefix:(p , dN) |
|
2731 |
filesDo:fileBlock directoriesDo:dirBlock |
|
2732 |
]. |
|
19664 | 2733 |
]. |
2734 |
]. |
|
2735 |
||
2736 |
" |
|
2737 |
'.' asFilename |
|
2738 |
recursiveDirectoryContentsWithPrefix:'bla' |
|
2739 |
filesDo:[:f | Transcript show:'file: '; showCR:f] |
|
2740 |
directoriesDo:[:f | Transcript show:'dir: '; showCR:f] |
|
2741 |
" |
|
2742 |
! |
|
2743 |
||
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2744 |
withAllDirectoriesDo:aBlock |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2745 |
"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
|
2746 |
The block is invoked with a filename-arguments. |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2747 |
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
|
2748 |
filenames (but by creation time - on some systems). |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2749 |
This excludes entries for '.' or '..'. |
17310 | 2750 |
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
|
2751 |
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
|
2752 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2753 |
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
|
2754 |
aBlock value:self. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2755 |
]. |
17310 | 2756 |
self allDirectoriesDo:aBlock. |
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2757 |
|
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2758 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2759 |
'.' asFilename withAllDirectoriesDo:[:fn | Transcript showCR:fn name]. |
17310 | 2760 |
'IdoNOTexist' asFilename withAllDirectoriesDo:[:fn | Transcript showCR:fn name]. |
2761 |
'/etc/hosts' asFilename withAllDirectoriesDo:[:fn | Transcript showCR:fn name]. |
|
5889
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2762 |
" |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2763 |
! ! |
171985b0ea2f
more & better enumeration protocol
Claus Gittinger <cg@exept.de>
parents:
5877
diff
changeset
|
2764 |
|
542 | 2765 |
!Filename methodsFor:'error handling'! |
2766 |
||
615 | 2767 |
fileCreationError:filename |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2768 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2769 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2770 |
"report an error that some file could not be created" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2771 |
|
615 | 2772 |
^ OperatingSystem accessDeniedErrorSignal |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2773 |
raiseRequestWith:filename?self |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2774 |
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
|
2775 |
! |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2776 |
|
615 | 2777 |
reportError:string with:filename |
1120
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2778 |
"{ Pragma: +optSpace }" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2779 |
|
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2780 |
"report an error" |
94c803be0210
compile errorMethods with +optSpace
Claus Gittinger <cg@exept.de>
parents:
1081
diff
changeset
|
2781 |
|
15192 | 2782 |
^ OsError |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2783 |
raiseRequestWith:filename?self |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2784 |
errorString:string |
615 | 2785 |
! ! |
2786 |
||
2787 |
!Filename methodsFor:'file access'! |
|
2788 |
||
3015 | 2789 |
appendStream |
2790 |
"return a stream for appending to the file represented by the receiver. |
|
2791 |
If the file does not already exist, it is created. |
|
2792 |
Same as #appendingWriteStream for ST-80 compatibility." |
|
2793 |
||
2794 |
^ self appendingWriteStream |
|
2795 |
! |
|
2796 |
||
615 | 2797 |
appendingWriteStream |
2798 |
"return a stream for appending to the file represented by the receiver. |
|
5720 | 2799 |
If the file does not already exist, it is created; |
2800 |
if it does exist, writes are appended at the end." |
|
615 | 2801 |
|
2947 | 2802 |
^ FileStream appendingOldFileNamed:(self osNameForAccess) |
5720 | 2803 |
|
2804 |
" |
|
2805 |
|s| |
|
2806 |
||
2807 |
s := '/tmp/foo' asFilename writeStream. |
|
2808 |
s nextPutAll:'1234567890'. |
|
2809 |
s close. |
|
2810 |
||
2811 |
s := '/tmp/foo' asFilename appendingWriteStream. |
|
2812 |
s nextPutAll:'abcdef'. |
|
2813 |
s close. |
|
2814 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2815 |
'/tmp/foo' asFilename contents |
5720 | 2816 |
" |
615 | 2817 |
! |
2818 |
||
15490 | 2819 |
existingReadWriteStream |
2820 |
"return a stream for read/write the file represented by the receiver. |
|
2821 |
If the file does not already exist, an exception is raised." |
|
2822 |
||
2823 |
^ FileStream oldFileNamed:(self osNameForAccess) |
|
2824 |
||
2825 |
" |
|
2826 |
'/tmp/blaFaselQuall666666' asFilename remove. |
|
2827 |
'/tmp/blaFaselQuall666666' asFilename existingReadWriteStream. |
|
2828 |
" |
|
2829 |
" |
|
2830 |
|s| |
|
2831 |
s := '/tmp/foo' asFilename readWriteStream. |
|
2832 |
s nextPutAll:'1234567890'; close. |
|
2833 |
s := '/tmp/foo' asFilename existingReadWriteStream. |
|
2834 |
s nextPutAll:'abcdef'; close. |
|
2835 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2836 |
'/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
|
2837 |
'/tmp/foo' asFilename remove |
15490 | 2838 |
" |
2839 |
! |
|
2840 |
||
615 | 2841 |
newReadWriteStream |
2842 |
"return a stream for read/write the file represented by the receiver. |
|
5720 | 2843 |
If the file does not already exist, it is created; |
2844 |
if it does exist, it is truncated." |
|
615 | 2845 |
|
2947 | 2846 |
^ FileStream newFileNamed:(self osNameForAccess) |
5720 | 2847 |
|
2848 |
" |
|
2849 |
|s| |
|
2850 |
||
2851 |
s := '/tmp/foo' asFilename writeStream. |
|
2852 |
s nextPutAll:'1234567890'. |
|
2853 |
s close. |
|
2854 |
||
2855 |
s := '/tmp/foo' asFilename newReadWriteStream. |
|
2856 |
s nextPutAll:'12345'. |
|
2857 |
s close. |
|
2858 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2859 |
'/tmp/foo' asFilename contents |
5720 | 2860 |
" |
615 | 2861 |
! |
2862 |
||
15459 | 2863 |
openWithMode:anArrayOrString |
2864 |
"return a stream for read/write the file represented by the receiver. |
|
2865 |
If the file does not already exist, it is created; |
|
2866 |
if it does exist, it is truncated." |
|
2867 |
||
2868 |
^ FileStream open:self osNameForAccess withMode:anArrayOrString |
|
2869 |
||
2870 |
" |
|
2871 |
|s| |
|
2872 |
||
2873 |
s := '/tmp/foo' asFilename openWithMode:'r+'. |
|
2874 |
s nextPutAll:'1234567890'. |
|
2875 |
s close. |
|
2876 |
||
2877 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2878 |
'/tmp/foo' asFilename contents |
15459 | 2879 |
" |
2880 |
! |
|
2881 |
||
615 | 2882 |
readStream |
20156 | 2883 |
"Return a stream for reading from the file represented by the receiver. |
7828 | 2884 |
Raises an error if the file does not exist." |
615 | 2885 |
|
2947 | 2886 |
^ FileStream readonlyFileNamed:(self osNameForAccess) |
615 | 2887 |
|
2888 |
" |
|
20156 | 2889 |
'/tmp/foo' asFilename readStream |
615 | 2890 |
" |
2891 |
! |
|
2892 |
||
2893 |
readWriteStream |
|
2894 |
"return a stream for read/write the file represented by the receiver. |
|
7828 | 2895 |
If the file does not already exist, it is created. |
2896 |
If the file does exist, it is NOT truncated, but rewritten at the beginning." |
|
615 | 2897 |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
2898 |
^ FileStream fileNamed:(self osNameForAccess) |
5720 | 2899 |
|
2900 |
" |
|
2901 |
|s| |
|
2902 |
||
2903 |
s := '/tmp/foo' asFilename writeStream. |
|
2904 |
s nextPutAll:'1234567890'. |
|
2905 |
s close. |
|
2906 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2907 |
s := '/tmp/foo' asFilename readWriteStream. |
5720 | 2908 |
s nextPutAll:'abcdef'. |
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 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2912 |
'/tmp/foo' asFilename remove |
5720 | 2913 |
" |
615 | 2914 |
! |
2915 |
||
2916 |
writeStream |
|
2917 |
"return a stream for writing to the file represented by the receiver. |
|
5720 | 2918 |
If the file does not already exist, it is created; |
2919 |
if it does exist, it is truncated." |
|
615 | 2920 |
|
2947 | 2921 |
^ FileStream newFileForWritingNamed:(self osNameForAccess) |
615 | 2922 |
|
2923 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2924 |
'/tmp/foo' asFilename writeStream |
615 | 2925 |
" |
5720 | 2926 |
|
2927 |
" |
|
2928 |
|s| |
|
2929 |
||
2930 |
s := '/tmp/foo' asFilename writeStream. |
|
2931 |
s nextPutAll:'1234567890'. |
|
2932 |
s close. |
|
2933 |
||
2934 |
s := '/tmp/foo' asFilename writeStream. |
|
2935 |
s nextPutAll:'12345'. |
|
2936 |
s close. |
|
2937 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2938 |
'/tmp/foo' asFilename contents |
5720 | 2939 |
" |
615 | 2940 |
! ! |
2941 |
||
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2942 |
!Filename methodsFor:'file access - migration'! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2943 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2944 |
appendingWriteStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2945 |
"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
|
2946 |
If the file does not already exist, it is created; |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2947 |
if it does exist, writes are appended at the end. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2948 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2949 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2950 |
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
|
2951 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2952 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2953 |
^ [ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2954 |
FileStream appendingOldFileNamed:(self osNameForAccess) |
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2955 |
] on:FileStream openErrorSignal do:[:ex| nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2956 |
! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2957 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2958 |
newReadWriteStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2959 |
"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
|
2960 |
If the file does not already exist, it is created; |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2961 |
if it does exist, it is truncated. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2962 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2963 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2964 |
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
|
2965 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2966 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2967 |
^ [ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2968 |
FileStream newFileNamed:(self osNameForAccess) |
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2969 |
] on:FileStream openErrorSignal do:[:ex|nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2970 |
! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2971 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2972 |
readStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2973 |
"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
|
2974 |
If the file does not already exist, nil is returned. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2975 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2976 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2977 |
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
|
2978 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2979 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2980 |
^ [ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2981 |
FileStream readonlyFileNamed:(self osNameForAccess) |
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2982 |
] on:FileStream openErrorSignal do:[:ex|nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2983 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2984 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
2985 |
'/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
|
2986 |
'/tmp/foo' asFilename readStream |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2987 |
" |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2988 |
! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2989 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2990 |
readWriteStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2991 |
"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
|
2992 |
If the file does not already exist, it is created. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2993 |
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
|
2994 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2995 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2996 |
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
|
2997 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
2998 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
2999 |
^ [ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3000 |
FileStream fileNamed:(self osNameForAccess) |
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
3001 |
] on:FileStream openErrorSignal do:[:ex|^ nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3002 |
! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3003 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3004 |
writeStreamOrNil |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3005 |
"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
|
3006 |
If the file does not already exist, it is created; |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3007 |
if it does exist, it is truncated. |
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 |
Return nil, if the file cannot be opened. |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3010 |
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
|
3011 |
instead of an exception when an error occurs." |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3012 |
|
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
3013 |
^ [ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3014 |
FileStream newFileForWritingNamed:(self osNameForAccess) |
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
3015 |
] on:FileStream openErrorSignal do:[:ex|^ nil]. |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3016 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3017 |
|
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3018 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3019 |
'/etc/foo' asFilename writeStreamOrNil |
8140
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3020 |
" |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3021 |
! ! |
7cc7ac5f29ca
Define #xxxStreamOrNil methods.
Stefan Vogel <sv@exept.de>
parents:
8095
diff
changeset
|
3022 |
|
16310 | 3023 |
!Filename methodsFor:'file access rights'! |
615 | 3024 |
|
12529 | 3025 |
accessRights |
3026 |
"return the access rights of the file as opaque data |
|
3027 |
(SmallInteger in unix/linux)" |
|
3028 |
||
21071 | 3029 |
|access| |
3030 |
||
3031 |
access := OperatingSystem accessModeOf:self osName. |
|
3032 |
access isOSErrorHolder ifTrue:[ |
|
3033 |
access reportProceedableError:'get access rights failed'. |
|
3034 |
]. |
|
3035 |
^ access. |
|
12529 | 3036 |
|
3037 |
" |
|
3038 |
'Make.proto' asFilename accessRights |
|
21071 | 3039 |
'foo' asFilename accessRights |
12529 | 3040 |
" |
3041 |
! |
|
3042 |
||
3043 |
accessRights:opaqueData |
|
3044 |
"set the access rights of the file to opaqueData, |
|
3045 |
which is normally retrieved by Filename>>#accessRights." |
|
3046 |
||
21064 | 3047 |
|osErrorHolder| |
3048 |
||
3049 |
osErrorHolder := OperatingSystem changeAccessModeOf:self osNameForFile to:opaqueData. |
|
3050 |
osErrorHolder notNil ifTrue:[ |
|
3051 |
osErrorHolder reportProceedableError:'change access rights failed'. |
|
3052 |
]. |
|
3053 |
||
12529 | 3054 |
|
3055 |
" |
|
3056 |
|rights| |
|
3057 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3058 |
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
|
3059 |
'Make.proto' asFilename accessRights:rights. |
12529 | 3060 |
" |
3061 |
||
3062 |
"Modified: / 5.5.1999 / 13:41:21 / cg" |
|
3063 |
! |
|
3064 |
||
615 | 3065 |
addAccessRights:aCollection |
3066 |
"add the access rights as specified in aCollection for the file represented |
|
3067 |
by the receiver. The argument must be a collection of symbols, |
|
3068 |
such as #readUser, #writeGroup etc." |
|
3069 |
||
21064 | 3070 |
|access osName osErrorHolder| |
2922 | 3071 |
|
2947 | 3072 |
osName := self osNameForFile. |
2922 | 3073 |
access := OperatingSystem accessModeOf:osName. |
21071 | 3074 |
access isOSErrorHolder ifTrue:[ |
3075 |
access reportProceedableError:'get access rights failed'. |
|
3076 |
]. |
|
3077 |
||
615 | 3078 |
aCollection do:[:accessSymbol | |
21064 | 3079 |
access := access bitOr:(OperatingSystem accessMaskFor:accessSymbol). |
3080 |
]. |
|
3081 |
osErrorHolder := OperatingSystem changeAccessModeOf:osName to:access. |
|
3082 |
osErrorHolder notNil ifTrue:[ |
|
3083 |
osErrorHolder reportProceedableError:'change access rights failed'. |
|
3084 |
]. |
|
615 | 3085 |
|
3086 |
" |
|
3087 |
'foo' asFilename writeStream close. |
|
3088 |
'foo' asFilename addAccessRights:#(readUser readGroup readOthers). |
|
3089 |
'foo' asFilename addAccessRights:#(writeUser writeGroup writeOthers). |
|
3090 |
'foo' asFilename addAccessRights:#(executeUser executeGroup executeOthers). |
|
3091 |
" |
|
3092 |
! |
|
3093 |
||
6223 | 3094 |
makeExecutable |
3095 |
"make the file executable - you must have permission to do so. |
|
3096 |
For directories, execution means: 'allow changing into it'" |
|
3097 |
||
3098 |
^ self addAccessRights:#(executeUser) |
|
3099 |
||
3100 |
"Created: 9.1.1996 / 15:32:47 / cg" |
|
3101 |
! |
|
3102 |
||
3103 |
makeExecutableForAll |
|
3104 |
"make the file executable for all - you must have permission to do so. |
|
3105 |
For directories, execution means: 'allow changing into it'" |
|
3106 |
||
3107 |
^ self addAccessRights:#(executeUser executeGroup executeOthers) |
|
3108 |
||
3109 |
"Created: 9.1.1996 / 15:32:28 / cg" |
|
3110 |
! |
|
3111 |
||
3112 |
makeExecutableForGroup |
|
3113 |
"make the file executable for the group - you must have permission to do so. |
|
3114 |
For directories, execution means: 'allow changing into it'" |
|
3115 |
||
3116 |
^ self addAccessRights:#(executeGroup) |
|
3117 |
||
3118 |
"Created: 9.1.1996 / 15:32:28 / cg" |
|
3119 |
! |
|
3120 |
||
3121 |
makeReadable |
|
3122 |
"make the file readable for the owner - you must have permission to do so." |
|
3123 |
||
3124 |
^ self addAccessRights:#(readUser) |
|
3125 |
! |
|
3126 |
||
3127 |
makeReadableForAll |
|
3128 |
"make the file readable for all - you must have permission to do so." |
|
3129 |
||
3130 |
^ self addAccessRights:#(readUser readGroup readOthers) |
|
3131 |
! |
|
3132 |
||
3133 |
makeReadableForGroup |
|
3134 |
"make the file readable for the group - you must have permission to do so." |
|
3135 |
||
3136 |
^ self addAccessRights:#(readGroup) |
|
3137 |
! |
|
3138 |
||
3139 |
makeUnwritable |
|
3140 |
"make the file unwritable for all - you must have permission to do so." |
|
3141 |
||
3142 |
^ self removeAccessRights:#(writeUser writeGroup writeOthers) |
|
3143 |
! |
|
3144 |
||
3145 |
makeWritable |
|
3146 |
"make the file writableable for all - you must have permission to do so." |
|
3147 |
||
3148 |
^ self addAccessRights:#(writeUser) |
|
3149 |
! |
|
3150 |
||
3151 |
makeWritableForAll |
|
3152 |
"make the file writable for all - you must have permission to do so." |
|
3153 |
||
3154 |
^ self addAccessRights:#(writeUser writeGroup writeOthers) |
|
3155 |
! |
|
3156 |
||
3157 |
makeWritableForGroup |
|
3158 |
"make the file writable for the group - you must have permission to do so." |
|
3159 |
||
3160 |
^ self addAccessRights:#(writeGroup) |
|
3161 |
! |
|
3162 |
||
3163 |
removeAccessRights:aCollection |
|
3164 |
"remove the access rights as specified in aCollection for the file represented |
|
3165 |
by the receiver. The argument must be a collection of symbols, |
|
3166 |
such as #readUser, #writeGroup etc. |
|
3167 |
Raises an exception if not successful." |
|
3168 |
||
21064 | 3169 |
|access osName osErrorHolder| |
6223 | 3170 |
|
3171 |
osName := self osNameForFile. |
|
3172 |
access := OperatingSystem accessModeOf:osName. |
|
21071 | 3173 |
access isOSErrorHolder ifTrue:[ |
3174 |
access reportProceedableError:'get access rights failed'. |
|
3175 |
]. |
|
3176 |
||
6223 | 3177 |
aCollection do:[:accessSymbol | |
21064 | 3178 |
access := access bitAnd:(OperatingSystem accessMaskFor:accessSymbol) bitInvert. |
3179 |
]. |
|
3180 |
osErrorHolder := OperatingSystem changeAccessModeOf:osName to:access. |
|
3181 |
osErrorHolder notNil ifTrue:[ |
|
3182 |
osErrorHolder reportProceedableError:'change access rights failed'. |
|
6223 | 3183 |
]. |
3184 |
||
3185 |
" |
|
3186 |
'foo' asFilename writeStream close. |
|
3187 |
'foo' asFilename removeAccessRights:#(readUser readGroup readOthers). |
|
3188 |
'foo' asFilename removeAccessRights:#(writeUser writeGroup writeOthers). |
|
3189 |
'foo' asFilename removeAccessRights:#(executeUser executeGroup executeOthers). |
|
3190 |
" |
|
3191 |
||
3192 |
"Modified: / 5.5.1999 / 13:41:21 / cg" |
|
3193 |
! |
|
3194 |
||
3195 |
symbolicAccessRights |
|
3196 |
"return the access rights of the file as a aCollection of access symbols. |
|
3197 |
The returned collection consists of symbols like: |
|
21071 | 3198 |
#readUser, #writeGroup etc." |
6223 | 3199 |
|
3200 |
|access osName| |
|
3201 |
||
3202 |
osName := self osNameForFile. |
|
3203 |
access := OperatingSystem accessModeOf:osName. |
|
21071 | 3204 |
access isOSErrorHolder ifTrue:[ |
3205 |
access reportProceedableError:'get access rights failed'. |
|
3206 |
]. |
|
6223 | 3207 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3208 |
^ |
21071 | 3209 |
#( readUser writeUser executeUser |
3210 |
readGroup writeGroup executeGroup |
|
3211 |
readOthers writeOthers executeOthers |
|
3212 |
) select:[:eachSymbolicAccessSymbol | |
|
3213 |
access bitTest:(OperatingSystem accessMaskFor:eachSymbolicAccessSymbol). |
|
3214 |
]. |
|
3215 |
||
3216 |
" |
|
3217 |
'Make.proto' asFilename symbolicAccessRights |
|
6223 | 3218 |
" |
3219 |
||
3220 |
"Modified: / 5.5.1999 / 13:41:21 / cg" |
|
3221 |
! |
|
3222 |
||
3223 |
symbolicAccessRights:aCollectionOfSymbols |
|
3224 |
"set the access rights of the file given a aCollection of access symbols. |
|
3225 |
The collection must consist of symbols like: |
|
21064 | 3226 |
#readUser, #writeGroup etc." |
3227 |
||
3228 |
|access osName osErrorHolder| |
|
6223 | 3229 |
|
3230 |
osName := self osNameForFile. |
|
3231 |
access := aCollectionOfSymbols inject:0 into:[:bitsSoFar :eachSymbolicAccessSymbol | |
|
21064 | 3232 |
bitsSoFar bitOr:(OperatingSystem accessMaskFor:eachSymbolicAccessSymbol) |
3233 |
]. |
|
3234 |
||
3235 |
osErrorHolder := OperatingSystem changeAccessModeOf:osName to:access. |
|
3236 |
osErrorHolder notNil ifTrue:[ |
|
3237 |
osErrorHolder reportProceedableError:'change access rights failed'. |
|
6223 | 3238 |
]. |
3239 |
||
3240 |
" |
|
3241 |
|rights| |
|
3242 |
||
21071 | 3243 |
rights := 'Make.proto' asFilename symbolicAccessRights. |
3244 |
'Make.proto' asFilename symbolicAccessRights:(rights , #(executeOthers)). |
|
6223 | 3245 |
" |
3246 |
||
3247 |
"Modified: / 5.5.1999 / 13:41:21 / cg" |
|
3248 |
! ! |
|
3249 |
||
3250 |
!Filename methodsFor:'file operations'! |
|
3251 |
||
7329 | 3252 |
appendTo:newNameOrStream |
3253 |
"append the file - the argument must be convertable to a filename. |
|
3254 |
Raises an exception, if an error occurs." |
|
3255 |
||
3256 |
|inStream outStream outStreamToClose| |
|
3257 |
||
3258 |
inStream := self readStream. |
|
3259 |
[ |
|
21064 | 3260 |
newNameOrStream isStream ifTrue:[ |
3261 |
outStream := newNameOrStream. |
|
3262 |
] ifFalse:[ |
|
3263 |
outStream := outStreamToClose := newNameOrStream asFilename appendingWriteStream. |
|
3264 |
]. |
|
3265 |
||
3266 |
inStream binary. |
|
3267 |
outStream binary. |
|
3268 |
||
3269 |
inStream copyToEndInto:outStream. |
|
7329 | 3270 |
] ensure:[ |
21064 | 3271 |
inStream close. |
3272 |
outStreamToClose notNil ifTrue:[outStreamToClose close]. |
|
7329 | 3273 |
]. |
3274 |
||
3275 |
" |
|
3276 |
'/etc/group' asFilename appendTo:'/tmp/Makefile.foo'. |
|
3277 |
'Makefile' asFilename appendTo:'/tmp/Makefile.foo' |
|
3278 |
'Makefile' asFilename copyTo:'/' |
|
3279 |
'smalltalk' asFilename copyTo:'/dev/null' |
|
3280 |
" |
|
3281 |
||
3282 |
"Modified: / 23.12.1999 / 21:52:36 / cg" |
|
3283 |
! |
|
3284 |
||
10020 | 3285 |
copyTo:newNameArg |
16578 | 3286 |
"Copy the file's contents into another file. |
9235 | 3287 |
The argument must be convertable to a filename. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3288 |
Raises an exception, if an error occurs." |
615 | 3289 |
|
12529 | 3290 |
|newName inStream outStream newNameAlreadyExists| |
10020 | 3291 |
|
3292 |
newName := newNameArg asFilename. |
|
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
3293 |
|
19957 | 3294 |
"Contents is not copied if newName represents the same file as me." |
10020 | 3295 |
newName asAbsoluteFilename = self asAbsoluteFilename ifTrue: [ ^ self ]. |
8535 | 3296 |
|
19957 | 3297 |
(newName exists and:[newName isDirectory]) ifTrue:[ |
3298 |
newName := newName construct:(self baseName). |
|
3299 |
]. |
|
3300 |
||
615 | 3301 |
inStream := self readStream. |
17143 | 3302 |
inStream isNil ifTrue:[ |
19957 | 3303 |
"open failed, but somenone did a proceed for the OpenError. |
3304 |
Ignore this file but continue in order to copy the rest when |
|
3305 |
doing a recursive copy" |
|
3306 |
^ self. |
|
17143 | 3307 |
]. |
3308 |
||
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
3309 |
[ |
19957 | 3310 |
newNameAlreadyExists := newName exists. |
3311 |
outStream := newName writeStream. |
|
3312 |
newNameAlreadyExists ifFalse:[ |
|
21064 | 3313 |
"ignore the error - may occur when copying to a network drive" |
3314 |
OsError catch:[ |
|
19957 | 3315 |
"would be nice to keep the access rights of the original test suite" |
3316 |
newName accessRights:self accessRights. |
|
3317 |
]. |
|
3318 |
]. |
|
3319 |
inStream binary; buffered:false. |
|
3320 |
outStream binary; buffered:false. |
|
3321 |
inStream copyToEndInto:outStream. |
|
6804
caf6a4521d4c
added utility: ExternalStream >> copyToEndInto:
Claus Gittinger <cg@exept.de>
parents:
6803
diff
changeset
|
3322 |
] ensure:[ |
19957 | 3323 |
inStream close. |
3324 |
outStream notNil ifTrue:[outStream close]. |
|
615 | 3325 |
]. |
3326 |
||
3327 |
" |
|
12529 | 3328 |
'Make.proto' asFilename copyTo:'/tmp/Makefile.foo' |
3329 |
'Make.proto' asFilename copyTo:'/' |
|
615 | 3330 |
'smalltalk' asFilename copyTo:'/dev/null' |
3331 |
" |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3332 |
|
10020 | 3333 |
"Modified: / 10-09-2004 / 09:49:28 / janfrog" |
19957 | 3334 |
"Modified: / 06-06-2016 / 12:15:25 / cg" |
615 | 3335 |
! |
3336 |
||
15465 | 3337 |
copyToStream:outStream |
16578 | 3338 |
"Copy the file's contents into another file. |
15465 | 3339 |
The argument must be convertable to a filename. |
3340 |
Raises an exception, if an error occurs." |
|
3341 |
||
15858 | 3342 |
|inStream resetBinary| |
15465 | 3343 |
|
3344 |
"Contents is not copied if newName represent same file as me." |
|
3345 |
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
|
3346 |
outStream fileName asAbsoluteFilename = self asAbsoluteFilename ifTrue: [ ^ self ]. |
15465 | 3347 |
]. |
3348 |
||
3349 |
inStream := self readStream. |
|
3350 |
[ |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3351 |
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
|
3352 |
resetBinary := false. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3353 |
outStream isBinary ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3354 |
outStream binary. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3355 |
resetBinary := true. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3356 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3357 |
inStream copyToEndInto:outStream. |
15465 | 3358 |
] ensure:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3359 |
inStream close. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3360 |
resetBinary ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3361 |
outStream text. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3362 |
]. |
15465 | 3363 |
]. |
3364 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3365 |
" |
15465 | 3366 |
|out| |
3367 |
out := FileStream newTemporary. |
|
3368 |
'Make.proto' asFilename copyToStream:out. |
|
3369 |
out reset; contents |
|
3370 |
" |
|
3371 |
! |
|
3372 |
||
6983 | 3373 |
createAsEmptyFile |
19440 | 3374 |
"create an empty file with the receiver's name. |
6983 | 3375 |
Raises an exception if not successful |
3376 |
(either already existing or creation not possible)" |
|
3377 |
||
3378 |
|writeStream| |
|
3379 |
||
3380 |
self exists ifTrue:[ |
|
19599 | 3381 |
OperatingSystem accessDeniedErrorSignal |
3382 |
raiseRequestWith:self |
|
3383 |
errorString:(' - file exists: ' , self asString). |
|
3384 |
^ self |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3385 |
]. |
6983 | 3386 |
|
3387 |
FileStream openErrorSignal handle:[:ex| |
|
19599 | 3388 |
self fileCreationError:self. |
3389 |
^ self |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3390 |
] do:[ |
19599 | 3391 |
writeStream := self newReadWriteStream. |
6983 | 3392 |
]. |
3393 |
writeStream close. |
|
3394 |
! |
|
3395 |
||
21064 | 3396 |
createAsHardLinkTo:linkFilenameString |
3397 |
"create a directory with the receiver's name. |
|
3398 |
Raises an exception if not successful" |
|
3399 |
||
3400 |
|errorHolder| |
|
3401 |
||
3402 |
errorHolder := OperatingSystem createHardLinkFrom:linkFilenameString asFilename osName to:self osName. |
|
3403 |
errorHolder notNil ifTrue:[ |
|
3404 |
errorHolder reportProceedableError:'hard link failed'. |
|
3405 |
]. |
|
3406 |
||
3407 |
" |
|
3408 |
'/tmp/link' asFilename createAsHardLinkTo:'bla' |
|
3409 |
" |
|
3410 |
! |
|
3411 |
||
17143 | 3412 |
createAsSymbolicLinkTo:linkFilenameString |
19440 | 3413 |
"create a directory with the receiver's name. |
17143 | 3414 |
Raises an exception if not successful" |
3415 |
||
21064 | 3416 |
|errorHolder| |
3417 |
||
3418 |
errorHolder := OperatingSystem createSymbolicLinkFrom:linkFilenameString asFilename osName to:self osName. |
|
3419 |
errorHolder notNil ifTrue:[ |
|
3420 |
errorHolder reportError:'symbolic link failed'. |
|
3421 |
]. |
|
3422 |
||
3423 |
" |
|
3424 |
'/tmp/link' asFilename createAsSymbolicLinkTo:'bla' |
|
17143 | 3425 |
" |
3426 |
! |
|
3427 |
||
615 | 3428 |
delete |
3429 |
"remove the file - same as remove, for ST-80 compatibility" |
|
3430 |
||
3431 |
self remove |
|
3432 |
! |
|
3433 |
||
3434 |
makeDirectory |
|
19440 | 3435 |
"create a directory with the receiver's name. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3436 |
Raises an exception if not successful" |
615 | 3437 |
|
21064 | 3438 |
|osErrorHolder| |
3439 |
||
3440 |
osErrorHolder := OperatingSystem createDirectory:(self osNameForDirectory). |
|
3441 |
osErrorHolder notNil ifTrue:[ |
|
3442 |
"/ |
|
3443 |
"/ could have existed before ... |
|
3444 |
"/ |
|
3445 |
(self exists and:[self isDirectory]) ifFalse:[ |
|
3446 |
osErrorHolder reportProceedableError:'make directory failed'. |
|
3447 |
] |
|
3448 |
]. |
|
3449 |
^ nil |
|
1970 | 3450 |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3451 |
"Modified: / 5.5.1999 / 13:36:33 / cg" |
615 | 3452 |
! |
3453 |
||
6996
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3454 |
moveFileTo:newName |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3455 |
"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
|
3456 |
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
|
3457 |
Raise an exception if not successful. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3458 |
(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
|
3459 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3460 |
[self renameTo:newName] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3461 |
on:OsError |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3462 |
do:[:ex | |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3463 |
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
|
3464 |
ex reject |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3465 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3466 |
self safeCopyTo:newName. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3467 |
self remove |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3468 |
]. |
6996
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3469 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3470 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3471 |
|f s| |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3472 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3473 |
f := '/tmp/foo' asFilename. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3474 |
s := f writeStream. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3475 |
s nextPutLine:'hello'. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3476 |
s close. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3477 |
f renameTo:'./foo' |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3478 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3479 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3480 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3481 |
|f s| |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3482 |
|
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3483 |
f := '/tmp/foo' asFilename. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3484 |
s := f writeStream. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3485 |
s nextPutLine:'hello'. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3486 |
s close. |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3487 |
f moveTo:'./foo' |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3488 |
" |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3489 |
! |
720a54a2a358
move now also supports recursive directory moves
Claus Gittinger <cg@exept.de>
parents:
6995
diff
changeset
|
3490 |
|
16490 | 3491 |
moveTo:newNameArg |
615 | 3492 |
"copy the file represented by the receiver, then delete it. |
3493 |
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
|
3494 |
Raise an exception if not successful. |
3d801043be3f
dont read the whole directory in #directoryContentsDo:
Claus Gittinger <cg@exept.de>
parents:
5577
diff
changeset
|
3495 |
(Notice, that a rename is tried first, in case of non-cross device move)" |
615 | 3496 |
|
16490 | 3497 |
|newName| |
3498 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3499 |
newName := newNameArg asFilename. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3500 |
[self renameTo:newName] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3501 |
on:(OSErrorHolder inappropriateReferentSignal) |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3502 |
do:[:ex | |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3503 |
"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
|
3504 |
self isDirectory ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3505 |
self recursiveMoveDirectoryTo:newName. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3506 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3507 |
self safeCopyTo:newName. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3508 |
self remove. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3509 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3510 |
]. |
5507
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3511 |
|
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3512 |
" |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3513 |
|f s| |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3514 |
|
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3515 |
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
|
3516 |
s := f writeStream. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3517 |
s nextPutLine:'hello'. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3518 |
s close. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3519 |
f renameTo:'./foo' |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3520 |
" |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3521 |
|
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3522 |
" |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3523 |
|f s| |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3524 |
|
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3525 |
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
|
3526 |
s := f writeStream. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3527 |
s nextPutLine:'hello'. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3528 |
s close. |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3529 |
f moveTo:'./foo' |
e8c61b1741c6
in #moveTo: - try a link first, then do a copy-remove.
Claus Gittinger <cg@exept.de>
parents:
5303
diff
changeset
|
3530 |
" |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3531 |
! |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3532 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3533 |
recursiveCopyTo:destination |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3534 |
"if I represent a regular file, copy it. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3535 |
Otherwise, copy the directory and recursively |
12975 | 3536 |
all of its subfiles/subdirectories. |
17143 | 3537 |
|
3538 |
Raises an exception if not successful. |
|
3539 |
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
|
3540 |
If a whole directory is to be copied and the destination directory |
17143 | 3541 |
does not exist, it will be created." |
3542 |
||
3543 |
|ok destinationFilename| |
|
3544 |
||
3545 |
destinationFilename := destination asFilename. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3546 |
self isDirectory ifFalse:[ |
19599 | 3547 |
destinationFilename isDirectory ifTrue:[ |
3548 |
destinationFilename := destinationFilename construct:self baseName. |
|
3549 |
]. |
|
3550 |
self copyTo:destinationFilename. |
|
3551 |
^ self. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3552 |
]. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3553 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3554 |
"/ typically, an 'cp -r' is faster; |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3555 |
"/ 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
|
3556 |
"/ fallBack doing a manual directory walk. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3557 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3558 |
ok := OperatingSystem |
19599 | 3559 |
recursiveCopyDirectory:(self osNameForDirectory) |
3560 |
to:(destinationFilename osNameForDirectory). |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3561 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3562 |
ok ifFalse:[ |
19599 | 3563 |
self recursiveCopyWithoutOSCommandTo:destinationFilename |
3564 |
]. |
|
3565 |
||
3566 |
" |
|
3567 |
'.' asFilename recursiveCopyTo:'/temp/xxx'. |
|
17143 | 3568 |
" |
3569 |
||
12975 | 3570 |
"Created: / 05-05-1999 / 13:35:01 / cg" |
3571 |
"Modified: / 31-05-1999 / 13:11:34 / cg" |
|
3572 |
"Modified: / 29-07-2010 / 12:41:06 / sr" |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3573 |
! |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3574 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3575 |
recursiveCopyWithoutOSCommandTo:destination |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3576 |
"if I represent a regular file, copy it. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3577 |
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
|
3578 |
This one walks down the directory hierarchy, not using any OS command to do the copy. |
17143 | 3579 |
Raises an exception if not successful. |
3580 |
||
3581 |
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
|
3582 |
If a whole directory is to be copied and the destination directory |
17143 | 3583 |
does not exist, it will be created." |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3584 |
|
12529 | 3585 |
|destinationFilename| |
3586 |
||
3587 |
destinationFilename := destination asFilename. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3588 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3589 |
self isDirectory ifTrue:[ |
21064 | 3590 |
destinationFilename exists ifFalse:[ |
3591 |
destinationFilename makeDirectory. |
|
3592 |
OsError catch:[ |
|
3593 |
destinationFilename accessRights:self accessRights. |
|
3594 |
]. |
|
3595 |
]. |
|
3596 |
||
3597 |
self directoryContentsDo:[:aFilenameString | |
|
3598 |
|src srcInfo dst info| |
|
3599 |
||
3600 |
src := self construct:aFilenameString. |
|
3601 |
dst := destinationFilename construct:aFilenameString. |
|
3602 |
||
3603 |
srcInfo := src linkInfo. |
|
3604 |
srcInfo isDirectory ifTrue:[ |
|
3605 |
src recursiveCopyWithoutOSCommandTo:dst |
|
3606 |
] ifFalse:[srcInfo isSymbolicLink ifTrue:[ |
|
3607 |
dst |
|
3608 |
remove; |
|
3609 |
createAsSymbolicLinkTo:srcInfo path. |
|
3610 |
] ifFalse:[ |
|
3611 |
src copyTo:dst. |
|
3612 |
]]. |
|
3613 |
]. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3614 |
] ifFalse:[ |
21064 | 3615 |
destinationFilename isDirectory ifTrue:[ |
3616 |
destinationFilename := destinationFilename construct:self baseName. |
|
3617 |
]. |
|
3618 |
self copyTo:destinationFilename. |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3619 |
] |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3620 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3621 |
" |
18952 | 3622 |
'.' asFilename recursiveCopyWithoutOSCommandTo:'/temp/xxx'. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3623 |
'smalltalk.rc' asFilename recursiveCopyWithoutOSCommandTo:'/tmp/xxx'. |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3624 |
" |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3625 |
|
4246 | 3626 |
"Modified: / 31.5.1999 / 18:12:31 / cg" |
615 | 3627 |
! |
3628 |
||
659 | 3629 |
recursiveMakeDirectory |
18490 | 3630 |
"create a directory with the receiver's name and all required intermediate |
659 | 3631 |
directories. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3632 |
Raises an exception if not successful." |
659 | 3633 |
|
21064 | 3634 |
|osErrorHolder| |
3635 |
||
3636 |
osErrorHolder := OperatingSystem recursiveCreateDirectory:(self osNameForDirectory). |
|
3637 |
osErrorHolder notNil ifTrue:[ |
|
3638 |
osErrorHolder reportProceedableError:'recursive makedir failed'. |
|
3639 |
]. |
|
3640 |
||
3641 |
" |
|
3642 |
'k:\bla\quark' asFilename recursiveMakeDirectory |
|
3643 |
" |
|
659 | 3644 |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3645 |
"Created: / 27.11.1995 / 23:36:40 / cg" |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3646 |
"Modified: / 5.5.1999 / 13:38:42 / cg" |
21064 | 3647 |
|
3648 |
" |
|
3649 |
'C:\windows\bla\xx' asFilename recursiveMakeDirectory |
|
3650 |
'C:\windows\bla' asFilename recursiveRemoveAll |
|
3651 |
" |
|
659 | 3652 |
! |
3653 |
||
6997 | 3654 |
recursiveMoveDirectoryTo:newName |
3655 |
"recursively copy the directory represented by the receiver, then delete it. |
|
3656 |
This is different to renaming in case of cross device moves. |
|
3657 |
Raise an exception if not successful. |
|
3658 |
(Notice, that a rename is tried first, in case of non-cross device move)" |
|
3659 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3660 |
[self renameTo:newName] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3661 |
on:OsError |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3662 |
do:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3663 |
self recursiveCopyTo:newName. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3664 |
self recursiveRemove |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3665 |
]. |
6997 | 3666 |
! |
3667 |
||
615 | 3668 |
recursiveRemove |
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
3669 |
"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
|
3670 |
Otherwise, remove the directory and all of its subfiles/subdirectories. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3671 |
Raise an exception if not successful." |
615 | 3672 |
|
3673 |
|ok| |
|
3674 |
||
3302 | 3675 |
"/ 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
|
3676 |
"/ 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
|
3677 |
"/ fallBack doing a manual directory walk. |
3302 | 3678 |
|
3679 |
ok := OperatingSystem recursiveRemoveDirectory:(self osNameForDirectory). |
|
3680 |
ok ifFalse:[ |
|
19599 | 3681 |
self recursiveRemoveWithoutOSCommand |
18952 | 3682 |
]. |
3683 |
||
3684 |
" |
|
3685 |
'foo/bar' asFilename recursiveMakeDirectory. |
|
3686 |
'foo' asFilename remove. |
|
3687 |
self assert:('foo' asFilename exists not). |
|
3688 |
||
3689 |
||
3690 |
'foo' asFilename recursiveRemove. |
|
3691 |
'foo/bar' asFilename recursiveMakeDirectory. |
|
3692 |
'foo' asFilename recursiveRemove. |
|
3693 |
self assert:('foo' asFilename exists not). |
|
3302 | 3694 |
" |
3695 |
||
3696 |
"Created: / 14.11.1995 / 11:19:29 / cg" |
|
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3697 |
"Modified: / 5.5.1999 / 13:43:35 / cg" |
3302 | 3698 |
! |
3699 |
||
13246 | 3700 |
recursiveRemoveAll |
13247
9e47a0e73ba4
comment/format in: #recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents:
13246
diff
changeset
|
3701 |
"Remove all of my subfiles/subdirectories. |
3302 | 3702 |
Raise an error if not successful. |
3703 |
This one walks down the directory hierarchy, not using any OS |
|
3704 |
command to do the remove." |
|
3299
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
3705 |
|
5abe74e42d94
recursiveRemove is now done without OS support.
Claus Gittinger <cg@exept.de>
parents:
3171
diff
changeset
|
3706 |
self isDirectory ifTrue:[ |
21064 | 3707 |
self directoryContentsAsFilenamesDo:[:eachFilename | |
3708 |
OsError handle:[:ex | |
|
3709 |
eachFilename isDirectory ifFalse:[ ex reject ]. |
|
3710 |
eachFilename |
|
3711 |
recursiveRemoveAll; |
|
3712 |
removeDirectory. |
|
3713 |
] do:[ |
|
3714 |
eachFilename remove |
|
3715 |
]. |
|
18952 | 3716 |
|
3717 |
"/ eachFilename isDirectory ifTrue:[ |
|
3718 |
"/ eachFilename recursiveRemoveWithoutOSCommand |
|
3719 |
"/ ] ifFalse:[ |
|
3720 |
"/ eachFilename remove |
|
3721 |
"/ ]. |
|
21064 | 3722 |
] |
615 | 3723 |
]. |
13246 | 3724 |
|
3725 |
" |
|
3726 |
'foo' asFilename makeDirectory. |
|
3727 |
'foo/bar' asFilename writeStream close. |
|
3728 |
'foo' asFilename remove |
|
3729 |
" |
|
3730 |
" |
|
3731 |
'foo' asFilename makeDirectory. |
|
3732 |
'foo/bar' asFilename writeStream close. |
|
18952 | 3733 |
'foo' asFilename recursiveRemove. |
3734 |
self assert:('foo' asFilename exists not). |
|
13246 | 3735 |
" |
3736 |
||
3737 |
"Created: / 25-01-2011 / 16:42:15 / cg" |
|
3738 |
! |
|
3739 |
||
3740 |
recursiveRemoveWithoutOSCommand |
|
3741 |
"if I represent a regular file, remove it. |
|
3742 |
Otherwise, remove the directory and all of its subfiles/subdirectories. |
|
3743 |
Raise an error if not successful. |
|
3744 |
This one walks down the directory hierarchy, not using any OS |
|
3745 |
command to do the remove." |
|
3746 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3747 |
self |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3748 |
recursiveRemoveAll; |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3749 |
remove. |
615 | 3750 |
|
3751 |
" |
|
3752 |
'foo' asFilename makeDirectory. |
|
3753 |
'foo/bar' asFilename writeStream close. |
|
4940 | 3754 |
'foo' asFilename remove |
615 | 3755 |
" |
3756 |
" |
|
3757 |
'foo' asFilename makeDirectory. |
|
3758 |
'foo/bar' asFilename writeStream close. |
|
4940 | 3759 |
'foo' asFilename recursiveRemove |
615 | 3760 |
" |
3761 |
||
13246 | 3762 |
"Created: / 25-02-1998 / 19:50:40 / cg" |
13949 | 3763 |
"Modified: / 19-01-2012 / 17:18:28 / cg" |
615 | 3764 |
! |
3765 |
||
3766 |
remove |
|
845 | 3767 |
"remove the file/directory. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3768 |
Raises an exception if not successful. |
845 | 3769 |
Use #recursiveRemove in order to (recursively) remove non empty directories." |
615 | 3770 |
|
21064 | 3771 |
|linkInfo osName osErrorHolder| |
8741 | 3772 |
|
18952 | 3773 |
osName := self osNameForAccess. |
21064 | 3774 |
osErrorHolder := OperatingSystem removeFile:osName. |
3775 |
osErrorHolder notNil ifTrue:[ |
|
3776 |
linkInfo := self linkInfo. |
|
3777 |
linkInfo isNil ifTrue:[ |
|
3778 |
"file does not exist - no error" |
|
3779 |
^ self. |
|
3780 |
] ifFalse:[linkInfo isDirectory ifTrue:[ |
|
3781 |
osErrorHolder := OperatingSystem removeDirectory:osName |
|
3782 |
]]. |
|
3783 |
osErrorHolder notNil ifTrue:[ |
|
3784 |
self exists ifTrue:[ |
|
3785 |
osErrorHolder reportProceedableError:'remove failed'. |
|
3786 |
] |
|
3787 |
] |
|
615 | 3788 |
]. |
3789 |
||
3790 |
" |
|
3791 |
(FileStream newFileNamed:'foo') close. |
|
3792 |
'foo' asFilename remove |
|
3793 |
" |
|
3794 |
||
3795 |
" |
|
3796 |
'foo' asFilename makeDirectory. |
|
3797 |
'foo/bar' asFilename writeStream close. |
|
8738 | 3798 |
'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
|
3799 |
'foo' asFilename recursiveRemove. |
615 | 3800 |
" |
3801 |
||
13793
3f1c660956ce
added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents:
13781
diff
changeset
|
3802 |
"Modified: / 20-11-1997 / 17:40:22 / stefan" |
3f1c660956ce
added: #new_recursiveRemoveAll
Claus Gittinger <cg@exept.de>
parents:
13781
diff
changeset
|
3803 |
"Modified: / 11-10-2011 / 10:20:01 / cg" |
615 | 3804 |
! |
3805 |
||
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3806 |
removeDirectory |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3807 |
"remove the directory. |
21441 | 3808 |
Raises an exception if not successful (or if it's not a directory). |
5596 | 3809 |
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
|
3810 |
Use #recursiveRemove in order to (recursively) remove non empty directories." |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3811 |
|
21064 | 3812 |
|osErrorHolder| |
3813 |
||
3814 |
osErrorHolder := OperatingSystem removeDirectory:self osNameForAccess. |
|
3815 |
osErrorHolder notNil ifTrue:[ |
|
3816 |
self exists ifTrue:[ |
|
3817 |
osErrorHolder reportProceedableError:'remove directory failed'. |
|
3818 |
]. |
|
3819 |
]. |
|
3820 |
||
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3821 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3822 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3823 |
(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
|
3824 |
'foo' asFilename removeDirectory |
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3825 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3826 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3827 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3828 |
'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
|
3829 |
'foo' asFilename removeDirectory |
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3830 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3831 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3832 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3833 |
'foo' asFilename makeDirectory. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3834 |
'foo/bar' asFilename writeStream close. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3835 |
('foo' asFilename remove) ifFalse:[ |
21064 | 3836 |
Transcript showCR:'could not remove foo' |
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3837 |
] |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3838 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3839 |
|
21441 | 3840 |
"Modified: / 20-11-1997 / 17:40:22 / stefan" |
3841 |
"Modified: / 05-05-1999 / 13:41:12 / cg" |
|
3842 |
"Modified (comment): / 13-02-2017 / 20:19:10 / cg" |
|
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3843 |
! |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3844 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3845 |
removeFile |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3846 |
"remove the file. |
21441 | 3847 |
Raises an exception if not successful (or if it's not a file). |
5596 | 3848 |
Use #remove if it is not known if the receiver is a directory or file. |
3849 |
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
|
3850 |
|
21064 | 3851 |
|osErrorHolder| |
3852 |
||
3853 |
osErrorHolder := OperatingSystem removeFile:self osNameForAccess. |
|
3854 |
osErrorHolder notNil ifTrue:[ |
|
3855 |
self exists ifTrue:[ |
|
3856 |
osErrorHolder reportProceedableError:'remove of file failed'. |
|
3857 |
]. |
|
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3858 |
]. |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3859 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3860 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3861 |
(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
|
3862 |
'foo' asFilename removeFile |
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3863 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3864 |
|
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3865 |
" |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3866 |
'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
|
3867 |
'foo' asFilename removeFile |
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3868 |
" |
21441 | 3869 |
|
3870 |
"Modified (comment): / 13-02-2017 / 20:19:15 / cg" |
|
5595
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3871 |
! |
b80d12c4983b
added #removeFile and #removeDirectory,
Claus Gittinger <cg@exept.de>
parents:
5594
diff
changeset
|
3872 |
|
21045 | 3873 |
renameTo:newName |
671 | 3874 |
"rename the file - the argument must be convertable to a String. |
15823 | 3875 |
Raises an exception if not successful. |
3876 |
If newName already exists, it will be replaced by myself." |
|
615 | 3877 |
|
21045 | 3878 |
|errorHolder| |
3879 |
||
3880 |
errorHolder := OperatingSystem |
|
3881 |
renameFile:(self osNameForFile) |
|
3882 |
to:(newName asFilename osNameForFile). |
|
3883 |
||
3884 |
errorHolder notNil ifTrue:[ |
|
3885 |
errorHolder |
|
3886 |
parameter:self; |
|
21064 | 3887 |
reportProceedableError:'rename failed'. |
615 | 3888 |
]. |
3889 |
||
3890 |
" |
|
3891 |
'/tmp/foo' asFilename renameTo:'/tmp/bar' |
|
21045 | 3892 |
'/tmp/' asFilename renameTo:'/etc/bar' |
21023 | 3893 |
'C:\windows' asFilename renameTo:'C:\win' |
615 | 3894 |
" |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3895 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3896 |
"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
|
3897 |
! |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3898 |
|
15819 | 3899 |
safeCopyTo:newNameArg |
16578 | 3900 |
"Copy the file's contents into another file. |
15819 | 3901 |
Do it safe in an atomic operation shich makes sure that no partially written file appears. |
3902 |
The argument must be convertable to a filename. |
|
3903 |
Raises an exception, if an error occurs." |
|
3904 |
||
15823 | 3905 |
|newName inStream accessRights tempStream| |
15819 | 3906 |
|
3907 |
newName := newNameArg asFilename. |
|
3908 |
||
3909 |
"Contents is not copied if newName represent same file as me." |
|
3910 |
newName asAbsoluteFilename = self asAbsoluteFilename ifTrue: [ ^ self ]. |
|
3911 |
||
3912 |
inStream := self readStream. |
|
15823 | 3913 |
newName exists ifTrue:[ |
20252 | 3914 |
accessRights := newName accessRights. |
15819 | 3915 |
] ifFalse:[ |
20252 | 3916 |
accessRights := self accessRights. |
15819 | 3917 |
]. |
3918 |
||
3919 |
[ |
|
20252 | 3920 |
"let the temp filename start with a ~ to make it invisible" |
3921 |
tempStream := FileStream newTemporaryIn:newName directory osNameForFile nameTemplate:'~%1_%2'. |
|
21064 | 3922 |
"ignore the error - may occur when copying to a network drive" |
3923 |
OsError catch:[ |
|
20252 | 3924 |
"would be nice to keep the access rights of the original file" |
3925 |
tempStream fileName accessRights:accessRights. |
|
3926 |
]. |
|
3927 |
||
3928 |
inStream binary; buffered:false. |
|
3929 |
tempStream binary; buffered:false. |
|
3930 |
[ |
|
3931 |
inStream copyToEndInto:tempStream. |
|
3932 |
] ifCurtailed:[ |
|
3933 |
tempStream close. |
|
3934 |
tempStream fileName remove. |
|
3935 |
tempStream := nil. |
|
3936 |
]. |
|
3937 |
tempStream syncData. |
|
15819 | 3938 |
] ensure:[ |
20252 | 3939 |
inStream close. |
3940 |
tempStream notNil ifTrue:[tempStream close]. |
|
15819 | 3941 |
]. |
3942 |
tempStream fileName renameTo:newName. |
|
3943 |
||
3944 |
" |
|
3945 |
'Make.proto' asFilename safeCopyTo:'/tmp/Makefile.foo' |
|
3946 |
'Make.proto' asFilename safeCopyTo:'/' |
|
3947 |
'smalltalk' asFilename safeCopyTo:'/xxxxxxxxxxxxxxxx/bla' |
|
3948 |
" |
|
3949 |
||
3950 |
"Modified: / 10-09-2004 / 09:49:28 / janfrog" |
|
3951 |
"Modified: / 29-09-2006 / 16:26:32 / cg" |
|
3952 |
! |
|
3953 |
||
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3954 |
truncateTo:newSize |
16578 | 3955 |
"change the file's size. |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3956 |
This may not be supported on all operating systems |
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3957 |
(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
|
3958 |
|
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
3959 |
(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
|
3960 |
^ 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
|
3961 |
] |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3962 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3963 |
" |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3964 |
|s| |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3965 |
|
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3966 |
s := 'test' asFilename writeStream. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3967 |
s next:1000 put:$1. |
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3968 |
s close. |
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
3969 |
('test' asFilename fileSize) printCR. |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3970 |
'test' asFilename truncateTo:100. |
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
3971 |
('test' asFilename fileSize) printCR. |
932
f57ec42ceb44
added interface to truncate & ftruncate (req. by Mr. Olberding)
Claus Gittinger <cg@exept.de>
parents:
883
diff
changeset
|
3972 |
" |
4148
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3973 |
|
70c391aa0e3e
added recursiveCopy support.
Claus Gittinger <cg@exept.de>
parents:
4131
diff
changeset
|
3974 |
"Modified: / 5.5.1999 / 13:41:59 / cg" |
615 | 3975 |
! ! |
3976 |
||
3977 |
!Filename methodsFor:'file queries'! |
|
3978 |
||
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3979 |
accessTime |
16578 | 3980 |
"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
|
3981 |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3982 |
| i | |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3983 |
|
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3984 |
(i := self info) isNil ifTrue:[^ nil]. |
6793
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
3985 |
^ i accessTime |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3986 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3987 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
3988 |
Filename currentDirectory accessTime |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3989 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3990 |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
3991 |
"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
|
3992 |
"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
|
3993 |
"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
|
3994 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
3995 |
|
6977 | 3996 |
creationTime |
16578 | 3997 |
"return a timeStamp containing the file's creation time. |
6977 | 3998 |
NOTICE: only windoof distinguishes creation from modification; |
6978 | 3999 |
under unix, nil is returned (callers should fall back and use mod-time then" |
6977 | 4000 |
|
4001 |
|i| |
|
4002 |
||
4003 |
(i := self info) isNil ifTrue:[^ nil]. "/ non-existing |
|
6978 | 4004 |
^ i creationTime |
4005 |
||
4006 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4007 |
Filename currentDirectory creationTime |
6977 | 4008 |
" |
4009 |
||
4010 |
"Created: / 9.7.1996 / 10:18:59 / cg" |
|
4011 |
"Modified: / 26.9.1997 / 13:05:39 / stefan" |
|
4012 |
"Modified: / 14.8.1998 / 17:42:50 / cg" |
|
4013 |
! |
|
4014 |
||
615 | 4015 |
dates |
16578 | 4016 |
"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
|
4017 |
that responds to the at: message with arguments |
615 | 4018 |
#modified, #accessed or #statusChanged." |
4019 |
||
2922 | 4020 |
|info dates osName| |
4021 |
||
2947 | 4022 |
osName := self osNameForAccess. |
2922 | 4023 |
info := OperatingSystem infoOf:osName. |
615 | 4024 |
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
|
4025 |
"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
|
4026 |
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
|
4027 |
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
|
4028 |
info isNil ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4029 |
^ nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4030 |
] |
615 | 4031 |
]. |
4032 |
dates := IdentityDictionary new. |
|
6978 | 4033 |
dates at:#created put:(info creationTime). |
6793
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
4034 |
dates at:#modified put:(info modificationTime). |
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
4035 |
dates at:#accessed put:(info accessTime). |
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
4036 |
dates at:#statusChanged put:(info statusChangeTime). |
615 | 4037 |
^ dates |
4038 |
||
4039 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4040 |
Filename currentDirectory dates |
615 | 4041 |
'../regression' asFilename dates |
4042 |
" |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4043 |
|
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4044 |
"Modified: 1.11.1996 / 20:19:24 / cg" |
615 | 4045 |
! |
4046 |
||
4047 |
fileSize |
|
4048 |
"return the size of the file in bytes" |
|
4049 |
||
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4050 |
|i| |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4051 |
|
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4052 |
(i := self info) isNil ifTrue:[^ nil]. |
6794
498d85323172
use #fileSize instead of #size
Claus Gittinger <cg@exept.de>
parents:
6793
diff
changeset
|
4053 |
^ i fileSize |
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4054 |
|
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4055 |
"Modified: / 17.8.1998 / 10:23:46 / cg" |
615 | 4056 |
! |
4057 |
||
4058 |
fileType |
|
4059 |
"this returns a string describing the type of contents of |
|
4060 |
the file. This is done using the unix 'file' command, |
|
4061 |
(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
|
4062 |
On non-unix systems, this may simply return 'file', |
2922 | 4063 |
not knowning about the contents. |
4064 |
Warning: |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4065 |
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
|
4066 |
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
|
4067 |
NOT as a tag to be used by a program." |
3665 | 4068 |
|
16755 | 4069 |
|suffix baseNm info mime| |
3665 | 4070 |
|
4071 |
"/ 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
|
4072 |
"/ do the most obvious ones here. |
3665 | 4073 |
"/ (also useful since the 'file' command takes some time, and the code |
4074 |
"/ 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
|
4075 |
|
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4076 |
info := self linkInfo. |
9060 | 4077 |
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
|
4078 |
^ 'removed' "/ could happen, when coming from a snapshot image |
9060 | 4079 |
]. |
4080 |
||
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4081 |
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
|
4082 |
^ 'symbolic link to ' , info path |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
4083 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4084 |
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
|
4085 |
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
|
4086 |
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
|
4087 |
^ 'directory' |
2573 | 4088 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4089 |
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
|
4090 |
^ 'character device special file' |
3665 | 4091 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4092 |
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
|
4093 |
^ 'block device special file' |
3665 | 4094 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4095 |
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
|
4096 |
^ 'socket' |
3665 | 4097 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
4098 |
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
|
4099 |
^ '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
|
4100 |
]. |
3665 | 4101 |
|
1602 | 4102 |
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
|
4103 |
info fileSize == 0 ifTrue:[^ 'empty']. |
1602 | 4104 |
|
17112 | 4105 |
"/ suffix := self suffix asLowercase. |
4106 |
"/ baseNm := self withoutSuffix baseName asLowercase. |
|
2922 | 4107 |
|
16755 | 4108 |
mime := self mimeTypeOfContents. |
4109 |
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
|
4110 |
"/ 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
|
4111 |
(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
|
4112 |
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
|
4113 |
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
|
4114 |
]. |
1602 | 4115 |
]. |
2906 | 4116 |
^ 'file' |
615 | 4117 |
|
4118 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4119 |
'Makefile' asFilename fileType |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4120 |
'.' asFilename fileType |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4121 |
'/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
|
4122 |
'/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
|
4123 |
'/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
|
4124 |
'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
|
4125 |
'bitmaps/SBrowser.xbm' asFilename fileType |
615 | 4126 |
" |
1601
1d57e1047323
avoid calling 'file' for symbolic links & directories
Claus Gittinger <cg@exept.de>
parents:
1540
diff
changeset
|
4127 |
|
3665 | 4128 |
"Modified: / 21.7.1998 / 11:25:56 / cg" |
615 | 4129 |
! |
4130 |
||
2836 | 4131 |
id |
16578 | 4132 |
"return the file's/directory's file-id (inode number)" |
2836 | 4133 |
|
2947 | 4134 |
^ OperatingSystem idOf:(self osNameForAccess) |
2836 | 4135 |
|
4136 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4137 |
Filename currentDirectory id |
2836 | 4138 |
" |
4139 |
||
4140 |
"Modified: 9.7.1996 / 10:19:27 / cg" |
|
4141 |
"Created: 5.8.1997 / 19:26:01 / cg" |
|
4142 |
! |
|
4143 |
||
615 | 4144 |
info |
16578 | 4145 |
"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
|
4146 |
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
|
4147 |
the returned object) is: |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4148 |
|
20798 | 4149 |
type - a symbol giving the files fileType |
4150 |
mode - numeric access mode |
|
4151 |
uid - owners user id |
|
4152 |
gid - owners group id |
|
4153 |
size - files size |
|
4154 |
id - files number (i.e. inode number) |
|
4155 |
accessed - last access time (as osTime-stamp) |
|
4156 |
modified - last modification time (as osTime-stamp) |
|
4157 |
statusChangeTime - last staus change (as osTime-stamp) |
|
615 | 4158 |
|
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4159 |
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
|
4160 |
all of the information. |
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4161 |
The minimum returned info (i.e. on all OS's) will consist of at least: |
20798 | 4162 |
modified |
4163 |
size |
|
4164 |
type |
|
4165 |
||
4166 |
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
|
4167 |
to either handle nil values, |
615 | 4168 |
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
|
4169 |
(i.e. instead of: |
20798 | 4170 |
someFilename type == #directory |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4171 |
use |
20798 | 4172 |
someFilename isDirectory |
615 | 4173 |
" |
4174 |
||
2947 | 4175 |
^ OperatingSystem infoOf:(self osNameForAccess) |
615 | 4176 |
|
4177 |
" |
|
4178 |
Filename currentDirectory info |
|
3768
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4179 |
'/dev/null' asFilename info |
615 | 4180 |
'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
|
4181 |
'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
|
4182 |
'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
|
4183 |
'../../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
|
4184 |
'.' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4185 |
'..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4186 |
'..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4187 |
'..\..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4188 |
'..\..\..\..' asFilename info |
4801b87c1cd7
care for non-existing info in #accessTime, #modTime and #fileSize
Claus Gittinger <cg@exept.de>
parents:
3763
diff
changeset
|
4189 |
'c:\' asFilename info |
615 | 4190 |
" |
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
4191 |
|
16272 | 4192 |
"Modified: / 17-08-1998 / 10:24:10 / cg" |
4193 |
"Modified (comment): / 21-03-2014 / 00:35:30 / Jan Vrany <jan.vrany@fit.cvut.cz>" |
|
615 | 4194 |
! |
4195 |
||
4196 |
linkInfo |
|
16578 | 4197 |
"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
|
4198 |
instead of the link's target. |
615 | 4199 |
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
|
4200 |
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
|
4201 |
is returned |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4202 |
(while in this case, #info returns the info of the target file, |
615 | 4203 |
which is accessed via the symbolic link). |
4204 |
||
4205 |
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
|
4206 |
path -> the target files pathname |
615 | 4207 |
|
4208 |
See the comment in #info for more details." |
|
4209 |
||
2947 | 4210 |
^ OperatingSystem linkInfoOf:(self osNameForAccess) |
615 | 4211 |
|
4212 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4213 |
Filename currentDirectory linkInfo |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4214 |
'/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
|
4215 |
'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
|
4216 |
'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
|
4217 |
'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
|
4218 |
'../../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
|
4219 |
'/usr/tmp' asFilename linkInfo |
615 | 4220 |
" |
1862
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
4221 |
|
e8f44f10f1ab
changes for new #infoOf: / #linkInfoOf: return
Claus Gittinger <cg@exept.de>
parents:
1859
diff
changeset
|
4222 |
"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
|
4223 |
! |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4224 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4225 |
modificationTime |
16578 | 4226 |
"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
|
4227 |
|
3763
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
4228 |
|i| |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
4229 |
|
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
4230 |
(i := self info) isNil ifTrue:[^ nil]. "/ non-existing |
6793
0d3e3fd18a70
modified -> modificationTime
Claus Gittinger <cg@exept.de>
parents:
6776
diff
changeset
|
4231 |
^ i modificationTime |
1532
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4232 |
|
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4233 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4234 |
Filename currentDirectory modificationTime |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4235 |
" |
6b4c38b9090c
added #modificationTime & #accessTime (easier to use than #dates)
Claus Gittinger <cg@exept.de>
parents:
1523
diff
changeset
|
4236 |
|
3763
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
4237 |
"Created: / 9.7.1996 / 10:18:59 / cg" |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
4238 |
"Modified: / 26.9.1997 / 13:05:39 / stefan" |
31d58d04ac15
care for nil-info in #modificationTime
Claus Gittinger <cg@exept.de>
parents:
3753
diff
changeset
|
4239 |
"Modified: / 14.8.1998 / 17:42:50 / cg" |
2836 | 4240 |
! |
4241 |
||
4242 |
type |
|
4243 |
"return the symbolic type of the file" |
|
4244 |
||
2947 | 4245 |
^ OperatingSystem typeOf:(self osNameForAccess) |
2836 | 4246 |
|
4247 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4248 |
Filename currentDirectory type |
2836 | 4249 |
" |
4250 |
||
4251 |
"Modified: 9.7.1996 / 10:19:27 / cg" |
|
4252 |
"Created: 5.8.1997 / 19:31:26 / cg" |
|
615 | 4253 |
! ! |
4254 |
||
4255 |
!Filename methodsFor:'file utilities'! |
|
4256 |
||
4257 |
edit |
|
4258 |
"start an editView on the file represented by the receiver" |
|
4259 |
||
4260 |
EditTextView openOn:self asString |
|
4261 |
||
4262 |
" |
|
4263 |
'smalltalk.rc' asFilename edit |
|
4264 |
" |
|
4265 |
! |
|
4266 |
||
4267 |
fileIn |
|
13424 | 4268 |
"load source code from the file" |
4269 |
||
4270 |
^ (ProgrammingLanguage forFile: self) fileIn: self |
|
4271 |
||
4272 |
"Modified: / 16-08-2009 / 13:27:36 / Jan Vrany <vranyj1@fel.cvut.cz>" |
|
542 | 4273 |
! ! |
4274 |
||
2 | 4275 |
!Filename methodsFor:'instance creation'! |
4276 |
||
10969
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4277 |
/ subname |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4278 |
"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
|
4279 |
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
|
4280 |
(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
|
4281 |
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
|
4282 |
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
|
4283 |
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
|
4284 |
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
|
4285 |
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
|
4286 |
|
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4287 |
^ 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
|
4288 |
|
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4289 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4290 |
'/tmp' asFilename / 'foo' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4291 |
'/' 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
|
4292 |
'/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
|
4293 |
|
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4294 |
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
|
4295 |
'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
|
4296 |
" |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4297 |
! |
046b204c6ea2
New method: #/ as synonym of #construct:. Thanks to Jan Vrany, see Bug 823.
Stefan Vogel <sv@exept.de>
parents:
10902
diff
changeset
|
4298 |
|
615 | 4299 |
construct:subname |
4300 |
"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
|
4301 |
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
|
4302 |
(i.e. for a file or a subdirectory in that directory). |
2922 | 4303 |
The argument may not specify an absolute path name. |
4304 |
Please do not use this to create filenames with suffixes, |
|
4305 |
since some systems require special naming conventions. |
|
4306 |
See also: #withSuffix: (which is different, but often needed)." |
|
615 | 4307 |
|
11784 | 4308 |
|constructedName| |
4309 |
||
4310 |
constructedName := self constructString:subname. |
|
15811 | 4311 |
^ self species named:constructedName. |
615 | 4312 |
|
4313 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4314 |
'/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
|
4315 |
'/' asFilename construct:'foo' |
615 | 4316 |
'/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
|
4317 |
'/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
|
4318 |
'/foo/bar' asFilename construct:'baz' asFilename |
2922 | 4319 |
|
4320 |
Bad example; works on UNIX, but may not on others: |
|
11784 | 4321 |
'foo/bar.baz' asFilename construct:'.suff' |
615 | 4322 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4323 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4324 |
"Modified: 29.2.1996 / 20:55:06 / cg" |
2911 | 4325 |
! |
4326 |
||
2922 | 4327 |
constructDirectory:subname |
4328 |
"same as #construct: on most systems. |
|
4329 |
(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
|
4330 |
|
15811 | 4331 |
^ self species named:(self constructDirectoryString:subname) |
2922 | 4332 |
! |
4333 |
||
4334 |
constructDirectoryString:subName |
|
4335 |
"same as #constructString: on most systems. |
|
4336 |
(may allow different/relaxed name syntax of the argument on some systems)" |
|
4337 |
||
4338 |
^ self constructString:subName |
|
4339 |
! |
|
4340 |
||
4341 |
constructString:subName |
|
2911 | 4342 |
"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
|
4343 |
filename-string for an entry within this directory |
2922 | 4344 |
(i.e. for a file or a subdirectory in that directory). |
2960 | 4345 |
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
|
4346 |
The code below works for UNIX & MSDOS; |
2960 | 4347 |
other filename classes (i.e. VMS) may want to redefine this method." |
4348 |
||
4349 |
|sepString sub| |
|
4350 |
||
4351 |
sub := subName asString. |
|
20069 | 4352 |
nameString size == 0 ifTrue:[ |
4353 |
^ sub |
|
4354 |
]. |
|
15811 | 4355 |
sepString := self species separatorString. |
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
4356 |
(nameString endsWith:sepString) ifTrue:[ |
20069 | 4357 |
^ nameString , sub |
6247 | 4358 |
]. |
2960 | 4359 |
^ nameString , sepString , sub |
2911 | 4360 |
|
4361 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4362 |
'/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
|
4363 |
'/' asFilename constructString:'foo' |
2911 | 4364 |
'/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
|
4365 |
'/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
|
4366 |
'' asFilename constructString:'baz' |
2911 | 4367 |
" |
4368 |
||
3677
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
4369 |
"Modified: / 7.9.1995 / 10:15:22 / claus" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
4370 |
"Created: / 9.9.1997 / 08:57:08 / cg" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
4371 |
"Modified: / 20.1.1998 / 15:58:23 / md" |
51542c86ba2a
md's changes for msdos compatibility.
Claus Gittinger <cg@exept.de>
parents:
3666
diff
changeset
|
4372 |
"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
|
4373 |
! |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4374 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4375 |
filenameFor:fileName |
6973 | 4376 |
"return a filename representing the argument, fileName |
4377 |
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
|
4378 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4379 |
|f| |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4380 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4381 |
f := fileName asFilename. |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4382 |
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
|
4383 |
^ (self construct:fileName) |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4384 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4385 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4386 |
'/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
|
4387 |
'/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
|
4388 |
" |
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4389 |
|
e1f1111afa12
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2939
diff
changeset
|
4390 |
"Created: 18.9.1997 / 14:34:14 / stefan" |
9263 | 4391 |
! |
4392 |
||
4393 |
secureConstruct:subname |
|
4394 |
"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
|
4395 |
filename for an entry within this directory |
9263 | 4396 |
(i.e. for a file or a subdirectory in that directory). |
4397 |
The argument may not specify an absolute path name. |
|
4398 |
Please do not use this to create filenames with suffixes, |
|
4399 |
since some systems require special naming conventions. |
|
4400 |
See also: #withSuffix: (which is different, but often needed). |
|
4401 |
||
4402 |
This method differs from #construct:, by not permitting subName |
|
4403 |
to navigate above (via ..) the current filename." |
|
4404 |
||
15811 | 4405 |
^ self species named:(self secureConstructString:subname) |
9263 | 4406 |
|
4407 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4408 |
'/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
|
4409 |
'/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
|
4410 |
'/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
|
4411 |
'/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
|
4412 |
'/' asFilename secureConstruct:'foo' |
9263 | 4413 |
'/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
|
4414 |
'/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
|
4415 |
'/foo/bar' asFilename secureConstruct:'baz' asFilename |
9263 | 4416 |
|
4417 |
Bad example; works on UNIX, but may not on others: |
|
4418 |
'foo/bar.baz' secureConstruct:'.suff' |
|
4419 |
" |
|
4420 |
||
4421 |
"Modified: 29.2.1996 / 20:55:06 / cg" |
|
4422 |
! |
|
4423 |
||
4424 |
secureConstructString:subName |
|
4425 |
"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
|
4426 |
filename-string for an entry within this directory |
9263 | 4427 |
(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
|
4428 |
|
9263 | 4429 |
This method differs from #constructString, by not permitting subName |
4430 |
to navigate above (via ..) the current filename. |
|
4431 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4432 |
The code below works for UNIX & MSDOS; |
9263 | 4433 |
other filename classes (i.e. VMS) may want to redefine this method." |
4434 |
||
4435 |
|sepString sub normalizedPath pathStream| |
|
4436 |
||
15811 | 4437 |
sepString := self species separatorString. |
9263 | 4438 |
sub := subName asString. |
4439 |
||
4440 |
sub := sub asCollectionOfSubstringsSeparatedByAll:sepString. |
|
4441 |
normalizedPath := OrderedCollection new:sub size. |
|
4442 |
sub do:[:eachPathComponent| |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4443 |
eachPathComponent = '..' ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4444 |
normalizedPath isEmpty ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4445 |
self error:'secureConstruct: - trying to escape from: ', nameString. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4446 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4447 |
normalizedPath removeLast. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4448 |
] ifFalse:[(eachPathComponent notEmpty and:[eachPathComponent ~= '.']) ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4449 |
normalizedPath add:eachPathComponent. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4450 |
]] |
9263 | 4451 |
]. |
18272 | 4452 |
pathStream := CharacterWriteStream with:nameString. |
9263 | 4453 |
(nameString notEmpty and:[(nameString endsWith:sepString) not]) ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4454 |
pathStream nextPutAll:sepString. |
9263 | 4455 |
]. |
4456 |
normalizedPath do:[:eachPathComponent| |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4457 |
pathStream nextPutAll:eachPathComponent. |
9263 | 4458 |
] separatedBy:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4459 |
pathStream nextPutAll:sepString. |
9263 | 4460 |
]. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4461 |
|
9263 | 4462 |
^ pathStream contents. |
4463 |
||
4464 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4465 |
'/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
|
4466 |
'/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
|
4467 |
'/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
|
4468 |
'/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
|
4469 |
'/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
|
4470 |
'/' asFilename secureConstructString:'foo' |
9263 | 4471 |
'/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
|
4472 |
'/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
|
4473 |
'' asFilename secureConstructString:'baz' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4474 |
'' asFilename secureConstructString:'/baz' |
9263 | 4475 |
" |
2 | 4476 |
! ! |
4477 |
||
195 | 4478 |
!Filename methodsFor:'misc'! |
4479 |
||
4480 |
, aString |
|
4481 |
"this allows filenames to understand how names are concatenated. |
|
14072 | 4482 |
Returns a string consisting of the receiver's name, concatenated |
195 | 4483 |
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
|
4484 |
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
|
4485 |
See also: #withSuffix: which is new and better." |
195 | 4486 |
|
5866 | 4487 |
<resource:#obsolete> |
4488 |
||
2906 | 4489 |
self obsoleteMethodWarning:'use #construct:'. |
308 | 4490 |
^ (nameString , aString asString) |
195 | 4491 |
|
4492 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4493 |
'Makefile' asFilename , '.bak' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4494 |
('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
|
4495 |
'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
|
4496 |
'Makefile' asFilename construct:'.bak' |
195 | 4497 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4498 |
|
14072 | 4499 |
"Modified: / 07-09-1997 / 23:45:36 / cg" |
4500 |
"Modified (comment): / 01-04-2012 / 13:18:21 / cg" |
|
9263 | 4501 |
! |
4502 |
||
4503 |
canonicalize |
|
4504 |
"normalize a filename by removing all empty path components or dots, |
|
4505 |
and by resolving parent directory '..' references. |
|
4506 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4507 |
The code below works for UNIX & MSDOS; |
9263 | 4508 |
other filename classes (i.e. VMS) may want to redefine this method." |
4509 |
||
15811 | 4510 |
nameString := self species canonicalize:nameString. |
9263 | 4511 |
|
4512 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4513 |
'/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
|
4514 |
'/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
|
4515 |
'/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
|
4516 |
'..' asFilename canonicalize. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4517 |
'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
|
4518 |
'//bla/../fasel' asFilename canonicalize. |
9263 | 4519 |
" |
195 | 4520 |
! ! |
4521 |
||
14232 | 4522 |
!Filename methodsFor:'os shell'! |
4523 |
||
4524 |
openExplorer |
|
4525 |
"open a file-explorer on the directory represented by the receiver. |
|
4526 |
On non-windows systems, an error is raised" |
|
4527 |
||
4528 |
OperatingSystem isMSWINDOWSlike ifFalse:[ |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4529 |
self warn:'sorry - this operation is only available under windows'. |
14232 | 4530 |
]. |
4531 |
||
4532 |
OperatingSystem |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4533 |
openApplicationForDocument:self pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4534 |
operation:#explore. |
14232 | 4535 |
|
4536 |
"Created: / 21-07-2012 / 12:28:18 / cg" |
|
14804 | 4537 |
! |
4538 |
||
4539 |
openFinder |
|
4540 |
"open a finder on the directory represented by the receiver. |
|
4541 |
On non-osx systems, an error is raised" |
|
4542 |
||
4543 |
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
|
4544 |
self warn:'sorry - this operation is only available under osx'. |
14804 | 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 |
OperatingSystem executeCommand:'open "',self pathName,'"' |
14804 | 4548 |
! |
4549 |
||
4550 |
openTerminal |
|
16545 | 4551 |
"open a terminal window on the directory represented by the receiver; |
4552 |
on osx, a terminal app is opened, |
|
4553 |
on windows a cmd.exe window, |
|
4554 |
on unix, an xterm is opened." |
|
4555 |
||
4556 |
OperatingSystem isOSXlike ifTrue:[ |
|
20798 | 4557 |
"/ I don't know yet how to tell the terminal to |
20678 | 4558 |
"/ go to a particular directory. |
4559 |
"/ therefore, use the built in terminal |
|
4560 |
VT100TerminalView openShellIn:self pathName. |
|
4561 |
^ self. |
|
4562 |
]. |
|
4563 |
"/ using the code below seems to close the window immediately |
|
4564 |
"/ at least on win7. |
|
4565 |
"/ use out own terminal, to make sure. |
|
4566 |
(OperatingSystem isMSWINDOWSlike |
|
4567 |
and:[OperatingSystem isWin7Like]) ifTrue:[ |
|
20798 | 4568 |
"/ I don't know yet how to tell the terminal to |
20678 | 4569 |
"/ go to a particular directory. |
4570 |
"/ therefore, use the built in terminal |
|
4571 |
VT100TerminalView openShellIn:self pathName. |
|
4572 |
^ self. |
|
16545 | 4573 |
]. |
14804 | 4574 |
|
14941 | 4575 |
[ |
20678 | 4576 |
|cmd| |
4577 |
||
4578 |
OperatingSystem isOSXlike ifTrue:[ |
|
4579 |
cmd := '/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal ' |
|
4580 |
] ifFalse:[ |
|
4581 |
OperatingSystem isMSWINDOWSlike ifTrue:[ |
|
4582 |
cmd := #('c:\windows\System32\cmd.exe') |
|
4583 |
] ifFalse:[ |
|
4584 |
"/ VT100TerminalView openShellIn:self pathName |
|
4585 |
cmd := 'xterm' |
|
4586 |
] |
|
4587 |
]. |
|
4588 |
OperatingSystem |
|
4589 |
executeCommand:cmd |
|
4590 |
inDirectory:self pathName |
|
4591 |
showWindow:#default. |
|
14941 | 4592 |
] fork |
20678 | 4593 |
|
4594 |
"Modified: / 18-10-2016 / 16:08:15 / cg" |
|
14232 | 4595 |
! ! |
4596 |
||
615 | 4597 |
!Filename methodsFor:'printing & storing'! |
174 | 4598 |
|
615 | 4599 |
printOn:aStream |
4392 | 4600 |
"append a user printed representation of the receiver to aStream. |
4601 |
The format is suitable for a human - not meant to be read back." |
|
174 | 4602 |
|
2906 | 4603 |
aStream nextPutAll:(self class name). |
4604 |
aStream nextPutAll:'('''. |
|
615 | 4605 |
nameString printOn:aStream. |
4606 |
aStream nextPutAll:''')' |
|
2906 | 4607 |
|
4608 |
"Modified: 7.9.1997 / 23:46:20 / cg" |
|
1 | 4609 |
! |
4610 |
||
615 | 4611 |
storeOn:aStream |
4612 |
"append a printed representation of the receiver to aStream, |
|
4613 |
which allows reconstructing it via readFrom:" |
|
328 | 4614 |
|
615 | 4615 |
aStream nextPut:$(. |
4616 |
nameString storeOn:aStream. |
|
4617 |
aStream nextPutAll:' asFilename)' |
|
1 | 4618 |
! ! |
4619 |
||
7258 | 4620 |
!Filename methodsFor:'private-accessing'! |
1 | 4621 |
|
6227 | 4622 |
getName |
21263 | 4623 |
<resource: #obsolete> |
6227 | 4624 |
"get the raw filename" |
4625 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4626 |
^ nameString |
6227 | 4627 |
! |
4628 |
||
21263 | 4629 |
nameString |
4630 |
"raw access to nameString - req'd for xml-store/reload" |
|
4631 |
||
4632 |
^ nameString |
|
4633 |
! |
|
4634 |
||
4635 |
nameString:aString |
|
4636 |
"raw access to nameString - req'd for xml-store/reload" |
|
4637 |
||
4638 |
nameString := aString |
|
4639 |
! |
|
4640 |
||
68 | 4641 |
setName:aString |
38 | 4642 |
"set the filename" |
4643 |
||
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
4644 |
nameString := aString. |
3666 | 4645 |
|
4646 |
"Modified: / 21.7.1998 / 10:44:18 / cg" |
|
1 | 4647 |
! ! |
4648 |
||
2 | 4649 |
!Filename methodsFor:'queries'! |
4650 |
||
68 | 4651 |
exists |
92 | 4652 |
"return true, if such a file exists." |
68 | 4653 |
|
2947 | 4654 |
^ OperatingSystem isValidPath:(self osNameForAccess) |
68 | 4655 |
|
85 | 4656 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4657 |
'/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
|
4658 |
'/tmp' asFilename exists |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4659 |
'Makefile' asFilename exists |
85 | 4660 |
" |
77 | 4661 |
! |
4662 |
||
5928 | 4663 |
filenamesMatching:aPattern |
4664 |
"VW compatibility" |
|
4665 |
||
15811 | 4666 |
^ (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
|
4667 |
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
|
4668 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4669 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4670 |
'/etc' asFilename filenamesMatching:'a*;c*' |
5928 | 4671 |
" |
4672 |
||
4673 |
"Created: / 15.4.1997 / 15:40:02 / cg" |
|
4674 |
"Modified: / 3.8.1998 / 21:22:15 / cg" |
|
4675 |
! |
|
4676 |
||
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
4677 |
filesMatching:aPattern |
2550 | 4678 |
"given the receiver, representing a directory; |
4679 |
return a collection of files matching a pattern. |
|
4680 |
The pattern may be a simple matchPattern, or a set of |
|
4681 |
multiple patterns separated by semicolons." |
|
4682 |
||
19821 | 4683 |
^ OrderedCollection withCollectedContents:[:coll | |
4684 |
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
|
4685 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4686 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4687 |
'/etc' asFilename filesMatching:'a*;c*' |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
4688 |
" |
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
4689 |
|
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
4690 |
"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
|
4691 |
"Modified: / 3.8.1998 / 21:22:15 / cg" |
2550 | 4692 |
! |
4693 |
||
19821 | 4694 |
filesMatching:aPattern caseSensitive:caseSensitive do:aBlock |
4695 |
"given the receiver, representing a directory; |
|
4696 |
evaluate aBlock for files which match a pattern. |
|
4697 |
The pattern may be a simple matchPattern, or a set of |
|
4698 |
multiple patterns separated by semicolons." |
|
4699 |
||
4700 |
|matchers| |
|
4701 |
||
4702 |
matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;. |
|
4703 |
self directoryContentsDo:[:name | |
|
4704 |
(matchers contains:[:p | p match:name caseSensitive:caseSensitive]) ifTrue:[ |
|
4705 |
aBlock value:name |
|
4706 |
] |
|
4707 |
]. |
|
4708 |
||
4709 |
" |
|
4710 |
'/etc' asFilename filesMatching:'a*;c*' do:[:f | Transcript showCR:f] |
|
4711 |
" |
|
4712 |
||
4713 |
"Created: / 15.4.1997 / 15:40:02 / cg" |
|
4714 |
"Modified: / 3.8.1998 / 21:22:15 / cg" |
|
4715 |
! |
|
4716 |
||
4717 |
filesMatching:aPattern do:aBlock |
|
4718 |
"given the receiver, representing a directory; |
|
4719 |
evaluate aBlock for files which match a pattern. |
|
4720 |
The pattern may be a simple matchPattern, or a set of |
|
4721 |
multiple patterns separated by semicolons." |
|
4722 |
||
4723 |
self filesMatching:aPattern caseSensitive:self species isCaseSensitive do:aBlock |
|
4724 |
||
4725 |
" |
|
4726 |
'/etc' asFilename filesMatching:'a*;c*' do:[:f | Transcript showCR:f] |
|
4727 |
" |
|
4728 |
||
4729 |
"Created: / 15.4.1997 / 15:40:02 / cg" |
|
4730 |
"Modified: / 3.8.1998 / 21:22:15 / cg" |
|
4731 |
! |
|
4732 |
||
2550 | 4733 |
filesMatchingWithoutDotDirs:aPattern |
4734 |
"given the receiver, representing a directory; |
|
4735 |
return a collection of files matching a pattern. |
|
4736 |
Exclude '.' and '..' from the returned list. |
|
4737 |
The pattern may be a simple matchPattern, or a set of |
|
4738 |
multiple patterns separated by semicolons." |
|
4739 |
||
19821 | 4740 |
^ OrderedCollection withCollectedContents:[:coll | |
4741 |
self filesMatchingWithoutDotDirs:aPattern do:[:fn | coll add:fn]] |
|
4742 |
||
4743 |
" |
|
4744 |
Filename currentDirectory filesMatching:'.*' |
|
4745 |
Filename currentDirectory filesMatchingWithoutDotDirs:'*.*' |
|
4746 |
'/etc' asFilename filesMatchingWithoutDotDirs:'*' |
|
4747 |
" |
|
4748 |
||
4749 |
"Created: / 15.4.1997 / 12:52:10 / cg" |
|
4750 |
"Modified: / 3.8.1998 / 21:22:30 / cg" |
|
4751 |
! |
|
4752 |
||
4753 |
filesMatchingWithoutDotDirs:aPattern caseSensitive:caseSensitive do:aBlock |
|
4754 |
"given the receiver, representing a directory; |
|
4755 |
evaluate aBlock for files matching a pattern. |
|
4756 |
Exclude '.' and '..'. |
|
4757 |
The pattern may be a simple matchPattern, or a set of |
|
4758 |
multiple patterns separated by semicolons." |
|
4759 |
||
4760 |
|matchers| |
|
2550 | 4761 |
|
4762 |
matchers := aPattern asCollectionOfSubstringsSeparatedBy:$;. |
|
19821 | 4763 |
|
4764 |
self directoryContentsDo:[:name | |
|
4765 |
(name ~= '.' |
|
4766 |
and:[ name ~= '..' |
|
4767 |
and:[ (matchers contains:[:p | p match:name caseSensitive:caseSensitive]) ]]) |
|
4768 |
ifTrue:[ |
|
4769 |
aBlock value:name |
|
4770 |
] |
|
4771 |
]. |
|
4772 |
||
4773 |
" |
|
4774 |
Filename currentDirectory filesMatching:'M*' |
|
4775 |
'/etc' asFilename filesMatching:'[a-z]*' |
|
4776 |
'../../libbasic' asFilename filesMatching:'[A-D]*.st' |
|
4777 |
" |
|
4778 |
||
4779 |
"Created: / 15.4.1997 / 12:52:10 / cg" |
|
4780 |
"Modified: / 3.8.1998 / 21:22:30 / cg" |
|
4781 |
! |
|
4782 |
||
4783 |
filesMatchingWithoutDotDirs:aPattern do:aBlock |
|
4784 |
"given the receiver, representing a directory; |
|
4785 |
evaluate aBlock for files matching a pattern. |
|
4786 |
Exclude '.' and '..'. |
|
4787 |
The pattern may be a simple matchPattern, or a set of |
|
4788 |
multiple patterns separated by semicolons." |
|
4789 |
||
4790 |
self filesMatchingWithoutDotDirs:aPattern caseSensitive:self species isCaseSensitive do:aBlock |
|
2550 | 4791 |
|
4792 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4793 |
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
|
4794 |
'/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
|
4795 |
'../../libbasic' asFilename filesMatching:'[A-D]*.st' |
2550 | 4796 |
" |
4797 |
||
3719
ce88c6f64d37
ignore case for PC-filenames when searching for matches.
Claus Gittinger <cg@exept.de>
parents:
3713
diff
changeset
|
4798 |
"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
|
4799 |
"Modified: / 3.8.1998 / 21:22:30 / cg" |
2548
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
4800 |
! |
b6182b559ea2
made filesMatching ST-80 compatible.
Claus Gittinger <cg@exept.de>
parents:
2547
diff
changeset
|
4801 |
|
9206 | 4802 |
fullAlternativePathName |
19821 | 4803 |
"some filesystems (aka: windows) have alternative (short) filenames. |
4804 |
Those systems redefine this method to return it. |
|
4805 |
Otherwise, the same as the regular name is returned here" |
|
4806 |
||
9206 | 4807 |
^ nameString |
4808 |
! |
|
4809 |
||
615 | 4810 |
isExecutable |
4811 |
"return true, if such a file exists and is executable (by Unix's definition). |
|
4812 |
For directories, true is returned if the directory can be entered. |
|
4813 |
See isExecutableProgram for a related check." |
|
4814 |
||
2947 | 4815 |
^ OperatingSystem isExecutable:(self osNameForAccess) |
615 | 4816 |
|
4817 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4818 |
'/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
|
4819 |
'/tmp' asFilename isExecutable |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4820 |
'Makefile' asFilename isExecutable |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4821 |
'/bin/ls' asFilename isExecutable |
356 | 4822 |
" |
4823 |
! |
|
4824 |
||
615 | 4825 |
isExecutableProgram |
4826 |
"return true, if such a file exists and is an executable program. |
|
4827 |
(i.e. for directories, false is returned.)" |
|
356 | 4828 |
|
2922 | 4829 |
|osName| |
4830 |
||
2947 | 4831 |
osName := self osNameForAccess. |
2922 | 4832 |
^ (OperatingSystem isExecutable:osName) |
4833 |
and:[(OperatingSystem isDirectory:osName) not] |
|
356 | 4834 |
|
4835 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4836 |
'/tmp' asFilename isExecutable |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4837 |
'/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
|
4838 |
'/tmp' asFilename isExecutableProgram |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4839 |
'/bin/ls' asFilename isExecutableProgram |
20457 | 4840 |
|
4841 |
'ls' asFilename isExecutableProgram |
|
4842 |
OperatingSystem canExecuteCommand:'ls' |
|
615 | 4843 |
" |
4844 |
! |
|
4845 |
||
2922 | 4846 |
isHidden |
4847 |
"return true, if the receiver represents a hidden file. |
|
4848 |
The definitions of hidden files depends on the OS used; |
|
4849 |
on UNIX, a name starting with a period is considered hidden; |
|
16578 | 4850 |
on MSDOS, the file's hidden attribute is also used. |
2922 | 4851 |
VMS has no concept of hidden files." |
4852 |
||
4853 |
^ false |
|
4854 |
! |
|
4855 |
||
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4856 |
isMountPoint:aPathName |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4857 |
"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
|
4858 |
Warning: |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4859 |
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
|
4860 |
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
|
4861 |
Aka: do not ask: '../../' asFilename isMountPoint; |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4862 |
" |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4863 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4864 |
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
|
4865 |
self error:'this query must be done on an absolute pathname'. |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4866 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4867 |
^ OperatingSystem isMountPoint:(self name) |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4868 |
! |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
4869 |
|
615 | 4870 |
isReadable |
4871 |
"return true, if such a file exists and is readable." |
|
4872 |
||
2947 | 4873 |
^ OperatingSystem isReadable:(self osNameForFile) |
615 | 4874 |
|
4875 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4876 |
'/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
|
4877 |
'/tmp' asFilename isReadable |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4878 |
'Makefile' asFilename isReadable |
328 | 4879 |
" |
4880 |
! |
|
4881 |
||
11529 | 4882 |
isSharedLibrary |
4883 |
"return true, if such a file exists and is a shared library." |
|
4884 |
||
4885 |
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
|
4886 |
"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
|
4887 |
^ false. |
11529 | 4888 |
]. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4889 |
^ (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
|
4890 |
and:[self isRegularFile]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4891 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4892 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4893 |
'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
|
4894 |
'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
|
4895 |
'/tmp' asFilename isSharedLibrary |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4896 |
'/tmp.dll' asFilename isSharedLibrary |
11529 | 4897 |
" |
4898 |
! |
|
4899 |
||
615 | 4900 |
isWritable |
4901 |
"return true, if such a file exists and is writable." |
|
4902 |
||
2947 | 4903 |
^ OperatingSystem isWritable:(self osNameForFile) |
615 | 4904 |
|
4905 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4906 |
'/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
|
4907 |
'/tmp' asFilename isWritable |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4908 |
'Makefile' asFilename isWritable |
328 | 4909 |
" |
174 | 4910 |
! |
4911 |
||
15574 | 4912 |
isWritableDirectory |
4913 |
"return true, if such a directory exists and is writable. |
|
4914 |
Don't believe #isWritable, since on an NFS mounted filesystem |
|
4915 |
with UID mapping and attribute cache enabled, there may be false negatives." |
|
4916 |
||
4917 |
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
|
4918 |
^ false. |
15574 | 4919 |
]. |
4920 |
||
4921 |
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
|
4922 |
"/ 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
|
4923 |
"/ attribute cache enabled, |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4924 |
"/ 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
|
4925 |
"/ check again... |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4926 |
[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4927 |
|tempFile| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4928 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4929 |
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
|
4930 |
tempFile close. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4931 |
tempFile fileName remove. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4932 |
] 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
|
4933 |
^ false. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4934 |
]. |
15574 | 4935 |
]. |
4936 |
^ true. |
|
4937 |
||
4938 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4939 |
'/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
|
4940 |
'/tmp' asFilename isWritableDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4941 |
'/etc' asFilename isWritableDirectory |
15574 | 4942 |
'Makefile' asFilename isWritableDirectory |
4943 |
'/net/exeptn/home2/office' asFilename isWritable |
|
4944 |
'/net/exeptn/home2/office' asFilename isWritableDirectory |
|
4945 |
" |
|
4946 |
! |
|
4947 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4948 |
separator |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4949 |
"return the directory-separator character" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4950 |
|
15811 | 4951 |
^ self species separator |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4952 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4953 |
"Modified: 29.2.1996 / 20:52:01 / cg" |
8947 | 4954 |
! |
4955 |
||
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
4956 |
species |
15811 | 4957 |
"create only new instances of the concrete OS specific class. |
4958 |
Redefined in AutoDeletedFilename, to not create AutoDeleted instances |
|
4959 |
per default (from directories etc.)" |
|
4960 |
||
4961 |
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
|
4962 |
^ ConcreteClass. |
15811 | 4963 |
] ifFalse:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4964 |
^ self class. |
15811 | 4965 |
]. |
11781
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
4966 |
! |
6488fd6cc498
Make AutoDeletedFilename work like Filename
Stefan Vogel <sv@exept.de>
parents:
11763
diff
changeset
|
4967 |
|
8947 | 4968 |
withSpecialExpansions |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4969 |
"return a new filename, expanding any OS specific macros. |
15811 | 4970 |
Here, a ~/ prefix is expanded to the users home dir (as in bash)" |
8947 | 4971 |
|
4972 |
|newName| |
|
4973 |
||
15811 | 4974 |
newName := self species nameWithSpecialExpansions:nameString. |
4975 |
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
|
4976 |
^ self. |
8947 | 4977 |
]. |
15811 | 4978 |
^ self species named:newName. |
8947 | 4979 |
|
4980 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4981 |
'~' asFilename withSpecialExpansions |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4982 |
'~/Desktop' asFilename withSpecialExpansions |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
4983 |
'~stefan' asFilename withSpecialExpansions |
15811 | 4984 |
'~stefan/Desktop' asFilename withSpecialExpansions |
8947 | 4985 |
" |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4986 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4987 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4988 |
!Filename methodsFor:'queries-contents'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
4989 |
|
7291 | 4990 |
mimeTypeFromName |
16578 | 4991 |
"return the mimeType as guessed from the file's name/and or extension. |
7291 | 4992 |
This could be less accurate than mimeTypeOfContents, but avoids |
4993 |
reading the file (is therefore much faster). |
|
4994 |
Also it works with non-existing files. |
|
4995 |
Returns nil for directories and other non-regular files." |
|
4996 |
||
17112 | 4997 |
|mimeTypes| |
4998 |
||
16755 | 4999 |
"/ kludge to avoid making libview a prereq. of libbasic |
17112 | 5000 |
(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
|
5001 |
^ mimeTypes mimeTypeForFilename:(self name) |
16755 | 5002 |
]. |
5003 |
^ nil |
|
7291 | 5004 |
|
5005 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5006 |
'Makefile' asFilename mimeTypeFromName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5007 |
'.' asFilename mimeTypeFromName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5008 |
'/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
|
5009 |
'/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
|
5010 |
'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
|
5011 |
'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
|
5012 |
'../../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
|
5013 |
'/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
|
5014 |
'/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
|
5015 |
'/x.gz' asFilename mimeTypeFromName |
7291 | 5016 |
" |
5017 |
! |
|
5018 |
||
5011 | 5019 |
mimeTypeOfContents |
5020 |
"this tries to guess the mime type of contents of |
|
5021 |
the file. Returns nil, if the file is unreadable, not a plain file |
|
5022 |
or the contents is unknown. |
|
5023 |
This is done using some heuristics, and may need some improvement" |
|
5024 |
||
17111 | 5025 |
|type buffer s size mimeTypes| |
5011 | 5026 |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
5027 |
type := self type. |
11406
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
5028 |
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
|
5029 |
type == #directory ifTrue:[ ^ nil ]. |
11406
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
5030 |
type == #characterSpecial ifTrue:[ ^ nil ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
5031 |
type == #blockSpecial ifTrue:[ ^ nil ]. |
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
5032 |
type == #socket ifTrue:[ ^ nil ]. |
5011 | 5033 |
self fileSize == 0 ifTrue:[^ nil]. |
5034 |
||
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
5035 |
s := self readStreamOrNil. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
5036 |
s isNil ifTrue:[^ nil]. |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
5037 |
|
5011 | 5038 |
"/ read some data from the file ... |
7685
535a69a7cd69
String new -> uninitializedNew: / basicNew:
Claus Gittinger <cg@exept.de>
parents:
7680
diff
changeset
|
5039 |
buffer := String new:2048. |
5011 | 5040 |
|
6943
910f4b17c342
care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6908
diff
changeset
|
5041 |
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
|
5042 |
size := 0. |
6943
910f4b17c342
care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6908
diff
changeset
|
5043 |
] do:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5044 |
size := s nextBytes:buffer size into:buffer. |
6943
910f4b17c342
care for unreadable contents in mimeTypeOfContents
Claus Gittinger <cg@exept.de>
parents:
6908
diff
changeset
|
5045 |
]. |
5011 | 5046 |
s close. |
11406
af2c2118e164
refactored - mimetypeofdata now where it belongs to
Claus Gittinger <cg@exept.de>
parents:
11397
diff
changeset
|
5047 |
|
16755 | 5048 |
"/ kludge to avoid making libview a prereq. of libbasic |
17111 | 5049 |
(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
|
5050 |
^ mimeTypes mimeTypeOfData:buffer suffix:self suffix. |
16755 | 5051 |
]. |
5052 |
^ nil |
|
5011 | 5053 |
|
5054 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5055 |
'Makefile' asFilename mimeTypeOfContents |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5056 |
'.' asFilename mimeTypeOfContents |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5057 |
'/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
|
5058 |
'/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
|
5059 |
'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
|
5060 |
'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
|
5061 |
'../../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
|
5062 |
'/bläh' asFilename mimeTypeOfContents |
10153 | 5063 |
'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
|
5064 |
'G:\A\A01.TOP' asFilename mimeTypeOfContents |
10153 | 5065 |
" |
5066 |
||
5067 |
"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
|
5068 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5069 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5070 |
!Filename methodsFor:'queries-path & name'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5071 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5072 |
baseName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5073 |
"return my baseName as a string. |
20413 | 5074 |
- that's the file/directory name without leading parent-dirs. |
2922 | 5075 |
(i.e. '/usr/lib/st/file' asFilename baseName -> 'file' |
5076 |
and '/usr/lib' asFilename baseName -> lib). |
|
7075 | 5077 |
This method does not check if the path is valid. |
5078 |
The code here should work for Unix and MSDOS, but needs to be redefined |
|
5079 |
for VMS (and maybe others as well). |
|
2911 | 5080 |
See also: #pathName, #directoryName and #directoryPathName. |
5081 |
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
|
5082 |
|
2922 | 5083 |
|len index sep endIdx| |
5084 |
||
5085 |
sep := self separator. |
|
5086 |
len := nameString size. |
|
5087 |
((len == 1) and:[(nameString at:1) == sep]) ifTrue:[ |
|
20413 | 5088 |
^ nameString |
2922 | 5089 |
]. |
5090 |
||
5091 |
endIdx := len. |
|
5092 |
len > 1 ifTrue:[ |
|
20413 | 5093 |
(nameString at:len) == sep ifTrue:[endIdx := endIdx - 1]. |
2922 | 5094 |
]. |
5095 |
index := nameString lastIndexOf:sep startingAt:len-1. |
|
5096 |
^ 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
|
5097 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5098 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5099 |
'/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
|
5100 |
'/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
|
5101 |
'.' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5102 |
'..' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5103 |
'../..' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5104 |
'../../libbasic' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5105 |
'../../libpr' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5106 |
'../../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
|
5107 |
'/' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5108 |
'\' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5109 |
'c:\' asFilename baseName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5110 |
'\\idefix' asFilename baseName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5111 |
" |
2012 | 5112 |
|
3851 | 5113 |
"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
|
5114 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5115 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5116 |
directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5117 |
"return the directory name part of the file/directory as a new filename. |
20413 | 5118 |
- 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
|
5119 |
the receiver is contained in. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5120 |
(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
|
5121 |
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
|
5122 |
|
15811 | 5123 |
^ self species named:(self directoryName) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5124 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5125 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5126 |
'/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
|
5127 |
'/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
|
5128 |
'/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
|
5129 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5130 |
'.' asFilename directory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5131 |
'..' asFilename directory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5132 |
'../..' asFilename directory |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5133 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5134 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5135 |
"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
|
5136 |
! |
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 |
directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5139 |
"return the directory name part of the file/directory as a string. |
20413 | 5140 |
- 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
|
5141 |
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
|
5142 |
This method does not check if the path is valid. |
2922 | 5143 |
|
5144 |
(i.e. '/usr/lib/st/file' asFilename directoryName -> '/usr/lib/st' |
|
5145 |
and '/usr/lib' asFilename directoryName -> /usr'). |
|
5146 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5147 |
(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
|
5148 |
a string instead of a Filename instance). |
2922 | 5149 |
|
2012 | 5150 |
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
|
5151 |
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
|
5152 |
|
16389 | 5153 |
|index sep sepString p rest parentDirectoryString| |
2922 | 5154 |
|
5155 |
sep := self separator. |
|
5156 |
sepString := sep asString. |
|
5157 |
(nameString = sepString) ifTrue:[ |
|
20413 | 5158 |
"/ |
5159 |
"/ the trivial '/' case |
|
5160 |
"/ |
|
5161 |
^ sepString |
|
2922 | 5162 |
]. |
5163 |
||
5164 |
"/ |
|
3893 | 5165 |
"/ strip off multiple trailing slashes |
2922 | 5166 |
"/ |
5167 |
p := nameString. |
|
16389 | 5168 |
[p endsWith:sep] whileTrue:[ |
20413 | 5169 |
(p = sepString) ifTrue:[ |
5170 |
^ sepString |
|
5171 |
]. |
|
5172 |
p := p copyButLast:1 |
|
2922 | 5173 |
]. |
5174 |
||
16389 | 5175 |
parentDirectoryString := self class parentDirectoryName. |
5176 |
||
3886
e6efeb877eda
fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents:
3876
diff
changeset
|
5177 |
"/ strip off trailing components |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
5178 |
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
|
5179 |
index == 0 ifTrue:[ |
20413 | 5180 |
"/ no separator found |
5181 |
p = '.' ifTrue:[ |
|
5182 |
^ parentDirectoryString |
|
5183 |
]. |
|
5184 |
p = '..' ifTrue:[ |
|
5185 |
^ parentDirectoryString, sepString, parentDirectoryString |
|
5186 |
]. |
|
5187 |
^ '.' |
|
2922 | 5188 |
]. |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
5189 |
rest := p copyFrom:(index+1). |
7342
4e9ff418113f
fixed for directory name ending with '/..'
Claus Gittinger <cg@exept.de>
parents:
7332
diff
changeset
|
5190 |
(rest = '.') ifTrue:[ |
20413 | 5191 |
^ p copyTo:index-1. |
7342
4e9ff418113f
fixed for directory name ending with '/..'
Claus Gittinger <cg@exept.de>
parents:
7332
diff
changeset
|
5192 |
]. |
16389 | 5193 |
(rest = parentDirectoryString) ifTrue:[ |
20413 | 5194 |
^ (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
|
5195 |
]. |
3893 | 5196 |
index == 1 ifTrue:[ |
20413 | 5197 |
^ sepString |
3893 | 5198 |
]. |
3888
a528db31e5c0
had to change #directoryName again - it did not work.
Claus Gittinger <cg@exept.de>
parents:
3886
diff
changeset
|
5199 |
^ p copyTo:(index - 1) |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5200 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5201 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5202 |
'/home' asFilename directoryName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5203 |
'/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
|
5204 |
'/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
|
5205 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5206 |
'/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
|
5207 |
'bitmaps' asFilename directoryName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5208 |
'bitmaps' asFilename directoryPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5209 |
'.' asFilename directoryName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5210 |
'.' asFilename directoryPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5211 |
'..' asFilename directoryName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5212 |
'..' asFilename directoryPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5213 |
'../..' asFilename directoryName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5214 |
'../..' asFilename directoryPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5215 |
'/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
|
5216 |
'/foo/bar/baz/.' asFilename directoryName |
21064 | 5217 |
'c:\' asFilename directoryName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5218 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5219 |
|
3886
e6efeb877eda
fixed #directory & #directoryName for
Claus Gittinger <cg@exept.de>
parents:
3876
diff
changeset
|
5220 |
"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
|
5221 |
"Modified: / 21.10.1998 / 22:52:25 / cg" |
3893 | 5222 |
"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
|
5223 |
! |
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 |
directoryPathName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5226 |
"return the full directory pathname part of the file/directory as a string. |
20413 | 5227 |
- 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
|
5228 |
the receiver is contained in. |
2012 | 5229 |
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
|
5230 |
|
15811 | 5231 |
^ (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
|
5232 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5233 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5234 |
'/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
|
5235 |
'/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
|
5236 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5237 |
'.' asFilename directoryPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5238 |
'.' asFilename directoryName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5239 |
'.' asFilename directory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5240 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5241 |
'..' asFilename directoryPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5242 |
'..' asFilename directoryName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5243 |
'..' asFilename directory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5244 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5245 |
'../..' asFilename directoryPathName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5246 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5247 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5248 |
"Modified: 7.9.1995 / 10:42:13 / claus" |
2012 | 5249 |
"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
|
5250 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5251 |
|
14567 | 5252 |
encodedNameString |
5253 |
"answer the name as passed to OS system calls" |
|
5254 |
||
5255 |
^ OperatingSystem encodePath:nameString |
|
5256 |
! |
|
5257 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5258 |
filenameCompletion |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5259 |
"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
|
5260 |
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
|
5261 |
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
|
5262 |
it returns a collection of matching filename objects, |
19440 | 5263 |
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
|
5264 |
match. |
19440 | 5265 |
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
|
5266 |
If there is only one match, the size of the returned collection is exactly 1, |
19752 | 5267 |
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
|
5268 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5269 |
^ self filenameCompletionIn:nil |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5270 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5271 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5272 |
'mak' asFilename filenameCompletion |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5273 |
'Make' asFilename filenameCompletion |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5274 |
'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
|
5275 |
'/u' asFilename filenameCompletion |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5276 |
'../../libpr' asFilename inspect filenameCompletion |
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 |
|
1517 | 5279 |
"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
|
5280 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5281 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5282 |
filenameCompletionIn:aDirectory |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5283 |
"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
|
5284 |
|
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
5285 |
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
|
5286 |
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
|
5287 |
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
|
5288 |
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
|
5289 |
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
|
5290 |
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
|
5291 |
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
|
5292 |
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
|
5293 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5294 |
|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
|
5295 |
sepString parentString prefix nMatch nm caseless lcBaseName| |
3666 | 5296 |
|
15811 | 5297 |
mySpecies := self species. |
5298 |
||
5299 |
caseless := mySpecies isCaseSensitive not. |
|
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
5300 |
matching := OrderedCollection new. |
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
5301 |
|
15811 | 5302 |
nm := mySpecies nameWithSpecialExpansions:nameString. |
5303 |
nm := mySpecies canonicalize:nm. |
|
5304 |
||
5305 |
sepString := mySpecies separatorString. |
|
3666 | 5306 |
(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
|
5307 |
"/ two exceptions here: |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5308 |
"/ 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
|
5309 |
"/ 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
|
5310 |
self isDirectory ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5311 |
|first longest| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5312 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5313 |
first := nil. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5314 |
OpenError catch:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5315 |
self directoryContentsDo:[:fileName | |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5316 |
((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
|
5317 |
matching add:fileName. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5318 |
first isNil ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5319 |
first := longest := fileName. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5320 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5321 |
"/ 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
|
5322 |
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
|
5323 |
longest isEmpty ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5324 |
^ #() |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5325 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5326 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5327 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5328 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5329 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5330 |
longest notNil ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5331 |
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
|
5332 |
^ matching |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5333 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5334 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5335 |
^ #() |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5336 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5337 |
|
15811 | 5338 |
parentString := mySpecies parentDirectoryName. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5339 |
baseName := self baseName. |
3666 | 5340 |
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
|
5341 |
prefix := self directoryName. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5342 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5343 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5344 |
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
|
5345 |
dir := self directory |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5346 |
] ifFalse:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5347 |
aDirectory isNil ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5348 |
dir := self directory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5349 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5350 |
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
|
5351 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5352 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5353 |
|
3774
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
5354 |
caseless ifTrue:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5355 |
lcBaseName := baseName asLowercase |
3774
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
5356 |
]. |
e2a75c79c625
ignore case in fileNameCompletion, on systems where case is ignored
Claus Gittinger <cg@exept.de>
parents:
3768
diff
changeset
|
5357 |
|
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
5358 |
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
|
5359 |
^ #(). |
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
5360 |
] do:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5361 |
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
|
5362 |
((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
|
5363 |
((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
|
5364 |
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
|
5365 |
matching add:fileName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5366 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5367 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5368 |
]. |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5369 |
]. |
6556
367bc84f51fc
filename completion better if an empty basename is shown
Claus Gittinger <cg@exept.de>
parents:
6529
diff
changeset
|
5370 |
|
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5371 |
(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
|
5372 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5373 |
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
|
5374 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5375 |
matchLen := baseName size. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5376 |
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
|
5377 |
try := baseName. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5378 |
allMatching := false |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5379 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5380 |
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
|
5381 |
allMatching := true. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5382 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5383 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5384 |
[allMatching] whileTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5385 |
matching do:[:aName | |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5386 |
((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
|
5387 |
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
|
5388 |
allMatching := false |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5389 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5390 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5391 |
allMatching ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5392 |
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
|
5393 |
matchLen := matchLen + 1. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5394 |
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
|
5395 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5396 |
allMatching := false |
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 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5399 |
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
|
5400 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5401 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5402 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5403 |
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
|
5404 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5405 |
nameString := nm := try |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5406 |
]. |
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 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5409 |
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
|
5410 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5411 |
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
|
5412 |
(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
|
5413 |
"/ 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
|
5414 |
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
|
5415 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5416 |
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
|
5417 |
nMatch == 1 ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5418 |
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
|
5419 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5420 |
nMatch > 1 ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5421 |
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
|
5422 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5423 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5424 |
] ifFalse:[ |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5425 |
nMatch == 1 ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5426 |
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
|
5427 |
] |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5428 |
]. |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5429 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5430 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5431 |
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
|
5432 |
(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
|
5433 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5434 |
^ matching |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5435 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5436 |
" trivial cases: |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5437 |
|
11341
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5438 |
'../' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5439 |
'/' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5440 |
'/usr/' asFilename filenameCompletion -> empty |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5441 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5442 |
'mak' asFilename filenameCompletion |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5443 |
'Make' asFilename filenameCompletion |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5444 |
'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
|
5445 |
'/u' asFilename filenameCompletion |
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
5446 |
'../../libpr' asFilename filenameCompletion |
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
5447 |
'/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
|
5448 |
|
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5449 |
'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
|
5450 |
'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
|
5451 |
'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
|
5452 |
'c:\' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5453 |
'c:' asFilename filenameCompletion -> empty |
22494c109161
fixed filename completion for root directories (added another sep-char)
Claus Gittinger <cg@exept.de>
parents:
11192
diff
changeset
|
5454 |
'\' asFilename filenameCompletion -> empty |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5455 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5456 |
|
10793
0475c364e80a
care for bad (non-filename) arg in fileNameCompletion:
Claus Gittinger <cg@exept.de>
parents:
10780
diff
changeset
|
5457 |
"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
|
5458 |
"Modified: / 17-11-2007 / 14:31:08 / cg" |
2903 | 5459 |
! |
5460 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5461 |
head |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5462 |
"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
|
5463 |
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
|
5464 |
(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
|
5465 |
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
|
5466 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5467 |
^ self directoryName |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5468 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5469 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5470 |
Filename currentDirectory head |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5471 |
'Makefile' asFilename head |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5472 |
'/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
|
5473 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5474 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5475 |
"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
|
5476 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5477 |
|
7120 | 5478 |
isAbsolute |
5479 |
"return true, if the receiver represents an absolute pathname |
|
5480 |
(in contrast to one relative to the current directory)." |
|
5481 |
||
19670 | 5482 |
((nameString startsWith:self species separator) or:[nameString startsWith:$~]) ifTrue:[^ true]. |
7120 | 5483 |
^ self isVolumeAbsolute |
5484 |
||
5485 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5486 |
'/foo/bar' asFilename isAbsolute |
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
5487 |
'~/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
|
5488 |
'..' asFilename isAbsolute |
20459 | 5489 |
'..' 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
|
5490 |
'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
|
5491 |
'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
|
5492 |
'SBrowser.st' asFilename isRelative |
7120 | 5493 |
" |
5494 |
! |
|
5495 |
||
21390 | 5496 |
isBackupFilename |
5497 |
"return true, if this name is an for a backup file" |
|
5498 |
||
5499 |
^ nameString last == $~ or:[self hasSuffix:'bak']. |
|
5500 |
||
5501 |
"Created: / 09-02-2017 / 13:57:03 / stefan" |
|
5502 |
! |
|
5503 |
||
7120 | 5504 |
isExplicitRelative |
5505 |
"return true, if this name is an explicit relative name |
|
5506 |
(i.e. starts with './' or '../', to avoid path-prepending)" |
|
5507 |
||
5508 |
^ false |
|
5509 |
! |
|
5510 |
||
5511 |
isImplicit |
|
5512 |
"return true, if the receiver represents a builtin file. |
|
5513 |
The definitions of builtin files depends on the OS used; |
|
5514 |
on UNIX, '.' and '..' are builtin names." |
|
5515 |
||
5516 |
^ false |
|
5517 |
||
5518 |
"Created: 18.9.1997 / 18:04:51 / stefan" |
|
5519 |
! |
|
5520 |
||
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5521 |
isParentDirectoryOf:aFilenameOrString |
16389 | 5522 |
"Answer true, if myself is a parent directory of aFilenameOrString. |
5523 |
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
|
5524 |
not exist and relative and absolute path names are mixed |
18686 | 5525 |
('/' asFilename isParentDirectoryOf:'../noExistent' -> false) |
16389 | 5526 |
|
5527 |
Warning: maybe symbolic links must be resolved which could lead to automounting" |
|
5528 |
||
5529 |
|filenameArg otherNames myNames myName| |
|
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5530 |
|
7236
2b8b8680f5b9
isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents:
7134
diff
changeset
|
5531 |
filenameArg := aFilenameOrString asFilename. |
16389 | 5532 |
|
5533 |
"first do a simple comparison" |
|
5534 |
otherNames := self class canonicalizedNameComponents:filenameArg name. |
|
5535 |
myNames := self class canonicalizedNameComponents:self name. |
|
5536 |
((otherNames startsWith:myNames) and:[myNames first ~= self class parentDirectoryName]) ifTrue:[ |
|
19599 | 5537 |
^ otherNames ~= myNames |
7236
2b8b8680f5b9
isParentDirectoryOf - fix for directories
Claus Gittinger <cg@exept.de>
parents:
7134
diff
changeset
|
5538 |
]. |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5539 |
|
16389 | 5540 |
"fall back - try it again with ~ substitution and symbolic links resolved" |
5541 |
otherNames := self class canonicalizedNameComponents:filenameArg pathName. |
|
5542 |
myNames := self class canonicalizedNameComponents:self pathName. |
|
5543 |
(otherNames startsWith:myNames) ifTrue:[ |
|
19599 | 5544 |
^ otherNames ~= myNames |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5545 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5546 |
|
16389 | 5547 |
myName := self class nameFromComponents:myNames. |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5548 |
filenameArg allParentDirectoriesDo:[:parent | |
19599 | 5549 |
parent pathName = myName ifTrue:[^ true]. |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5550 |
]. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5551 |
^ false. |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5552 |
|
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5553 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5554 |
'/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
|
5555 |
'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
|
5556 |
'/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
|
5557 |
'/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
|
5558 |
'/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
|
5559 |
'/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
|
5560 |
'~' 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
|
5561 |
'~' asFilename isParentDirectoryOf:'.' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5562 |
'~' asFilename isParentDirectoryOf:'..' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5563 |
'~' asFilename isParentDirectoryOf:'../smalltalk' |
18686 | 5564 |
'../..' asFilename isParentDirectoryOf:'../nonExistent' |
5565 |
'..' asFilename isParentDirectoryOf:'../../nonExistent' |
|
5566 |
'/' 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
|
5567 |
'/' 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
|
5568 |
" |
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5569 |
! |
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5570 |
|
7120 | 5571 |
isRelative |
5572 |
"return true, if this name is interpreted relative to some |
|
5573 |
directory (opposite of absolute)" |
|
5574 |
||
5575 |
^ self isAbsolute not |
|
5576 |
||
5577 |
" |
|
5578 |
'./foo/bar' asFilename isRelative |
|
5579 |
'../../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
|
5580 |
'/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
|
5581 |
'bar' asFilename isRelative |
7120 | 5582 |
" |
5583 |
||
5584 |
"Modified: 16.1.1997 / 01:19:14 / cg" |
|
5585 |
! |
|
5586 |
||
5587 |
isRootDirectory |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5588 |
"return true, if I represent the root directory |
7120 | 5589 |
(i.e. I have no parentDir)" |
5590 |
||
5591 |
"/ mhmh - should we use: |
|
5592 |
"/ |
|
5593 |
"/ parentDir := self construct:'..'. |
|
5594 |
"/ (parentDir exists |
|
5595 |
"/ and:[parentDir isDirectory |
|
5596 |
"/ and:[parentDir id ~= self id]]) ifTrue:[ |
|
5597 |
"/ ^ false |
|
5598 |
"/ ]. |
|
5599 |
"/ ^ true |
|
5600 |
"/ |
|
5601 |
||
5602 |
^ self pathName = Filename rootDirectory pathName |
|
5603 |
||
5604 |
"Modified: 23.10.1997 / 00:38:35 / cg" |
|
5605 |
! |
|
5606 |
||
5607 |
isVolumeAbsolute |
|
5608 |
"return true, if the receiver represents an absolute pathname |
|
5609 |
on some disk volume (MSDOS only)" |
|
5610 |
||
5611 |
^ false |
|
5612 |
||
5613 |
"Modified: 7.9.1997 / 23:54:33 / cg" |
|
5614 |
! |
|
5615 |
||
2987
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
5616 |
localPathName |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
5617 |
"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
|
5618 |
but without any volume information. |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
5619 |
Only makes a difference on MSDOS & VMS systems." |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
5620 |
|
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
5621 |
^ self pathName |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
5622 |
! |
87a7ad1f4519
Simplify #accessTime and #modificationTime
Stefan Vogel <sv@exept.de>
parents:
2982
diff
changeset
|
5623 |
|
615 | 5624 |
name |
5625 |
"return the name of the file represented by the receiver as a string. |
|
883 | 5626 |
This may or may not be a relative name (i.e. include ..'s). |
615 | 5627 |
See also: pathName" |
174 | 5628 |
|
6773
26415b61ad09
isMountPoint & isParentDirectoryOf & allParentDirsDo:
penk
parents:
6771
diff
changeset
|
5629 |
"/ self isAbsolute ifTrue:[^ self pathName]. |
615 | 5630 |
^ nameString |
174 | 5631 |
|
5632 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5633 |
'/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
|
5634 |
'/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
|
5635 |
'.' asFilename name |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5636 |
'.' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5637 |
'../..' asFilename name |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5638 |
'../..' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5639 |
'bitmaps' asFilename name |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5640 |
'bitmaps' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5641 |
'/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
|
5642 |
'/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
|
5643 |
'source/..' asFilename name |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5644 |
'source/..' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5645 |
'/tmp/..' asFilename name |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5646 |
'/tmp/..' asFilename pathName |
92 | 5647 |
" |
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
5648 |
|
883 | 5649 |
"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
|
5650 |
! |
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
5651 |
|
615 | 5652 |
pathName |
5653 |
"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
|
5654 |
as a string. This will not include ..'s. |
1317 | 5655 |
If the path represented by the receiver does NOT represent a valid path, |
5656 |
no compression will be done (for now; this may change). |
|
5657 |
See also: name" |
|
538
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
5658 |
|
b9337c6c55bb
added recursiveRemove; remove now also removes directories
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
5659 |
|
1317 | 5660 |
"/ sep := self class separator. |
5661 |
"/ (nameString startsWith:sep) ifTrue:[ |
|
5662 |
"/ parentName := self class parentDirectoryName. |
|
5663 |
"/ (nameString findString:parentName) == 0 ifTrue:[ |
|
5664 |
"/ ^ nameString |
|
5665 |
"/ ] |
|
5666 |
"/ ]. |
|
15811 | 5667 |
^ OperatingSystem pathNameOf:(self species nameWithSpecialExpansions:nameString). |
2 | 5668 |
|
92 | 5669 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5670 |
'/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
|
5671 |
'.' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5672 |
'../..' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5673 |
'../..' asFilename name |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5674 |
'/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
|
5675 |
'/././usr' asFilename pathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5676 |
'~/..' asFilename pathName |
92 | 5677 |
" |
159 | 5678 |
|
1317 | 5679 |
"Modified: 27.4.1996 / 18:19:52 / cg" |
174 | 5680 |
! |
5681 |
||
11658 | 5682 |
physicalFilename |
5683 |
"return the fileName representing the physical file as represented by the receiver, |
|
20413 | 5684 |
If the receiver represents a symbolic link, that's the fileName of the |
19440 | 5685 |
final target. Otherwise, its the receiver's pathName itself. |
11658 | 5686 |
If any file along the symbolic path does not exist (i.e. is a broken link), |
5687 |
nil is returned." |
|
5688 |
||
5689 |
|pathOrNil| |
|
5690 |
||
5691 |
pathOrNil := self physicalPathName. |
|
5692 |
pathOrNil isNil ifTrue:[ |
|
20413 | 5693 |
^ nil |
11658 | 5694 |
]. |
5695 |
^ pathOrNil asFilename |
|
5696 |
||
5697 |
" |
|
20708 | 5698 |
'/foo/bar' asFilename physicalFilename |
11658 | 5699 |
" |
5700 |
! |
|
5701 |
||
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5702 |
physicalPathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5703 |
"return the full pathname of the physical file represented by the receiver, |
20413 | 5704 |
If the receiver represents a symbolic link, that's the fileName of the |
19440 | 5705 |
final target. Otherwise, its the receiver's pathName itself. |
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5706 |
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
|
5707 |
nil is returned." |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5708 |
|
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
5709 |
|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
|
5710 |
|
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
5711 |
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
|
5712 |
info isNil ifTrue:[ |
20413 | 5713 |
" I do not exist" |
5714 |
^ nil. |
|
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5715 |
]. |
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
5716 |
info isSymbolicLink ifFalse:[ |
20413 | 5717 |
^ 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
|
5718 |
]. |
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
5719 |
|
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5720 |
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
|
5721 |
[ |
20413 | 5722 |
path := info path. |
5723 |
path isNil ifTrue:[ |
|
5724 |
"/ cannot happen |
|
5725 |
^ nil |
|
5726 |
]. |
|
5727 |
path asFilename isAbsolute ifTrue:[ |
|
5728 |
t := path asFilename |
|
5729 |
] ifFalse:[ |
|
5730 |
t := (self species named:t directoryName) construct:path. |
|
5731 |
]. |
|
5732 |
info := t linkInfo. |
|
5733 |
info isNil ifTrue:[ |
|
5734 |
"t does not exist" |
|
5735 |
^ nil |
|
5736 |
]. |
|
8477
c962d56c1973
#linkInfo now returns the info also for files that are not a symlink
Stefan Vogel <sv@exept.de>
parents:
8280
diff
changeset
|
5737 |
] 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
|
5738 |
|
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5739 |
^ t pathName |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5740 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5741 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5742 |
'/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
|
5743 |
'.' asFilename physicalPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5744 |
'../..' asFilename physicalPathName |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5745 |
'/usr/tmp' asFilename physicalPathName |
2013
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5746 |
" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5747 |
|
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5748 |
"Modified: 21.12.1996 / 15:29:50 / cg" |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5749 |
! |
5053effe0156
commentary; added #physicalPathName
Claus Gittinger <cg@exept.de>
parents:
2012
diff
changeset
|
5750 |
|
615 | 5751 |
tail |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5752 |
"the file's name without directory prefix as a string. |
615 | 5753 |
An alias for baseName, for ST-80 compatiblity." |
174 | 5754 |
|
615 | 5755 |
^ self baseName |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5756 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5757 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5758 |
Filename currentDirectory tail |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5759 |
'Makefile' asFilename tail |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5760 |
'/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
|
5761 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5762 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5763 |
"Modified: 29.2.1996 / 20:19:50 / cg" |
2629 | 5764 |
! |
5765 |
||
7307
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5766 |
tail:nComponents |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5767 |
"return the last n components of myself. |
20413 | 5768 |
- 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
|
5769 |
(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
|
5770 |
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
|
5771 |
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
|
5772 |
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
|
5773 |
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
|
5774 |
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
|
5775 |
|
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5776 |
|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
|
5777 |
|
15811 | 5778 |
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
|
5779 |
components := self components. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5780 |
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
|
5781 |
start < 1 ifTrue:[ |
20413 | 5782 |
start := 1. |
7307
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5783 |
]. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5784 |
start = 1 ifTrue:[ |
20413 | 5785 |
tail := '' |
7307
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5786 |
] ifFalse:[ |
20413 | 5787 |
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
|
5788 |
]. |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5789 |
start+1 to:components size do:[:i| |
20413 | 5790 |
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
|
5791 |
]. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5792 |
^ tail. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5793 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5794 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5795 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5796 |
'/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
|
5797 |
'/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
|
5798 |
'/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
|
5799 |
'/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
|
5800 |
'.' asFilename tail:3 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5801 |
'..' asFilename tail:3 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5802 |
'../..' asFilename tail:2 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5803 |
'../../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
|
5804 |
'../../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
|
5805 |
'../../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
|
5806 |
'../../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
|
5807 |
'/' asFilename tail:2 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5808 |
'\' asFilename tail:2 |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5809 |
'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
|
5810 |
'\\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
|
5811 |
" |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5812 |
! |
9cae11d1fea1
new tail: to get the last n path components (as String)
Stefan Vogel <sv@exept.de>
parents:
7291
diff
changeset
|
5813 |
|
2629 | 5814 |
volume |
5815 |
"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
|
5816 |
This is only used with MSDOS and VMS filenames |
2906 | 5817 |
- by default (and on unix), an empty string is returned" |
5818 |
||
2629 | 5819 |
^ '' |
2906 | 5820 |
|
5821 |
"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
|
5822 |
! ! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
5823 |
|
7120 | 5824 |
!Filename methodsFor:'queries-type'! |
5825 |
||
5826 |
isDirectory |
|
5827 |
"return true, if the receiver represents an existing, |
|
5828 |
readable directories pathname." |
|
5829 |
||
5830 |
^ OperatingSystem isDirectory:(self osNameForAccess) |
|
5831 |
||
5832 |
" |
|
5833 |
'/foo/bar' asFilename isDirectory |
|
5834 |
'/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
|
5835 |
'Makefile' asFilename isDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5836 |
'c:\' asFilename isDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5837 |
'd:\' asFilename isDirectory |
7120 | 5838 |
" |
5839 |
||
5840 |
"Modified: / 21.9.1998 / 15:53:10 / cg" |
|
5841 |
! |
|
5842 |
||
5843 |
isNonEmptyDirectory |
|
5844 |
"return true, if the receiver represents an existing, |
|
5845 |
readable directories pathname, and the directory is not empty." |
|
5846 |
||
8280
0caa2f092e45
avoid expensive full-blocks (which return)
Claus Gittinger <cg@exept.de>
parents:
8243
diff
changeset
|
5847 |
FileStream openErrorSignal |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5848 |
handle:[:ex| ] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5849 |
do:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5850 |
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
|
5851 |
]. |
7120 | 5852 |
^ false. |
5853 |
||
5854 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5855 |
'/foo/bar' asFilename isNonEmptyDirectory |
7120 | 5856 |
'/tmp' asFilename isNonEmptyDirectory |
5857 |
'/tmp/empty' asFilename makeDirectory; isNonEmptyDirectory. |
|
5858 |
'/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
|
5859 |
'Makefile' asFilename isNonEmptyDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5860 |
'c:\' asFilename isNonEmptyDirectory |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5861 |
'd:\' asFilename isNonEmptyDirectory |
7120 | 5862 |
" |
5863 |
||
5864 |
"Modified: / 21.9.1998 / 15:53:10 / cg" |
|
5865 |
! |
|
5866 |
||
8836 | 5867 |
isRegularFile |
5868 |
"return true, if the receiver represents a plain, regular file" |
|
5869 |
||
5870 |
^ self type == #regular |
|
5871 |
||
5872 |
" |
|
5873 |
'/foo/bar' asFilename isRegularFile |
|
5874 |
'/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
|
5875 |
'Makefile' asFilename isRegularFile |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5876 |
'c:\' asFilename isRegularFile |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5877 |
'd:\' asFilename isRegularFile |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5878 |
'/dev/null' asFilename isRegularFile |
8836 | 5879 |
" |
5880 |
! |
|
5881 |
||
7120 | 5882 |
isSpecialFile |
5883 |
"return true, if the receiver represents a socket, named pipe, fifo |
|
5884 |
or device special file (i.e. anything non regular and non-directory)" |
|
5885 |
||
5886 |
|t| |
|
5887 |
||
5888 |
t := self type. |
|
5889 |
^ (t ~= #directory and:[t ~~ #regular and:[t ~~ #symbolicLink]]) |
|
5890 |
||
5891 |
" |
|
5892 |
'/foo/bar' asFilename isSpecialFile |
|
5893 |
'/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
|
5894 |
'Makefile' asFilename isSpecialFile |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5895 |
'c:\' asFilename isSpecialFile |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5896 |
'd:\' asFilename isSpecialFile |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5897 |
'/dev/null' asFilename isSpecialFile |
7120 | 5898 |
" |
5899 |
! |
|
5900 |
||
5901 |
isSymbolicLink |
|
5902 |
"return true, if the file represented by the receiver is a symbolic |
|
5903 |
link. Notice that not all OS's support symbolic links; those that do |
|
5904 |
not will always return false." |
|
5905 |
||
5906 |
^ OperatingSystem isSymbolicLink:(self osNameForFile) |
|
5907 |
||
5908 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5909 |
'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
|
5910 |
'Makefile' asFilename isSymbolicLink |
7120 | 5911 |
" |
5912 |
! ! |
|
5913 |
||
6529 | 5914 |
!Filename methodsFor:'reading-directories'! |
5915 |
||
5916 |
directoryContents |
|
5917 |
"return the contents of the directory as a collection of strings. |
|
5918 |
This excludes any entries for '.' or '..'. |
|
5919 |
Returns nil for non-existing directories; however, this behavior |
|
5920 |
may be changed in the near future, to raise an exception instead. |
|
5921 |
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
|
5922 |
Notice: |
19821 | 5923 |
this returns the file-names as strings; |
5924 |
see also #directoryContentsAsFilenames, which returns fileName instances." |
|
5925 |
||
5926 |
^ OrderedCollection withCollectedContents:[:coll | |
|
5927 |
self directoryContentsDo:[:each | coll add:each]] |
|
6529 | 5928 |
|
5929 |
" |
|
5930 |
'.' asFilename directoryContents |
|
5931 |
'/XXXdoesNotExist' asFilename directoryContents |
|
5932 |
" |
|
5933 |
||
5934 |
"Modified: / 18.9.1997 / 18:42:23 / stefan" |
|
5935 |
"Modified: / 3.8.1998 / 21:36:21 / cg" |
|
5936 |
! |
|
5937 |
||
5938 |
directoryContentsAsFilenames |
|
5939 |
"return the contents of the directory as a collection of filenames. |
|
5940 |
This excludes any entries for '.' or '..'. |
|
5941 |
Returns nil for non-existing directories; however, this behavior |
|
5942 |
may be changed in the near future, to raise an exception instead. |
|
5943 |
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
|
5944 |
Notice: |
19821 | 5945 |
this returns the file-names as fileName instances; |
5946 |
see also #directoryContents, which returns strings." |
|
5947 |
||
5948 |
^ OrderedCollection withCollectedContents:[:coll | |
|
5949 |
self directoryContentsAsFilenamesDo:[:each | coll add:each]] |
|
6529 | 5950 |
|
5951 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5952 |
'.' asFilename directoryContentsAsFilenames |
6529 | 5953 |
'/XXXdoesNotExist' asFilename directoryContentsAsFilenames |
5954 |
" |
|
5955 |
! |
|
5956 |
||
5957 |
fullDirectoryContents |
|
5958 |
"return the full contents of the directory as a collection of strings. |
|
5959 |
This is much like #directoryContents, but includes an entry for the |
|
5960 |
parent directory, if there is one. |
|
5961 |
Returns nil for non-existing directories; however, this behavior |
|
5962 |
may be changed in the near future, to raise an exception instead. |
|
5963 |
So users of this method better test for existing directory before." |
|
5964 |
||
5965 |
|files| |
|
5966 |
||
12910 | 5967 |
"here we get the files without '.' and '..'" |
6529 | 5968 |
files := self directoryContents. |
5969 |
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
|
5970 |
"/ 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
|
5971 |
^ files |
6529 | 5972 |
]. |
5973 |
||
12910 | 5974 |
files addFirst:'..'. |
6529 | 5975 |
^ files |
5976 |
||
5977 |
" |
|
5978 |
'.' asFilename fullDirectoryContents |
|
5979 |
'/XXXdoesNotExist' asFilename fullDirectoryContents |
|
5980 |
'd:\FET' asFilename fullDirectoryContents |
|
5981 |
" |
|
5982 |
||
5983 |
"Modified: / 21.9.1998 / 15:33:07 / cg" |
|
5984 |
! |
|
5985 |
||
5986 |
recursiveDirectoryContents |
|
5987 |
"return the contents of the directory and all subdirectories |
|
5988 |
as a collection of strings. |
|
5989 |
This excludes any entries for '.' or '..'. |
|
5990 |
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
|
5991 |
Notice: |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
5992 |
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
|
5993 |
see also #recursiveDirectoryContentsAsFilenames, which returns fileName instances. |
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
5994 |
|
6529 | 5995 |
Warning: this may take a long time to execute." |
5996 |
||
5997 |
|fileNames dirNames| |
|
5998 |
||
5999 |
fileNames := OrderedCollection new. |
|
6000 |
dirNames := OrderedCollection new. |
|
6001 |
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
|
6002 |
(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
|
6003 |
dirNames add:f |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6004 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6005 |
fileNames add:f |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6006 |
] |
6529 | 6007 |
]. |
6008 |
||
6009 |
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
|
6010 |
|dd subFiles| |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6011 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6012 |
dd := dN asFilename. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6013 |
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
|
6014 |
fileNames addAll:(subFiles collect:[:f | dd constructString:f]) |
6529 | 6015 |
]. |
6016 |
^ fileNames. |
|
6017 |
||
6018 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6019 |
'.' asFilename recursiveDirectoryContents |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6020 |
'../../clients' asFilename recursiveDirectoryContents |
6529 | 6021 |
" |
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6022 |
! |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6023 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6024 |
recursiveDirectoryContentsAsFilenames |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6025 |
"return the contents of the directory and all subdirectories |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6026 |
as a collection of filenames. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6027 |
This excludes any entries for '.' or '..'. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6028 |
Returns nil for non-existing directories; however, this behavior |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6029 |
may be changed in the near future, to raise an exception instead. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6030 |
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
|
6031 |
Notice: |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6032 |
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
|
6033 |
see also #recursiveDirectoryContents, which returns strings. |
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6034 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6035 |
Warning: this may take a long time to execute." |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6036 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6037 |
|names| |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6038 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6039 |
names := self recursiveDirectoryContents. |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6040 |
names isNil ifTrue:[^ nil]. |
12910 | 6041 |
^ names collect:[:entry | self construct:entry]. |
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6042 |
|
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6043 |
" |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6044 |
'.' asFilename recursiveDirectoryContentsAsFilenames |
7697
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6045 |
'/XXXdoesNotExist' asFilename recursiveDirectoryContentsAsFilenames |
1cb1a31cd2c2
recursiveDirectoryContentsAsFilenames
Claus Gittinger <cg@exept.de>
parents:
7685
diff
changeset
|
6046 |
" |
6529 | 6047 |
! ! |
6048 |
||
6049 |
!Filename methodsFor:'reading-files'! |
|
6050 |
||
6051 |
binaryContentsOfEntireFile |
|
6052 |
"return the binary contents of the file (as a byteArray); |
|
7680 | 6053 |
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
|
6054 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6055 |
^ self |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6056 |
readingFileDo:[:s | |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6057 |
|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
|
6058 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6059 |
s binary. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6060 |
nBytes := self fileSize. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6061 |
(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
|
6062 |
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
|
6063 |
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
|
6064 |
n == nBytes ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6065 |
result := bytes |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6066 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6067 |
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
|
6068 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6069 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6070 |
result := s contentsOfEntireFile |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6071 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6072 |
result |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6073 |
] |
6529 | 6074 |
|
6075 |
" |
|
6076 |
'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
|
6077 |
'foobar' asFilename binaryContentsOfEntireFile |
6529 | 6078 |
" |
14446
479f02b4c705
changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
14306
diff
changeset
|
6079 |
|
479f02b4c705
changed: #binaryContentsOfEntireFile
Claus Gittinger <cg@exept.de>
parents:
14306
diff
changeset
|
6080 |
"Modified: / 27-10-2012 / 19:42:07 / cg" |
6529 | 6081 |
! |
6082 |
||
6083 |
contents |
|
20156 | 6084 |
"Return the contents of the file as a collection of lines. |
6085 |
Raise an error if the file is unreadable/non-existing. |
|
6529 | 6086 |
See also #contentsOfEntireFile, which returns a string for textFiles. |
6087 |
CAVEAT: bad naming - but req'd for VW compatibility." |
|
6088 |
||
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
6089 |
^ self readingFileDo:[:s | s contents]. |
6529 | 6090 |
|
6091 |
" |
|
6092 |
'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
|
6093 |
'foobar' asFilename contents |
6529 | 6094 |
" |
6095 |
||
6096 |
"Modified: / 2.7.1996 / 12:49:45 / stefan" |
|
6097 |
"Created: / 11.7.1996 / 14:09:11 / cg" |
|
6098 |
"Modified: / 15.10.1998 / 11:41:45 / cg" |
|
6099 |
! |
|
6100 |
||
10780 | 6101 |
contentsAsString |
6102 |
"to compensate for the bad naming, use this to make things explicit. |
|
6103 |
See also #contents, which returns the lines as stringCollection for textFiles." |
|
6104 |
||
11397
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
6105 |
^ self contentsOfEntireFile |
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
6106 |
|
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
6107 |
" |
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
6108 |
'Makefile' asFilename contentsAsString |
872cd41bbe05
oops - contentsAsString was endlessly recursive
Claus Gittinger <cg@exept.de>
parents:
11341
diff
changeset
|
6109 |
'foobar' asFilename contentsAsString |
10780 | 6110 |
" |
6111 |
||
6112 |
"Modified: / 02-07-1996 / 12:49:45 / stefan" |
|
6113 |
"Created: / 08-11-2007 / 13:29:59 / cg" |
|
6114 |
! |
|
6115 |
||
6529 | 6116 |
contentsOfEntireFile |
6117 |
"return the contents of the file as a string; |
|
7680 | 6118 |
Raises an error, if the file is unreadable/non-existing. |
6529 | 6119 |
See also #contents, which returns the lines as stringCollection for textFiles. |
6120 |
CAVEAT: bad naming - but req'd for VW compatibility." |
|
6121 |
||
7888
e76fa60251dc
Remove obsolete nil-checks after opening streams
Stefan Vogel <sv@exept.de>
parents:
7846
diff
changeset
|
6122 |
^ self readingFileDo:[:s | s contentsOfEntireFile]. |
6529 | 6123 |
|
6124 |
" |
|
6125 |
'Makefile' asFilename contentsOfEntireFile |
|
19043 | 6126 |
'smalltalk.rc' asFilename contentsOfEntireFile |
6529 | 6127 |
'foobar' asFilename contentsOfEntireFile |
6128 |
" |
|
6129 |
||
6130 |
"Modified: / 2.7.1996 / 12:49:45 / stefan" |
|
6131 |
"Modified: / 15.10.1998 / 11:42:05 / cg" |
|
6132 |
! |
|
6133 |
||
6134 |
readingFileDo:aBlock |
|
20156 | 6135 |
"Create a read stream on the receiver file, evaluate aBlock, passing that stream as arg, |
6136 |
and return the block's value. |
|
7088
cc3233554827
Handle openErrorSignal in preparition for change openErrorSignal
Stefan Vogel <sv@exept.de>
parents:
7075
diff
changeset
|
6137 |
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
|
6138 |
(old behavior, will vanish:)the block is evaluated with a nil argument. |
6529 | 6139 |
Ensures that the stream is closed." |
6140 |
||
6141 |
|stream result| |
|
6142 |
||
6143 |
stream := self readStream. |
|
6144 |
[ |
|
20156 | 6145 |
result := aBlock value:stream |
6529 | 6146 |
] ensure:[ |
20156 | 6147 |
stream notNil ifTrue:[stream close] |
6529 | 6148 |
]. |
6149 |
^ result |
|
6150 |
||
6151 |
" |
|
6152 |
read the first line from some file: |
|
6153 |
||
6154 |
|rslt| |
|
6155 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6156 |
rslt := |
20156 | 6157 |
'/etc/passwd' asFilename |
6158 |
readingFileDo:[:s | |
|
6159 |
s nextLine |
|
6160 |
]. |
|
6529 | 6161 |
Transcript showCR:rslt. |
6162 |
" |
|
6163 |
||
6164 |
" |
|
6165 |
find all used shells in /etc/passwd and count their usage: |
|
6166 |
||
6167 |
|rslt| |
|
6168 |
||
6169 |
rslt := |
|
20156 | 6170 |
'/etc/passwd' asFilename |
6171 |
readingFileDo: |
|
6172 |
[:s | |
|
6173 |
|shells| |
|
6174 |
||
6175 |
shells := Bag new. |
|
6176 |
s linesDo: |
|
6177 |
[:line | |
|
6178 |
|parts| |
|
6179 |
||
6180 |
parts := line asCollectionOfSubstringsSeparatedBy:$:. |
|
6181 |
shells add:(parts seventh). |
|
6182 |
]. |
|
6183 |
shells contents |
|
6184 |
]. |
|
6529 | 6185 |
Transcript showCR:rslt. |
6186 |
" |
|
6771 | 6187 |
! |
6188 |
||
6189 |
readingLinesDo:aBlock |
|
20158 | 6190 |
"Create a read stream on the receiver file and |
6771 | 6191 |
evaluate aBlock for each line read from the stream. |
6192 |
If the file cannot be opened, an error is raised. |
|
6193 |
Ensures that the stream is closed." |
|
6194 |
||
6195 |
self readingFileDo:[:stream | |
|
20158 | 6196 |
stream linesDo:aBlock |
6771 | 6197 |
]. |
6198 |
||
6199 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6200 |
'/etc/passwd' asFilename |
20158 | 6201 |
readingLinesDo:[:eachLine | |
6202 |
Transcript showCR:eachLine. |
|
6203 |
]. |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6204 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6205 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6206 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6207 |
'/etc/xxxxx' asFilename |
20158 | 6208 |
readingLinesDo:[:eachLine | |
6209 |
Transcript showCR:eachLine. |
|
6210 |
]. |
|
6771 | 6211 |
" |
6529 | 6212 |
! ! |
6213 |
||
2922 | 6214 |
!Filename methodsFor:'special accessing'! |
6215 |
||
6216 |
osName |
|
6217 |
"special - return the OS's name for the receiver." |
|
6218 |
||
6219 |
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
|
6220 |
^ self osNameForDirectory |
2922 | 6221 |
]. |
6222 |
^ self osNameForFile |
|
6223 |
! |
|
6224 |
||
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
6225 |
osNameForAccess |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
6226 |
"internal - return the OS's name for the receiver to |
3665 | 6227 |
access its fileInfo. |
6228 |
This may be redefined for systems, where a special suffix must be |
|
6229 |
added in order to access directories (or others) as a file. |
|
6230 |
(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
|
6231 |
|
7064 | 6232 |
^ self osNameForFile |
3665 | 6233 |
|
6234 |
"Modified: / 21.7.1998 / 10:40:40 / cg" |
|
2978
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
6235 |
! |
e466e478fa43
Handle errors in #filenameCompletion:
Stefan Vogel <sv@exept.de>
parents:
2977
diff
changeset
|
6236 |
|
2922 | 6237 |
osNameForDirectory |
3753 | 6238 |
"internal - return the OS's name for the receiver to |
2922 | 6239 |
access it as a directory." |
6240 |
||
14218 | 6241 |
^ self osNameForFile |
3753 | 6242 |
|
6243 |
"Modified: / 12.8.1998 / 14:44:32 / cg" |
|
2922 | 6244 |
! |
6245 |
||
3720
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
6246 |
osNameForDirectoryContents |
3753 | 6247 |
"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
|
6248 |
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
|
6249 |
|
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
6250 |
^ self osNameForDirectory |
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
6251 |
|
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
6252 |
"Created: / 3.8.1998 / 21:36:06 / cg" |
3753 | 6253 |
"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
|
6254 |
! |
d2529646d235
oops - needed a kludge to read the top directory under win32
Claus Gittinger <cg@exept.de>
parents:
3719
diff
changeset
|
6255 |
|
2922 | 6256 |
osNameForFile |
6257 |
"internal - return the OS's name for the receiver to |
|
6258 |
access it as a file." |
|
6259 |
||
19670 | 6260 |
(nameString startsWith:$~) ifFalse:[ |
6261 |
^ nameString. |
|
14220
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
6262 |
]. |
2a3457b016be
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
14218
diff
changeset
|
6263 |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6264 |
^ self species nameWithSpecialExpansions:nameString. |
2922 | 6265 |
! ! |
6266 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6267 |
!Filename methodsFor:'suffixes'! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6268 |
|
11748 | 6269 |
addSuffix:aSuffix |
19440 | 6270 |
"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
|
6271 |
The new suffix is simply appended to the name, |
14306
f41ca29d9b54
comment/format in: #addSuffix:
Stefan Vogel <sv@exept.de>
parents:
14232
diff
changeset
|
6272 |
regardless whether there is already an existing suffix. |
f41ca29d9b54
comment/format in: #addSuffix:
Stefan Vogel <sv@exept.de>
parents:
14232
diff
changeset
|
6273 |
See also #withSuffix:" |
11748 | 6274 |
|
6275 |
|prefixName| |
|
6276 |
||
6277 |
prefixName := self name. |
|
6278 |
aSuffix isEmptyOrNil ifTrue:[ |
|
19599 | 6279 |
^ self species named:prefixName |
11748 | 6280 |
]. |
6281 |
||
15811 | 6282 |
^ self species named: |
19599 | 6283 |
(prefixName |
6284 |
, self species suffixSeparator asString |
|
6285 |
, aSuffix asString) |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6286 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6287 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6288 |
'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
|
6289 |
'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
|
6290 |
'.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
|
6291 |
'.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
|
6292 |
'.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
|
6293 |
'.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
|
6294 |
'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
|
6295 |
'.' asFilename addSuffix:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6296 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6297 |
'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
|
6298 |
'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
|
6299 |
'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
|
6300 |
'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
|
6301 |
'.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
|
6302 |
'.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
|
6303 |
'.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
|
6304 |
'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
|
6305 |
'.' asFilename addSuffix:'o' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6306 |
'/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
|
6307 |
'/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
|
6308 |
'/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
|
6309 |
'/foo/bar.c/baz' asFilename addSuffix:'st' |
11748 | 6310 |
" |
6311 |
! |
|
6312 |
||
2906 | 6313 |
hasSuffix:aSuffixString |
6314 |
"return true if my suffix is the same as aString. |
|
6315 |
This cares for systems, where case is ignored in filenames" |
|
6316 |
||
6317 |
|mySuffix| |
|
6318 |
||
6319 |
mySuffix := self suffix. |
|
15811 | 6320 |
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
|
6321 |
^ mySuffix = aSuffixString |
2906 | 6322 |
]. |
6323 |
^ mySuffix asLowercase = aSuffixString asLowercase |
|
6324 |
||
6325 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6326 |
'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
|
6327 |
'abc.ST' asFilename hasSuffix:'st' |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
6328 |
'.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
|
6329 |
'.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
|
6330 |
'.foorc.sav' asFilename hasSuffix:'sav' |
2906 | 6331 |
" |
6332 |
||
6333 |
"Modified: 7.9.1997 / 02:55:25 / cg" |
|
6334 |
! |
|
6335 |
||
10155 | 6336 |
nameWithoutSuffix |
19440 | 6337 |
"return the receiver's name without the suffix. |
10155 | 6338 |
If the name has no suffix, the original name is returned." |
6339 |
||
6340 |
|nm idx idxFromEnd| |
|
6341 |
||
6342 |
nm := self baseName. |
|
15811 | 6343 |
idx := nm lastIndexOf:(self species suffixSeparator). |
10155 | 6344 |
(idx == 0) ifTrue:[^ nameString]. |
6345 |
"/ be careful: if the name consists only of suffix (i.e '.foo'), |
|
6346 |
"/ the suffix is considered empty. |
|
6347 |
(idx == 1) ifTrue:[^ nameString]. |
|
6348 |
||
6349 |
idxFromEnd := nm size - idx. |
|
6350 |
idx := nameString size - idxFromEnd. |
|
6351 |
||
6352 |
^ nameString copyTo:(idx - 1) |
|
6353 |
||
6354 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6355 |
'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
|
6356 |
'abc' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6357 |
'/abc' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6358 |
'/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
|
6359 |
'./abc' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6360 |
'./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
|
6361 |
'./.abc' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6362 |
'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
|
6363 |
'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
|
6364 |
'.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
|
6365 |
'.b.' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6366 |
'.b' asFilename nameWithoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6367 |
'/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
|
6368 |
'/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
|
6369 |
'/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
|
6370 |
'/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
|
6371 |
'/foo/bar/baz/foo.c/bar.c' asFilename nameWithoutSuffix |
10155 | 6372 |
" |
6373 |
||
6374 |
"Modified: / 07-09-1995 / 11:15:42 / claus" |
|
6375 |
"Created: / 07-11-2006 / 13:55:18 / cg" |
|
6376 |
! |
|
6377 |
||
9453 | 6378 |
prefix |
6379 |
"return my prefix. |
|
6380 |
The suffix is the namepart after the final period character, |
|
6381 |
or the empty string, if the name does not contain a period." |
|
6382 |
||
6383 |
^ self prefixAndSuffix at:1 |
|
6384 |
||
6385 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6386 |
'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
|
6387 |
'abc' asFilename prefix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6388 |
'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
|
6389 |
'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
|
6390 |
'a.' asFilename prefix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6391 |
'.a' asFilename prefix |
9453 | 6392 |
" |
6393 |
||
6394 |
"Modified: / 07-09-1995 / 11:09:03 / claus" |
|
6395 |
"Created: / 13-07-2006 / 10:27:19 / fm" |
|
6396 |
! |
|
6397 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6398 |
prefixAndSuffix |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6399 |
"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
|
6400 |
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
|
6401 |
the prefix everything before, except for the period. |
1517 | 6402 |
The directory name part is stripped off (i.e. the returned prefix |
16578 | 6403 |
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
|
6404 |
(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
|
6405 |
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
|
6406 |
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
|
6407 |
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
|
6408 |
'.foorc'. |
1517 | 6409 |
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
|
6410 |
Notice: |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6411 |
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
|
6412 |
the period character as suffixCharacter." |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6413 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6414 |
|nm idx| |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6415 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6416 |
nm := self baseName. |
15811 | 6417 |
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
|
6418 |
"/ 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
|
6419 |
"/ the suffix is considered empty. |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
6420 |
((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
|
6421 |
^ Array with:nm with:'' |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6422 |
]. |
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6423 |
^ Array |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6424 |
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
|
6425 |
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
|
6426 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6427 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6428 |
'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
|
6429 |
'abc' asFilename prefixAndSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6430 |
'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
|
6431 |
'/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
|
6432 |
'a.' asFilename prefixAndSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6433 |
'.a' asFilename prefixAndSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6434 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6435 |
|parts| |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6436 |
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
|
6437 |
((parts at:1) , '.o') asFilename |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6438 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6439 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6440 |
"Modified: 7.9.1995 / 11:15:42 / claus" |
1517 | 6441 |
"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
|
6442 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6443 |
|
2906 | 6444 |
suffix |
6445 |
"return my suffix. |
|
6446 |
The suffix is the namepart after the final period character, |
|
6447 |
or the empty string, if the name does not contain a period." |
|
6448 |
||
6449 |
^ self prefixAndSuffix at:2 |
|
6450 |
||
6451 |
" |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6452 |
'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
|
6453 |
'abc' asFilename suffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6454 |
'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
|
6455 |
'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
|
6456 |
'a.' asFilename suffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6457 |
'.a' asFilename suffix |
2906 | 6458 |
" |
6459 |
||
6460 |
"Modified: 7.9.1995 / 11:09:03 / claus" |
|
6461 |
! |
|
6462 |
||
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6463 |
withSuffix:aSuffix |
19440 | 6464 |
"return a new filename for the receiver's name with a different suffix. |
6256 | 6465 |
If the name already has a suffix, the new suffix replaces it; |
1993 | 6466 |
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
|
6467 |
|
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
6468 |
|prefixName| |
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
6469 |
|
10155 | 6470 |
prefixName := self nameWithoutSuffix. |
7115
dea26def3167
prefix/suffix definition changed for files beginning with
Claus Gittinger <cg@exept.de>
parents:
7088
diff
changeset
|
6471 |
aSuffix isEmptyOrNil ifTrue:[ |
19599 | 6472 |
^ self species named:prefixName |
6262 | 6473 |
]. |
6474 |
||
15811 | 6475 |
^ self species named: |
19599 | 6476 |
(prefixName |
6477 |
, self class suffixSeparator asString |
|
6478 |
, aSuffix asString) |
|
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6479 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6480 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6481 |
'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
|
6482 |
'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
|
6483 |
'.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
|
6484 |
'.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
|
6485 |
'.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
|
6486 |
'.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
|
6487 |
'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
|
6488 |
'.' asFilename withSuffix:nil |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6489 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6490 |
'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
|
6491 |
'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
|
6492 |
'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
|
6493 |
'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
|
6494 |
'.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
|
6495 |
'.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
|
6496 |
'.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
|
6497 |
'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
|
6498 |
'.' asFilename withSuffix:'o' |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6499 |
'/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
|
6500 |
'/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
|
6501 |
'/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
|
6502 |
'/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
|
6503 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6504 |
|
10155 | 6505 |
"Modified: / 07-09-1995 / 11:15:42 / claus" |
6506 |
"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
|
6507 |
! |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6508 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6509 |
withoutSuffix |
19440 | 6510 |
"return a new filename for the receiver's name without the suffix. |
10155 | 6511 |
If the name has no suffix, a filename representing the same file as the receiver is returned." |
6512 |
||
6513 |
|n| |
|
6514 |
||
6515 |
n := self nameWithoutSuffix. |
|
6516 |
n = nameString ifTrue:[^ self]. |
|
15811 | 6517 |
^ self species named:n |
1049
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6518 |
|
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6519 |
" |
18667
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 withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6521 |
'abc' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6522 |
'/abc' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6523 |
'/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
|
6524 |
'./abc' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6525 |
'./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
|
6526 |
'./.abc' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6527 |
'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
|
6528 |
'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
|
6529 |
'.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
|
6530 |
'.b.' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6531 |
'.b' asFilename withoutSuffix |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6532 |
'/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
|
6533 |
'/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
|
6534 |
'/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
|
6535 |
'/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
|
6536 |
'/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
|
6537 |
" |
6f7b6c18a748
new goodies (bells & whistles upon claus's request)
Claus Gittinger <cg@exept.de>
parents:
932
diff
changeset
|
6538 |
|
10155 | 6539 |
"Modified: / 07-09-1995 / 11:15:42 / claus" |
6540 |
"Modified: / 07-11-2006 / 13:57:45 / cg" |
|
174 | 6541 |
! ! |
6542 |
||
5597 | 6543 |
!Filename methodsFor:'testing'! |
6544 |
||
6545 |
isFilename |
|
6546 |
"return true, if the receiver is some kind of filename; |
|
6547 |
false is returned here - the method is redefined from Object." |
|
6548 |
||
6549 |
^true |
|
6550 |
||
6551 |
||
6552 |
! ! |
|
6553 |
||
10271 | 6554 |
!Filename methodsFor:'writing-files'! |
6555 |
||
14512 | 6556 |
appendingFileDo:aBlock |
6557 |
"create a append-stream on the receiver file, evaluate aBlock, passing that stream as arg, |
|
19088 | 6558 |
and return the block's value. |
14512 | 6559 |
If the file cannot be opened, an exception is raised. |
6560 |
Ensures that the stream is closed." |
|
6561 |
||
6562 |
|stream result| |
|
6563 |
||
6564 |
stream := self appendStream. |
|
6565 |
[ |
|
19599 | 6566 |
result := aBlock value:stream |
14512 | 6567 |
] ensure:[ |
19599 | 6568 |
stream close |
14512 | 6569 |
]. |
6570 |
^ result |
|
6571 |
||
6572 |
" |
|
14513 | 6573 |
'ttt' asFilename appendingFileDo:[:s | |
19599 | 6574 |
s nextPutLine:'hello'. |
6575 |
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
|
6576 |
] |
14512 | 6577 |
" |
6578 |
||
6579 |
"Created: / 09-11-2012 / 10:07:41 / sr" |
|
6580 |
! |
|
6581 |
||
10779 | 6582 |
contents:aStringOrCollectionOfLines |
10271 | 6583 |
"create (or overwrite) a file given its contents as a collection of lines. |
6584 |
Raises an error, if the file is unwritable." |
|
6585 |
||
18667
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6586 |
^ self |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6587 |
writingFileDo:[:s | |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6588 |
aStringOrCollectionOfLines isNonByteCollection ifTrue:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6589 |
"a StringCollection or a collection of lines" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6590 |
aStringOrCollectionOfLines do:[:each | s nextPutLine:(each ? '')] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6591 |
] ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6592 |
"something string-like" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6593 |
aStringOrCollectionOfLines isString ifFalse:[ |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6594 |
s binary |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6595 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6596 |
s nextPutAll:aStringOrCollectionOfLines |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6597 |
] |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6598 |
]. |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6599 |
|
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6600 |
" |
ed22f49c33f1
temporarily disabled recent changes - expecco's keyfile check failed with them.
Claus Gittinger <cg@exept.de>
parents:
18659
diff
changeset
|
6601 |
'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
|
6602 |
'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
|
6603 |
'foo3' asFilename contents:#[1 2 3 4 5] |
10271 | 6604 |
" |
6605 |
||
6606 |
"Created: / 11-12-2006 / 14:11:21 / cg" |
|
10779 | 6607 |
"Modified: / 08-11-2007 / 13:28:41 / cg" |
10271 | 6608 |
! |
6609 |
||
6610 |
writingFileDo:aBlock |
|
6611 |
"create a write-stream on the receiver file, evaluate aBlock, passing that stream as arg, |
|
19088 | 6612 |
and return the block's value. |
10271 | 6613 |
If the file cannot be opened, an exception is raised. |
6614 |
Ensures that the stream is closed." |
|
6615 |
||
6616 |
|stream result| |
|
6617 |
||
6618 |
stream := self writeStream. |
|
6619 |
[ |
|
19599 | 6620 |
result := aBlock value:stream |
10271 | 6621 |
] ensure:[ |
19599 | 6622 |
stream close |
10271 | 6623 |
]. |
6624 |
^ result |
|
6625 |
||
6626 |
" |
|
6627 |
'ttt' asFilename writingFileDo:[:s | |
|
19599 | 6628 |
s nextPutLine:'hello'. |
6629 |
s nextPutLine:'world'. |
|
10271 | 6630 |
] |
6631 |
" |
|
6632 |
||
6633 |
"Created: / 11-12-2006 / 14:09:39 / cg" |
|
6634 |
! ! |
|
6635 |
||
1859
7f6040320daf
changes for new return from OS>>infoOf:
Claus Gittinger <cg@exept.de>
parents:
1614
diff
changeset
|
6636 |
!Filename class methodsFor:'documentation'! |
630 | 6637 |
|
6638 |
version |
|
18490 | 6639 |
^ '$Header$' |
12318 | 6640 |
! |
6641 |
||
6642 |
version_CVS |
|
18490 | 6643 |
^ '$Header$' |
630 | 6644 |
! ! |
6771 | 6645 |
|
14628 | 6646 |
|
2906 | 6647 |
Filename initialize! |