author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sat, 09 Apr 2011 18:19:04 +0100 | |
branch | jv |
changeset 17834 | 04ff72c5039a |
parent 17814 | b75a7f0c346b |
child 17841 | 7abcc4aef871 |
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 |
" |
17767 | 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 |
|
2907 | 50 |
!UnixFilename class methodsFor:'queries'! |
51 |
||
52 |
isBadCharacter:aCharacter |
|
53 |
"return true, if aCharacter is unallowed in a filename." |
|
54 |
||
55 |
aCharacter == $/ ifTrue:[^ true]. |
|
56 |
^ super isBadCharacter:aCharacter |
|
57 |
||
58 |
"Created: 8.9.1997 / 00:13:14 / cg" |
|
59 |
! |
|
60 |
||
2908 | 61 |
isCaseSensitive |
62 |
"return true, if filenames are case sensitive.return true, if filenames are case sensitive." |
|
63 |
||
64 |
^ true |
|
65 |
! |
|
66 |
||
3171 | 67 |
nullFilename |
68 |
"Return /dev/null" |
|
69 |
||
70 |
^ '/dev/null' |
|
71 |
||
72 |
" |
|
8752 | 73 |
Filename nullFilename |
3171 | 74 |
" |
75 |
||
76 |
"Modified: / 14.1.1998 / 14:20:55 / stefan" |
|
77 |
! |
|
78 |
||
2908 | 79 |
parentDirectoryName |
80 |
"return the name used for the parent directory. |
|
81 |
This is '..' for unix and dos-like systems. |
|
82 |
(there may be more in the future." |
|
83 |
||
84 |
^ '..' |
|
85 |
! |
|
86 |
||
2907 | 87 |
separator |
88 |
"return the file/directory separator." |
|
89 |
||
90 |
^ $/ |
|
91 |
||
92 |
" |
|
93 |
Filename concreteClass separator |
|
94 |
" |
|
95 |
||
96 |
"Created: 8.9.1997 / 00:18:14 / cg" |
|
8245 | 97 |
! |
98 |
||
99 |
separatorString |
|
100 |
"return the file/directory separator as a string." |
|
101 |
||
102 |
^ '/' |
|
103 |
||
104 |
" |
|
8752 | 105 |
Filename separatorString |
8245 | 106 |
" |
2907 | 107 |
! ! |
108 |
||
109 |
!UnixFilename methodsFor:'file queries'! |
|
110 |
||
111 |
fileType |
|
112 |
"this returns a string describing the type of contents of |
|
113 |
the file. This is done using the unix 'file' command, |
|
114 |
(which usually is configurable by /etc/magic). |
|
3664 | 115 |
Warning: |
116 |
Since the returned string differs among systems (and language settings), |
|
117 |
it is only useful for user-information; |
|
118 |
NOT as a tag to be used by a program." |
|
2907 | 119 |
|
120 |
|stream typeString| |
|
121 |
||
122 |
"/ since executing 'file' takes some time, do the most common |
|
123 |
"/ ones are checked first, using the general fileType implementation. |
|
124 |
"/ (also, the file-command is only available on Unix systems. |
|
125 |
||
126 |
typeString := super fileType. |
|
127 |
typeString ~= 'file' ifTrue:[^ typeString]. |
|
128 |
||
3125
543358373041
care for filenames with blanks when invoking 'file' command
Claus Gittinger <cg@exept.de>
parents:
2943
diff
changeset
|
129 |
stream := PipeStream readingFrom:('file "' , self pathName , '"'). |
2907 | 130 |
stream notNil ifTrue:[ |
3664 | 131 |
typeString := stream contents asString. |
132 |
stream close. |
|
133 |
typeString := typeString copyFrom:(typeString indexOf:$:) + 1. |
|
134 |
typeString := typeString withoutSeparators |
|
2907 | 135 |
]. |
136 |
^ typeString |
|
137 |
||
138 |
" |
|
139 |
'Makefile' asFilename fileType |
|
140 |
'.' asFilename fileType |
|
141 |
'/dev/null' asFilename fileType |
|
142 |
'smalltalk.rc' asFilename fileType |
|
143 |
'bitmaps/SBrowser.xbm' asFilename fileType |
|
3664 | 144 |
'../../libtool/bitmaps/SBrowser.xbm' asFilename fileType |
2907 | 145 |
" |
146 |
||
3664 | 147 |
"Modified: / 21.7.1998 / 11:26:32 / cg" |
2907 | 148 |
! ! |
149 |
||
2931 | 150 |
!UnixFilename methodsFor:'queries'! |
151 |
||
152 |
isExplicitRelative |
|
153 |
"return true, if this name is an explicit relative name |
|
154 |
(i.e. starts with './' or '../', to avoid path-prepending)" |
|
155 |
||
156 |
(nameString startsWith:'./') ifTrue:[ |
|
157 |
^ true |
|
158 |
]. |
|
159 |
(nameString startsWith:'../') ifTrue:[ |
|
160 |
^ true |
|
161 |
]. |
|
162 |
^ false |
|
163 |
! |
|
164 |
||
165 |
isHidden |
|
166 |
"return true, if the receiver represents a hidden file. |
|
167 |
On UNIX, a name starting with a period is considered hidden." |
|
168 |
||
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
169 |
|baseName| |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
170 |
|
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
171 |
baseName := self baseName. |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
172 |
^ ((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
|
173 |
! |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
174 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
175 |
isImplicit |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
176 |
"return true, if the receiver represents builtin names such as '.' or '..'. |
3664 | 177 |
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
|
178 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
179 |
|name| |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
180 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
181 |
name := self baseName. |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
182 |
^ name = '.' or:[name = '..']. |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
183 |
|
3664 | 184 |
"Modified: / 18.9.1997 / 18:03:28 / stefan" |
185 |
"Modified: / 21.7.1998 / 11:10:42 / cg" |
|
2931 | 186 |
! ! |
187 |
||
11318
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
188 |
!UnixFilename methodsFor:'special accessing'! |
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
189 |
|
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
190 |
osNameForDirectory |
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
191 |
"internal - return the OS's name for the receiver to |
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
192 |
access it as a directory." |
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
193 |
|
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
194 |
^ self osNameForFile |
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
195 |
! |
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
196 |
|
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
197 |
osNameForFile |
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
198 |
"internal - return the OS's name for the receiver to |
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
199 |
access it as a file." |
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
200 |
|
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
201 |
nameString bitsPerCharacter < 8 ifTrue:[ |
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
202 |
^ nameString. |
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
203 |
]. |
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
204 |
^ nameString utf8Encoded. |
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
205 |
! ! |
fc07976462e8
Care for UTF8 filenams in linux/unix
Stefan Vogel <sv@exept.de>
parents:
9940
diff
changeset
|
206 |
|
2911 | 207 |
!UnixFilename class methodsFor:'documentation'! |
2907 | 208 |
|
2911 | 209 |
version |
17834 | 210 |
^ '$Id: UnixFilename.st 10632 2011-04-09 17:19:04Z vranyj1 $' |
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
211 |
! |
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
212 |
|
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
213 |
version_CVS |
17834 | 214 |
^ 'Header: /var/local/cvs/stx/libbasic/UnixFilename.st,v 1.16 2009-10-28 14:02:12 cg Exp ' |
17761
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17735
diff
changeset
|
215 |
! |
17734
406b1590afe8
Merged with trunk r10476
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
216 |
|
17761
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17735
diff
changeset
|
217 |
version_SVN |
17834 | 218 |
^ '$Id: UnixFilename.st 10632 2011-04-09 17:19:04Z vranyj1 $' |
17761
b0e5971141bc
Added Lookup and BuiltinLookup classes
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17735
diff
changeset
|
219 |
! ! |
17767 | 220 |
|
17772
6e0b3c06c364
Method reverted to r10532
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17767
diff
changeset
|
221 |
|
17780 | 222 |
|
17807 | 223 |
|
17814 | 224 |
|
17834 | 225 |