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