author | Stefan Vogel <sv@exept.de> |
Fri, 11 Apr 2003 18:47:17 +0200 | |
changeset 7205 | 903fef64420c |
parent 3664 | 7bcbf8c6c2cf |
child 7939 | 3a8b75e8f804 |
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 |
" |
2907 | 12 |
|
13 |
Filename subclass:#UnixFilename |
|
14 |
instanceVariableNames:'' |
|
15 |
classVariableNames:'' |
|
16 |
poolDictionaries:'' |
|
17 |
category:'OS-Unix' |
|
18 |
! |
|
19 |
||
2911 | 20 |
!UnixFilename class methodsFor:'documentation'! |
21 |
||
2931 | 22 |
copyright |
23 |
" |
|
24 |
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
|
25 |
All Rights Reserved |
2931 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
2911 | 36 |
documentation |
37 |
" |
|
38 |
Filenames in Unix. |
|
39 |
" |
|
40 |
||
41 |
! ! |
|
42 |
||
2907 | 43 |
!UnixFilename class methodsFor:'queries'! |
44 |
||
45 |
isBadCharacter:aCharacter |
|
46 |
"return true, if aCharacter is unallowed in a filename." |
|
47 |
||
48 |
aCharacter == $/ ifTrue:[^ true]. |
|
49 |
^ super isBadCharacter:aCharacter |
|
50 |
||
51 |
"Created: 8.9.1997 / 00:13:14 / cg" |
|
52 |
! |
|
53 |
||
2908 | 54 |
isCaseSensitive |
55 |
"return true, if filenames are case sensitive.return true, if filenames are case sensitive." |
|
56 |
||
57 |
^ true |
|
58 |
! |
|
59 |
||
3171 | 60 |
nullFilename |
61 |
"Return /dev/null" |
|
62 |
||
63 |
^ '/dev/null' |
|
64 |
||
65 |
" |
|
66 |
Filename concreteClass nullFilename |
|
67 |
" |
|
68 |
||
69 |
"Modified: / 14.1.1998 / 14:20:55 / stefan" |
|
70 |
! |
|
71 |
||
2908 | 72 |
parentDirectoryName |
73 |
"return the name used for the parent directory. |
|
74 |
This is '..' for unix and dos-like systems. |
|
75 |
(there may be more in the future." |
|
76 |
||
77 |
^ '..' |
|
78 |
! |
|
79 |
||
2907 | 80 |
separator |
81 |
"return the file/directory separator." |
|
82 |
||
83 |
^ $/ |
|
84 |
||
85 |
" |
|
86 |
Filename concreteClass separator |
|
87 |
" |
|
88 |
||
89 |
"Created: 8.9.1997 / 00:18:14 / cg" |
|
90 |
! ! |
|
91 |
||
92 |
!UnixFilename methodsFor:'file queries'! |
|
93 |
||
94 |
fileType |
|
95 |
"this returns a string describing the type of contents of |
|
96 |
the file. This is done using the unix 'file' command, |
|
97 |
(which usually is configurable by /etc/magic). |
|
3664 | 98 |
Warning: |
99 |
Since the returned string differs among systems (and language settings), |
|
100 |
it is only useful for user-information; |
|
101 |
NOT as a tag to be used by a program." |
|
2907 | 102 |
|
103 |
|stream typeString| |
|
104 |
||
105 |
"/ since executing 'file' takes some time, do the most common |
|
106 |
"/ ones are checked first, using the general fileType implementation. |
|
107 |
"/ (also, the file-command is only available on Unix systems. |
|
108 |
||
109 |
typeString := super fileType. |
|
110 |
typeString ~= 'file' ifTrue:[^ typeString]. |
|
111 |
||
3125
543358373041
care for filenames with blanks when invoking 'file' command
Claus Gittinger <cg@exept.de>
parents:
2943
diff
changeset
|
112 |
stream := PipeStream readingFrom:('file "' , self pathName , '"'). |
2907 | 113 |
stream notNil ifTrue:[ |
3664 | 114 |
typeString := stream contents asString. |
115 |
stream close. |
|
116 |
typeString := typeString copyFrom:(typeString indexOf:$:) + 1. |
|
117 |
typeString := typeString withoutSeparators |
|
2907 | 118 |
]. |
119 |
^ typeString |
|
120 |
||
121 |
" |
|
122 |
'Makefile' asFilename fileType |
|
123 |
'.' asFilename fileType |
|
124 |
'/dev/null' asFilename fileType |
|
125 |
'smalltalk.rc' asFilename fileType |
|
126 |
'bitmaps/SBrowser.xbm' asFilename fileType |
|
3664 | 127 |
'../../libtool/bitmaps/SBrowser.xbm' asFilename fileType |
2907 | 128 |
" |
129 |
||
3664 | 130 |
"Modified: / 21.7.1998 / 11:26:32 / cg" |
2907 | 131 |
! ! |
132 |
||
2931 | 133 |
!UnixFilename methodsFor:'queries'! |
134 |
||
135 |
isExplicitRelative |
|
136 |
"return true, if this name is an explicit relative name |
|
137 |
(i.e. starts with './' or '../', to avoid path-prepending)" |
|
138 |
||
139 |
(nameString startsWith:'./') ifTrue:[ |
|
140 |
^ true |
|
141 |
]. |
|
142 |
(nameString startsWith:'../') ifTrue:[ |
|
143 |
^ true |
|
144 |
]. |
|
145 |
^ false |
|
146 |
! |
|
147 |
||
148 |
isHidden |
|
149 |
"return true, if the receiver represents a hidden file. |
|
150 |
On UNIX, a name starting with a period is considered hidden." |
|
151 |
||
152 |
^ self baseName startsWith:'.' |
|
2943
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
153 |
! |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
154 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
155 |
isImplicit |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
156 |
"return true, if the receiver represents builtin names such as '.' or '..'. |
3664 | 157 |
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
|
158 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
159 |
|name| |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
160 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
161 |
name := self baseName. |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
162 |
^ name = '.' or:[name = '..']. |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
163 |
|
3664 | 164 |
"Modified: / 18.9.1997 / 18:03:28 / stefan" |
165 |
"Modified: / 21.7.1998 / 11:10:42 / cg" |
|
166 |
! |
|
167 |
||
168 |
nameWithSpecialExpansions:aString |
|
169 |
"return the nameString, expanding any OS specific macros. |
|
170 |
Here, a ~ prefix is expanded to the users home dir (as in csh)" |
|
171 |
||
172 |
|dir user cutIdx idx userInfo| |
|
173 |
||
174 |
(aString startsWith:'~') ifTrue:[ |
|
175 |
dir := OperatingSystem getHomeDirectory. |
|
176 |
cutIdx := 2. |
|
177 |
"/ look for ~username |
|
178 |
(aString size > 1) ifTrue:[ |
|
179 |
idx := aString indexOf:$/. |
|
180 |
idx == 0 ifTrue:[ |
|
181 |
user := aString copyFrom:2. |
|
182 |
cutIdx := aString size + 1. |
|
183 |
] ifFalse:[ |
|
184 |
user := aString copyFrom:2 to:(idx - 1). |
|
185 |
cutIdx := idx. |
|
186 |
]. |
|
187 |
user size > 0 ifTrue:[ |
|
188 |
userInfo := OperatingSystem userInfoOf:user. |
|
189 |
(userInfo notNil and:[userInfo includesKey:#dir]) ifTrue:[ |
|
190 |
dir := userInfo at:#dir |
|
191 |
] ifFalse:[ |
|
192 |
dir := nil |
|
193 |
] |
|
194 |
]. |
|
195 |
dir isNil ifTrue:[ |
|
196 |
"/ ('Filename [info]: unknown user: ' , user) infoPrintCR. |
|
197 |
^ aString |
|
198 |
]. |
|
199 |
]. |
|
200 |
^ dir , (aString copyFrom:cutIdx) |
|
201 |
]. |
|
202 |
^ aString |
|
203 |
||
204 |
" |
|
205 |
UnixFilename new nameWithSpecialExpansions:'~' |
|
206 |
UnixFilename new nameWithSpecialExpansions:'~/work' |
|
207 |
UnixFilename new nameWithSpecialExpansions:'~sv' |
|
208 |
UnixFilename new nameWithSpecialExpansions:'~sv/work' |
|
209 |
UnixFilename new nameWithSpecialExpansions:'~foo' |
|
210 |
UnixFilename new nameWithSpecialExpansions:'~foo/bar' |
|
211 |
" |
|
212 |
||
213 |
"Modified: / 21.7.1998 / 11:09:59 / cg" |
|
2931 | 214 |
! ! |
215 |
||
2911 | 216 |
!UnixFilename class methodsFor:'documentation'! |
2907 | 217 |
|
2911 | 218 |
version |
3664 | 219 |
^ '$Header: /cvs/stx/stx/libbasic/UnixFilename.st,v 1.8 1998-07-21 14:26:50 cg Exp $' |
2907 | 220 |
! ! |