author | Stefan Vogel <sv@exept.de> |
Wed, 14 Jan 1998 15:12:50 +0100 | |
changeset 3171 | 02ef7b6cc664 |
parent 3125 | 543358373041 |
child 3664 | 7bcbf8c6c2cf |
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). |
|
98 |
On non-unix systems, this may return an empty string, not knowning |
|
99 |
about the contents. |
|
100 |
Since the returned string differs among systems (and language settings), |
|
101 |
it is only useful for user-information; NOT as a tag to be used by a program." |
|
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:[ |
3125
543358373041
care for filenames with blanks when invoking 'file' command
Claus Gittinger <cg@exept.de>
parents:
2943
diff
changeset
|
114 |
typeString := stream contents asString. |
543358373041
care for filenames with blanks when invoking 'file' command
Claus Gittinger <cg@exept.de>
parents:
2943
diff
changeset
|
115 |
stream close. |
543358373041
care for filenames with blanks when invoking 'file' command
Claus Gittinger <cg@exept.de>
parents:
2943
diff
changeset
|
116 |
typeString := typeString copyFrom:(typeString indexOf:$:) + 1. |
543358373041
care for filenames with blanks when invoking 'file' command
Claus Gittinger <cg@exept.de>
parents:
2943
diff
changeset
|
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 |
|
127 |
" |
|
128 |
||
129 |
"Modified: 7.9.1997 / 23:43:03 / cg" |
|
130 |
! ! |
|
131 |
||
2931 | 132 |
!UnixFilename methodsFor:'queries'! |
133 |
||
134 |
isExplicitRelative |
|
135 |
"return true, if this name is an explicit relative name |
|
136 |
(i.e. starts with './' or '../', to avoid path-prepending)" |
|
137 |
||
138 |
(nameString startsWith:'./') ifTrue:[ |
|
139 |
^ true |
|
140 |
]. |
|
141 |
(nameString startsWith:'../') ifTrue:[ |
|
142 |
^ true |
|
143 |
]. |
|
144 |
^ false |
|
145 |
! |
|
146 |
||
147 |
isHidden |
|
148 |
"return true, if the receiver represents a hidden file. |
|
149 |
On UNIX, a name starting with a period is considered hidden." |
|
150 |
||
151 |
^ 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
|
152 |
! |
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 |
isImplicit |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
155 |
"return true, if the receiver represents builtin names such as '.' or '..'. |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
156 |
On UNIX, a name starting with a period is considered hidden." |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
157 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
158 |
|name| |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
159 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
160 |
name := self baseName. |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
161 |
^ name = '.' or:[name = '..']. |
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
162 |
|
89dee83077bd
Add #isImplicit to check for builtin dir names such as '.' and '..'.
Stefan Vogel <sv@exept.de>
parents:
2931
diff
changeset
|
163 |
"Modified: 18.9.1997 / 18:03:28 / stefan" |
2931 | 164 |
! ! |
165 |
||
2911 | 166 |
!UnixFilename class methodsFor:'documentation'! |
2907 | 167 |
|
2911 | 168 |
version |
3171 | 169 |
^ '$Header: /cvs/stx/stx/libbasic/UnixFilename.st,v 1.7 1998-01-14 14:12:13 stefan Exp $' |
2907 | 170 |
! ! |