author | Stefan Vogel <sv@exept.de> |
Mon, 30 Jul 2018 09:04:37 +0200 | |
changeset 23243 | e04d4a19c021 |
parent 23042 | def1ea6ee127 |
child 23600 | f7a4056adc93 |
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 |
||
2907 | 88 |
!UnixFilename class methodsFor:'queries'! |
89 |
||
90 |
isBadCharacter:aCharacter |
|
91 |
"return true, if aCharacter is unallowed in a filename." |
|
92 |
||
93 |
aCharacter == $/ ifTrue:[^ true]. |
|
94 |
^ super isBadCharacter:aCharacter |
|
95 |
||
96 |
"Created: 8.9.1997 / 00:13:14 / cg" |
|
97 |
! |
|
98 |
||
2908 | 99 |
isCaseSensitive |
19818 | 100 |
"return true, if filenames are case sensitive. |
101 |
This is not really correct, as the sensitivity may depend on |
|
102 |
the paricular mounted file system (NFS, for example)" |
|
2908 | 103 |
|
14818 | 104 |
^ OperatingSystem caseSensitiveFilenames |
2908 | 105 |
! |
106 |
||
3171 | 107 |
nullFilename |
108 |
"Return /dev/null" |
|
109 |
||
110 |
^ '/dev/null' |
|
111 |
||
112 |
" |
|
8752 | 113 |
Filename nullFilename |
3171 | 114 |
" |
115 |
||
116 |
"Modified: / 14.1.1998 / 14:20:55 / stefan" |
|
117 |
! |
|
118 |
||
2908 | 119 |
parentDirectoryName |
120 |
"return the name used for the parent directory. |
|
121 |
This is '..' for unix and dos-like systems. |
|
122 |
(there may be more in the future." |
|
123 |
||
124 |
^ '..' |
|
125 |
! |
|
126 |
||
2907 | 127 |
separator |
128 |
"return the file/directory separator." |
|
129 |
||
130 |
^ $/ |
|
131 |
||
132 |
" |
|
133 |
Filename concreteClass separator |
|
134 |
" |
|
135 |
||
136 |
"Created: 8.9.1997 / 00:18:14 / cg" |
|
8245 | 137 |
! |
138 |
||
139 |
separatorString |
|
140 |
"return the file/directory separator as a string." |
|
141 |
||
142 |
^ '/' |
|
143 |
||
144 |
" |
|
8752 | 145 |
Filename separatorString |
8245 | 146 |
" |
2907 | 147 |
! ! |
148 |
||
149 |
!UnixFilename methodsFor:'file queries'! |
|
150 |
||
151 |
fileType |
|
21276 | 152 |
"this returns a string describing the type of contents of the file. |
153 |
This is done using the unix 'file' command, |
|
2907 | 154 |
(which usually is configurable by /etc/magic). |
3664 | 155 |
Warning: |
156 |
Since the returned string differs among systems (and language settings), |
|
157 |
it is only useful for user-information; |
|
21276 | 158 |
NOT as a tag to be used by a program. |
159 |
For this, use mimeType or mimeTypeOfContents." |
|
2907 | 160 |
|
16581 | 161 |
|typeString| |
2907 | 162 |
|
16754 | 163 |
"/ since executing 'file' takes some time, the most common |
2907 | 164 |
"/ ones are checked first, using the general fileType implementation. |
16754 | 165 |
"/ (also, the file-command is only available on Unix systems, |
166 |
"/ so this provides a reasonable fallback). |
|
2907 | 167 |
|
168 |
typeString := super fileType. |
|
169 |
typeString ~= 'file' ifTrue:[^ typeString]. |
|
170 |
||
22276 | 171 |
typeString := PipeStream outputFromCommand:('/usr/bin/file "' , self pathName , '"'). |
16581 | 172 |
typeString notNil ifTrue:[ |
3664 | 173 |
typeString := typeString copyFrom:(typeString indexOf:$:) + 1. |
174 |
typeString := typeString withoutSeparators |
|
2907 | 175 |
]. |
176 |
^ typeString |
|
177 |
||
178 |
" |
|
179 |
'Makefile' asFilename fileType |
|
180 |
'.' asFilename fileType |
|
181 |
'/dev/null' asFilename fileType |
|
182 |
'smalltalk.rc' asFilename fileType |
|
183 |
'bitmaps/SBrowser.xbm' asFilename fileType |
|
3664 | 184 |
'../../libtool/bitmaps/SBrowser.xbm' asFilename fileType |
16581 | 185 |
'./stx' asFilename fileType |
2907 | 186 |
" |
187 |
||
22276 | 188 |
"Modified: / 21-07-1998 / 11:26:32 / cg" |
189 |
"Modified: / 21-09-2017 / 11:09:52 / stefan" |
|
2907 | 190 |
! ! |
191 |
||
2931 | 192 |
!UnixFilename methodsFor:'queries'! |
193 |
||
194 |
isExplicitRelative |
|
195 |
"return true, if this name is an explicit relative name |
|
196 |
(i.e. starts with './' or '../', to avoid path-prepending)" |
|
197 |
||
198 |
(nameString startsWith:'./') ifTrue:[ |
|
199 |
^ true |
|
200 |
]. |
|
201 |
(nameString startsWith:'../') ifTrue:[ |
|
202 |
^ true |
|
203 |
]. |
|
204 |
^ false |
|
205 |
! |
|
206 |
||
207 |
isHidden |
|
208 |
"return true, if the receiver represents a hidden file. |
|
209 |
On UNIX, a name starting with a period is considered hidden." |
|
210 |
||
12390 | 211 |
|baseName| |
212 |
||
213 |
baseName := self baseName. |
|
214 |
^ ((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
|
215 |
! |
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 |
isImplicit |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
218 |
"return true, if the receiver represents builtin names such as '.' or '..'. |
3664 | 219 |
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
|
220 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
221 |
|name| |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
222 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
223 |
name := self baseName. |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
224 |
^ name = '.' or:[name = '..']. |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
225 |
|
3664 | 226 |
"Modified: / 18.9.1997 / 18:03:28 / stefan" |
227 |
"Modified: / 21.7.1998 / 11:10:42 / cg" |
|
2931 | 228 |
! ! |
229 |
||
11318
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
230 |
!UnixFilename methodsFor:'special accessing'! |
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
231 |
|
14221
d2ef1c042257
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
12390
diff
changeset
|
232 |
osName |
d2ef1c042257
Fix the '~/dir/name' resolution fow windows
Stefan Vogel <sv@exept.de>
parents:
12390
diff
changeset
|
233 |
"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
|
234 |
|
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
235 |
^ self osNameForFile |
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
236 |
! ! |
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
237 |
|
2911 | 238 |
!UnixFilename class methodsFor:'documentation'! |
2907 | 239 |
|
2911 | 240 |
version |
19818 | 241 |
^ '$Header$' |
12390 | 242 |
! |
243 |
||
244 |
version_CVS |
|
19818 | 245 |
^ '$Header$' |
2907 | 246 |
! ! |
14818 | 247 |