2907
|
1 |
'From Smalltalk/X, Version:3.1.9 on 8-sep-1997 at 12:39:54 am' !
|
|
2 |
|
|
3 |
Filename subclass:#UnixFilename
|
|
4 |
instanceVariableNames:''
|
|
5 |
classVariableNames:''
|
|
6 |
poolDictionaries:''
|
|
7 |
category:'OS-Unix'
|
|
8 |
!
|
|
9 |
|
|
10 |
!UnixFilename class methodsFor:'queries'!
|
|
11 |
|
|
12 |
isBadCharacter:aCharacter
|
|
13 |
"return true, if aCharacter is unallowed in a filename."
|
|
14 |
|
|
15 |
aCharacter == $/ ifTrue:[^ true].
|
|
16 |
^ super isBadCharacter:aCharacter
|
|
17 |
|
|
18 |
"Created: 8.9.1997 / 00:13:14 / cg"
|
|
19 |
!
|
|
20 |
|
2908
|
21 |
isCaseSensitive
|
|
22 |
"return true, if filenames are case sensitive.return true, if filenames are case sensitive."
|
|
23 |
|
|
24 |
^ true
|
|
25 |
!
|
|
26 |
|
|
27 |
parentDirectoryName
|
|
28 |
"return the name used for the parent directory.
|
|
29 |
This is '..' for unix and dos-like systems.
|
|
30 |
(there may be more in the future."
|
|
31 |
|
|
32 |
^ '..'
|
|
33 |
!
|
|
34 |
|
2907
|
35 |
separator
|
|
36 |
"return the file/directory separator."
|
|
37 |
|
|
38 |
^ $/
|
|
39 |
|
|
40 |
"
|
|
41 |
Filename concreteClass separator
|
|
42 |
"
|
|
43 |
|
|
44 |
"Created: 8.9.1997 / 00:18:14 / cg"
|
|
45 |
! !
|
|
46 |
|
|
47 |
!UnixFilename methodsFor:'file queries'!
|
|
48 |
|
|
49 |
fileType
|
|
50 |
"this returns a string describing the type of contents of
|
|
51 |
the file. This is done using the unix 'file' command,
|
|
52 |
(which usually is configurable by /etc/magic).
|
|
53 |
On non-unix systems, this may return an empty string, not knowning
|
|
54 |
about the contents.
|
|
55 |
Since the returned string differs among systems (and language settings),
|
|
56 |
it is only useful for user-information; NOT as a tag to be used by a program."
|
|
57 |
|
|
58 |
|stream typeString|
|
|
59 |
|
|
60 |
"/ since executing 'file' takes some time, do the most common
|
|
61 |
"/ ones are checked first, using the general fileType implementation.
|
|
62 |
"/ (also, the file-command is only available on Unix systems.
|
|
63 |
|
|
64 |
typeString := super fileType.
|
|
65 |
typeString ~= 'file' ifTrue:[^ typeString].
|
|
66 |
|
|
67 |
stream := PipeStream readingFrom:('file ' , self pathName).
|
|
68 |
stream notNil ifTrue:[
|
|
69 |
typeString := stream contents asString.
|
|
70 |
stream close.
|
|
71 |
typeString := typeString copyFrom:(typeString indexOf:$:) + 1.
|
|
72 |
typeString := typeString withoutSeparators
|
|
73 |
].
|
|
74 |
^ typeString
|
|
75 |
|
|
76 |
"
|
|
77 |
'Makefile' asFilename fileType
|
|
78 |
'.' asFilename fileType
|
|
79 |
'/dev/null' asFilename fileType
|
|
80 |
'smalltalk.rc' asFilename fileType
|
|
81 |
'bitmaps/SBrowser.xbm' asFilename fileType
|
|
82 |
"
|
|
83 |
|
|
84 |
"Modified: 7.9.1997 / 23:43:03 / cg"
|
|
85 |
! !
|
|
86 |
|
|
87 |
!UnixFilename methodsFor:'instance creation'!
|
|
88 |
|
|
89 |
constructString:subname
|
|
90 |
"taking the receiver as a directory name, construct a new
|
2908
|
91 |
filename-string for an entry within this directory
|
2907
|
92 |
(i.e. for a file or a subdirectory in that directory)."
|
|
93 |
|
|
94 |
|sepString|
|
|
95 |
|
|
96 |
sepString := self class separator asString.
|
|
97 |
nameString = sepString ifTrue:[
|
|
98 |
"I am the root"
|
|
99 |
^ sepString , subname
|
|
100 |
].
|
|
101 |
^ nameString , sepString , subname asString
|
|
102 |
|
|
103 |
"
|
|
104 |
'/tmp' asFilename constructString:'foo'
|
|
105 |
'/' asFilename constructString:'foo'
|
|
106 |
'/usr/tmp' asFilename constructString:'foo'
|
|
107 |
'/foo/bar' asFilename constructString:'baz'
|
|
108 |
"
|
|
109 |
|
|
110 |
"Modified: 7.9.1995 / 10:15:22 / claus"
|
|
111 |
"Modified: 29.2.1996 / 20:55:18 / cg"
|
|
112 |
"Created: 7.9.1997 / 23:44:55 / cg"
|
|
113 |
! !
|
|
114 |
|