author | Jan Vrany <jan.vrany@labware.com> |
Wed, 02 Aug 2023 13:04:52 +0100 | |
branch | jv |
changeset 25462 | 548cb62b20c7 |
parent 23107 | 40173e082cbc |
permissions | -rw-r--r-- |
2943
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
1 |
" |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
2 |
COPYRIGHT (c) 1997 by eXept Software AG |
23107 | 3 |
COPYRIGHT (c) 2016 Jan Vrany |
3125
543358373041
care for filenames with blanks when invoking 'file' command
Claus Gittinger <cg@exept.de>
parents:
2943
diff
changeset
|
4 |
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
|
5 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
6 |
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
|
7 |
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
|
8 |
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
|
9 |
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
|
10 |
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
|
11 |
hereby transferred. |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
12 |
" |
7939
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
13 |
"{ Package: 'stx:libbasic' }" |
3a8b75e8f804
catch twoByte string names (assume UTF8)
Claus Gittinger <cg@exept.de>
parents:
3664
diff
changeset
|
14 |
|
19818 | 15 |
"{ NameSpace: Smalltalk }" |
16 |
||
2907 | 17 |
Filename subclass:#UnixFilename |
18 |
instanceVariableNames:'' |
|
19 |
classVariableNames:'' |
|
20 |
poolDictionaries:'' |
|
21 |
category:'OS-Unix' |
|
22 |
! |
|
23 |
||
2911 | 24 |
!UnixFilename class methodsFor:'documentation'! |
25 |
||
2931 | 26 |
copyright |
27 |
" |
|
28 |
COPYRIGHT (c) 1997 by eXept Software AG |
|
23107 | 29 |
COPYRIGHT (c) 2016 Jan Vrany |
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 |
" |
21292 | 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 |
|
57 |
"return the default temp directory as a filename." |
|
58 |
||
59 |
|tempDirString tempDir| |
|
60 |
||
61 |
#('STX_TMPDIR' 'ST_TMPDIR' 'TMPDIR' 'TEMPDIR' 'TEMP' 'TMP') do:[:envVar | |
|
62 |
tempDirString := OperatingSystem getEnvironment:envVar. |
|
63 |
tempDirString notNil ifTrue:[ |
|
64 |
tempDir := self named:tempDirString. |
|
65 |
(tempDir exists and:[ tempDir isWritable ]) ifTrue:[ |
|
20731
bee58777b1f7
Separate temporary directories for different users
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19861
diff
changeset
|
66 |
Logger info: 'using tmp folder "%1" as specified by environment: "%2"' with:tempDir pathName with:envVar. |
17047 | 67 |
^ tempDir asFilename. |
68 |
]. |
|
69 |
]. |
|
70 |
]. |
|
71 |
||
72 |
tempDir := '/tmp' asFilename. |
|
73 |
('Filename [info]: using default unix tmp folder: ',tempDir pathName) infoPrintCR. |
|
74 |
^ tempDir |
|
75 |
||
76 |
" |
|
77 |
Filename defaultTempDirectoryName |
|
78 |
Filename defaultTempDirectoryName exists |
|
79 |
Filename defaultTempDirectoryName isWritable |
|
80 |
" |
|
20731
bee58777b1f7
Separate temporary directories for different users
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19861
diff
changeset
|
81 |
|
bee58777b1f7
Separate temporary directories for different users
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
19861
diff
changeset
|
82 |
"Modified: / 27-10-2016 / 23:09:08 / jv" |
17047 | 83 |
! ! |
84 |
||
2907 | 85 |
!UnixFilename class methodsFor:'queries'! |
86 |
||
87 |
isBadCharacter:aCharacter |
|
88 |
"return true, if aCharacter is unallowed in a filename." |
|
89 |
||
90 |
aCharacter == $/ ifTrue:[^ true]. |
|
91 |
^ super isBadCharacter:aCharacter |
|
92 |
||
93 |
"Created: 8.9.1997 / 00:13:14 / cg" |
|
94 |
! |
|
95 |
||
2908 | 96 |
isCaseSensitive |
19818 | 97 |
"return true, if filenames are case sensitive. |
98 |
This is not really correct, as the sensitivity may depend on |
|
99 |
the paricular mounted file system (NFS, for example)" |
|
2908 | 100 |
|
14818 | 101 |
^ OperatingSystem caseSensitiveFilenames |
2908 | 102 |
! |
103 |
||
3171 | 104 |
nullFilename |
105 |
"Return /dev/null" |
|
106 |
||
107 |
^ '/dev/null' |
|
108 |
||
109 |
" |
|
8752 | 110 |
Filename nullFilename |
3171 | 111 |
" |
112 |
||
113 |
"Modified: / 14.1.1998 / 14:20:55 / stefan" |
|
114 |
! |
|
115 |
||
2908 | 116 |
parentDirectoryName |
117 |
"return the name used for the parent directory. |
|
118 |
This is '..' for unix and dos-like systems. |
|
119 |
(there may be more in the future." |
|
120 |
||
121 |
^ '..' |
|
122 |
! |
|
123 |
||
2907 | 124 |
separator |
125 |
"return the file/directory separator." |
|
126 |
||
127 |
^ $/ |
|
128 |
||
129 |
" |
|
130 |
Filename concreteClass separator |
|
131 |
" |
|
132 |
||
133 |
"Created: 8.9.1997 / 00:18:14 / cg" |
|
8245 | 134 |
! |
135 |
||
136 |
separatorString |
|
137 |
"return the file/directory separator as a string." |
|
138 |
||
139 |
^ '/' |
|
140 |
||
141 |
" |
|
8752 | 142 |
Filename separatorString |
8245 | 143 |
" |
2907 | 144 |
! ! |
145 |
||
146 |
!UnixFilename methodsFor:'file queries'! |
|
147 |
||
148 |
fileType |
|
21276 | 149 |
"this returns a string describing the type of contents of the file. |
150 |
This is done using the unix 'file' command, |
|
2907 | 151 |
(which usually is configurable by /etc/magic). |
3664 | 152 |
Warning: |
153 |
Since the returned string differs among systems (and language settings), |
|
154 |
it is only useful for user-information; |
|
21276 | 155 |
NOT as a tag to be used by a program. |
156 |
For this, use mimeType or mimeTypeOfContents." |
|
2907 | 157 |
|
16581 | 158 |
|typeString| |
2907 | 159 |
|
16754 | 160 |
"/ since executing 'file' takes some time, the most common |
2907 | 161 |
"/ ones are checked first, using the general fileType implementation. |
16754 | 162 |
"/ (also, the file-command is only available on Unix systems, |
163 |
"/ so this provides a reasonable fallback). |
|
2907 | 164 |
|
165 |
typeString := super fileType. |
|
166 |
typeString ~= 'file' ifTrue:[^ typeString]. |
|
167 |
||
16581 | 168 |
typeString := PipeStream outputFromCommand:('file "' , self pathName , '"'). |
169 |
typeString notNil ifTrue:[ |
|
3664 | 170 |
typeString := typeString copyFrom:(typeString indexOf:$:) + 1. |
171 |
typeString := typeString withoutSeparators |
|
2907 | 172 |
]. |
173 |
^ typeString |
|
174 |
||
175 |
" |
|
176 |
'Makefile' asFilename fileType |
|
177 |
'.' asFilename fileType |
|
178 |
'/dev/null' asFilename fileType |
|
179 |
'smalltalk.rc' asFilename fileType |
|
180 |
'bitmaps/SBrowser.xbm' asFilename fileType |
|
3664 | 181 |
'../../libtool/bitmaps/SBrowser.xbm' asFilename fileType |
16581 | 182 |
'./stx' asFilename fileType |
2907 | 183 |
" |
184 |
||
3664 | 185 |
"Modified: / 21.7.1998 / 11:26:32 / cg" |
2907 | 186 |
! ! |
187 |
||
2931 | 188 |
!UnixFilename methodsFor:'queries'! |
189 |
||
190 |
isExplicitRelative |
|
191 |
"return true, if this name is an explicit relative name |
|
192 |
(i.e. starts with './' or '../', to avoid path-prepending)" |
|
193 |
||
194 |
(nameString startsWith:'./') ifTrue:[ |
|
195 |
^ true |
|
196 |
]. |
|
197 |
(nameString startsWith:'../') ifTrue:[ |
|
198 |
^ true |
|
199 |
]. |
|
200 |
^ false |
|
201 |
! |
|
202 |
||
203 |
isHidden |
|
204 |
"return true, if the receiver represents a hidden file. |
|
205 |
On UNIX, a name starting with a period is considered hidden." |
|
206 |
||
12390 | 207 |
|baseName| |
208 |
||
209 |
baseName := self baseName. |
|
210 |
^ ((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
|
211 |
! |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
212 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
213 |
isImplicit |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
214 |
"return true, if the receiver represents builtin names such as '.' or '..'. |
3664 | 215 |
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
|
216 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
217 |
|name| |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
218 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
219 |
name := self baseName. |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
220 |
^ name = '.' or:[name = '..']. |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
221 |
|
3664 | 222 |
"Modified: / 18.9.1997 / 18:03:28 / stefan" |
223 |
"Modified: / 21.7.1998 / 11:10:42 / cg" |
|
2931 | 224 |
! ! |
225 |
||
11318
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
226 |
!UnixFilename methodsFor:'special accessing'! |
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
227 |
|
14221
d2ef1c042257
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
12390
diff
changeset
|
228 |
osName |
d2ef1c042257
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
12390
diff
changeset
|
229 |
"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
|
230 |
|
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
231 |
^ self osNameForFile |
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
232 |
! ! |
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
233 |
|
2911 | 234 |
!UnixFilename class methodsFor:'documentation'! |
2907 | 235 |
|
2911 | 236 |
version |
19818 | 237 |
^ '$Header$' |
12390 | 238 |
! |
239 |
||
240 |
version_CVS |
|
19818 | 241 |
^ '$Header$' |
2907 | 242 |
! ! |
14818 | 243 |