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