author | Stefan Vogel <sv@exept.de> |
Thu, 10 Jan 2019 19:15:28 +0100 | |
changeset 23600 | f7a4056adc93 |
parent 23042 | def1ea6ee127 |
child 23624 | 5c6834205e82 |
permissions | -rw-r--r-- |
23042 | 1 |
"{ Encoding: utf8 }" |
2 |
||
2943
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
3 |
" |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
4 |
COPYRIGHT (c) 1997 by eXept Software AG |
3125
543358373041
care for filenames with blanks when invoking 'file' command
Claus Gittinger <cg@exept.de>
parents:
2943
diff
changeset
|
5 |
All Rights Reserved |
2943
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
6 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
7 |
This software is furnished under a license and may be used |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
8 |
only in accordance with the terms of that license and with the |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
9 |
inclusion of the above copyright notice. This software may not |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
10 |
be provided or otherwise made available to, or used by, any |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
11 |
other person. No title to or ownership of the software is |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
12 |
hereby transferred. |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
13 |
" |
7939
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
14 |
"{ Package: 'stx:libbasic' }" |
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
15 |
|
19818 | 16 |
"{ NameSpace: Smalltalk }" |
17 |
||
2907 | 18 |
Filename subclass:#UnixFilename |
19 |
instanceVariableNames:'' |
|
20 |
classVariableNames:'' |
|
21 |
poolDictionaries:'' |
|
22 |
category:'OS-Unix' |
|
23 |
! |
|
24 |
||
2911 | 25 |
!UnixFilename class methodsFor:'documentation'! |
26 |
||
2931 | 27 |
copyright |
28 |
" |
|
29 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
3125
543358373041
care for filenames with blanks when invoking 'file' command
Claus Gittinger <cg@exept.de>
parents:
2943
diff
changeset
|
30 |
All Rights Reserved |
2931 | 31 |
|
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 |
||
2911 | 41 |
documentation |
42 |
" |
|
43 |
Filenames in Unix. |
|
44 |
" |
|
45 |
||
11318
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
46 |
! |
7939
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
47 |
|
11318
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
48 |
examples |
7939
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
49 |
" |
23042 | 50 |
(self named:'/tmp/äöü') writeStream close |
7939
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
51 |
" |
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
52 |
! ! |
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
53 |
|
17047 | 54 |
!UnixFilename class methodsFor:'defaults'! |
55 |
||
56 |
defaultTempDirectoryName |
|
23042 | 57 |
"return the default temp directory as a filename. |
58 |
By default, this is '/tmp', but can be overriden by one of |
|
59 |
the shell variables: ('STX_TMPDIR' 'ST_TMPDIR' 'TMPDIR' 'TEMPDIR' 'TEMP' 'TMP')" |
|
17047 | 60 |
|
61 |
|tempDirString tempDir| |
|
62 |
||
63 |
#('STX_TMPDIR' 'ST_TMPDIR' 'TMPDIR' 'TEMPDIR' 'TEMP' 'TMP') do:[:envVar | |
|
64 |
tempDirString := OperatingSystem getEnvironment:envVar. |
|
65 |
tempDirString notNil ifTrue:[ |
|
66 |
tempDir := self named:tempDirString. |
|
67 |
(tempDir exists and:[ tempDir isWritable ]) ifTrue:[ |
|
17073 | 68 |
('Filename [info]: using tmp folder "%1" as specified by environment: "%2"' |
17075 | 69 |
bindWith:tempDir pathName with:envVar) infoPrintCR. |
17047 | 70 |
^ tempDir asFilename. |
71 |
]. |
|
72 |
]. |
|
73 |
]. |
|
74 |
||
75 |
tempDir := '/tmp' asFilename. |
|
76 |
('Filename [info]: using default unix tmp folder: ',tempDir pathName) infoPrintCR. |
|
77 |
^ tempDir |
|
78 |
||
79 |
" |
|
80 |
Filename defaultTempDirectoryName |
|
81 |
Filename defaultTempDirectoryName exists |
|
82 |
Filename defaultTempDirectoryName isWritable |
|
83 |
" |
|
23042 | 84 |
|
85 |
"Modified (comment): / 31-05-2018 / 09:56:20 / Claus Gittinger" |
|
17047 | 86 |
! ! |
87 |
||
23600 | 88 |
!UnixFilename class methodsFor:'misc'! |
89 |
||
90 |
nameWithSpecialExpansions:aString |
|
91 |
"return the nameString, expanding any OS specific macros. |
|
92 |
Here, a ~/ or ~user/ prefix is expanded to the users home dir (as in csh)" |
|
93 |
||
94 |
|expandedString| |
|
95 |
||
96 |
expandedString := aString. |
|
97 |
(expandedString includes:$$) ifTrue:[ |
|
98 |
expandedString := OperatingSystem expandEnvironmentStrings:expandedString. |
|
99 |
]. |
|
100 |
||
101 |
(expandedString startsWith:$~) ifTrue:[ |
|
102 |
^ super nameWithSpecialExpansions:expandedString. |
|
103 |
]. |
|
104 |
^ expandedString |
|
105 |
||
106 |
" |
|
107 |
self nameWithSpecialExpansions:'/usr/lib' |
|
108 |
self nameWithSpecialExpansions:'$JAVA_HOME/bin' |
|
109 |
self nameWithSpecialExpansions:'$(JAVA_HOME)/bin' |
|
110 |
self nameWithSpecialExpansions:'~/work' |
|
111 |
self nameWithSpecialExpansions:'~stefan/test' |
|
112 |
" |
|
113 |
||
114 |
"Created: / 10-01-2019 / 16:04:14 / Stefan Vogel" |
|
115 |
! ! |
|
116 |
||
2907 | 117 |
!UnixFilename class methodsFor:'queries'! |
118 |
||
119 |
isBadCharacter:aCharacter |
|
120 |
"return true, if aCharacter is unallowed in a filename." |
|
121 |
||
122 |
aCharacter == $/ ifTrue:[^ true]. |
|
123 |
^ super isBadCharacter:aCharacter |
|
124 |
||
125 |
"Created: 8.9.1997 / 00:13:14 / cg" |
|
126 |
! |
|
127 |
||
2908 | 128 |
isCaseSensitive |
19818 | 129 |
"return true, if filenames are case sensitive. |
130 |
This is not really correct, as the sensitivity may depend on |
|
131 |
the paricular mounted file system (NFS, for example)" |
|
2908 | 132 |
|
14818 | 133 |
^ OperatingSystem caseSensitiveFilenames |
2908 | 134 |
! |
135 |
||
3171 | 136 |
nullFilename |
137 |
"Return /dev/null" |
|
138 |
||
139 |
^ '/dev/null' |
|
140 |
||
141 |
" |
|
8752 | 142 |
Filename nullFilename |
3171 | 143 |
" |
144 |
||
145 |
"Modified: / 14.1.1998 / 14:20:55 / stefan" |
|
146 |
! |
|
147 |
||
2908 | 148 |
parentDirectoryName |
149 |
"return the name used for the parent directory. |
|
150 |
This is '..' for unix and dos-like systems. |
|
151 |
(there may be more in the future." |
|
152 |
||
153 |
^ '..' |
|
154 |
! |
|
155 |
||
2907 | 156 |
separator |
157 |
"return the file/directory separator." |
|
158 |
||
159 |
^ $/ |
|
160 |
||
161 |
" |
|
162 |
Filename concreteClass separator |
|
163 |
" |
|
164 |
||
165 |
"Created: 8.9.1997 / 00:18:14 / cg" |
|
8245 | 166 |
! |
167 |
||
168 |
separatorString |
|
169 |
"return the file/directory separator as a string." |
|
170 |
||
171 |
^ '/' |
|
172 |
||
173 |
" |
|
8752 | 174 |
Filename separatorString |
8245 | 175 |
" |
2907 | 176 |
! ! |
177 |
||
178 |
!UnixFilename methodsFor:'file queries'! |
|
179 |
||
180 |
fileType |
|
21276 | 181 |
"this returns a string describing the type of contents of the file. |
182 |
This is done using the unix 'file' command, |
|
2907 | 183 |
(which usually is configurable by /etc/magic). |
3664 | 184 |
Warning: |
185 |
Since the returned string differs among systems (and language settings), |
|
186 |
it is only useful for user-information; |
|
21276 | 187 |
NOT as a tag to be used by a program. |
188 |
For this, use mimeType or mimeTypeOfContents." |
|
2907 | 189 |
|
16581 | 190 |
|typeString| |
2907 | 191 |
|
16754 | 192 |
"/ since executing 'file' takes some time, the most common |
2907 | 193 |
"/ ones are checked first, using the general fileType implementation. |
16754 | 194 |
"/ (also, the file-command is only available on Unix systems, |
195 |
"/ so this provides a reasonable fallback). |
|
2907 | 196 |
|
197 |
typeString := super fileType. |
|
198 |
typeString ~= 'file' ifTrue:[^ typeString]. |
|
199 |
||
22276 | 200 |
typeString := PipeStream outputFromCommand:('/usr/bin/file "' , self pathName , '"'). |
16581 | 201 |
typeString notNil ifTrue:[ |
3664 | 202 |
typeString := typeString copyFrom:(typeString indexOf:$:) + 1. |
203 |
typeString := typeString withoutSeparators |
|
2907 | 204 |
]. |
205 |
^ typeString |
|
206 |
||
207 |
" |
|
208 |
'Makefile' asFilename fileType |
|
209 |
'.' asFilename fileType |
|
210 |
'/dev/null' asFilename fileType |
|
211 |
'smalltalk.rc' asFilename fileType |
|
212 |
'bitmaps/SBrowser.xbm' asFilename fileType |
|
3664 | 213 |
'../../libtool/bitmaps/SBrowser.xbm' asFilename fileType |
16581 | 214 |
'./stx' asFilename fileType |
2907 | 215 |
" |
216 |
||
22276 | 217 |
"Modified: / 21-07-1998 / 11:26:32 / cg" |
218 |
"Modified: / 21-09-2017 / 11:09:52 / stefan" |
|
2907 | 219 |
! ! |
220 |
||
2931 | 221 |
!UnixFilename methodsFor:'queries'! |
222 |
||
223 |
isExplicitRelative |
|
224 |
"return true, if this name is an explicit relative name |
|
225 |
(i.e. starts with './' or '../', to avoid path-prepending)" |
|
226 |
||
227 |
(nameString startsWith:'./') ifTrue:[ |
|
228 |
^ true |
|
229 |
]. |
|
230 |
(nameString startsWith:'../') ifTrue:[ |
|
231 |
^ true |
|
232 |
]. |
|
233 |
^ false |
|
234 |
! |
|
235 |
||
236 |
isHidden |
|
237 |
"return true, if the receiver represents a hidden file. |
|
238 |
On UNIX, a name starting with a period is considered hidden." |
|
239 |
||
12390 | 240 |
|baseName| |
241 |
||
242 |
baseName := self baseName. |
|
243 |
^ ((baseName startsWith:'.') and:[baseName ~= '..']) |
|
2943
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
244 |
! |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
245 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
246 |
isImplicit |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
247 |
"return true, if the receiver represents builtin names such as '.' or '..'. |
3664 | 248 |
On UNIX, the current and parent dir names are considered implicit." |
2943
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
249 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
250 |
|name| |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
251 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
252 |
name := self baseName. |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
253 |
^ name = '.' or:[name = '..']. |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
254 |
|
3664 | 255 |
"Modified: / 18.9.1997 / 18:03:28 / stefan" |
256 |
"Modified: / 21.7.1998 / 11:10:42 / cg" |
|
2931 | 257 |
! ! |
258 |
||
11318
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
259 |
!UnixFilename methodsFor:'special accessing'! |
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
260 |
|
14221
d2ef1c042257
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
12390
diff
changeset
|
261 |
osName |
d2ef1c042257
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
12390
diff
changeset
|
262 |
"redefined from superclass, because we do not distinguish file and directory names" |
11318
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
263 |
|
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
264 |
^ self osNameForFile |
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
265 |
! ! |
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
266 |
|
2911 | 267 |
!UnixFilename class methodsFor:'documentation'! |
2907 | 268 |
|
2911 | 269 |
version |
19818 | 270 |
^ '$Header$' |
12390 | 271 |
! |
272 |
||
273 |
version_CVS |
|
19818 | 274 |
^ '$Header$' |
2907 | 275 |
! ! |
14818 | 276 |