--- a/FileDir.st Mon Oct 10 01:29:01 1994 +0100
+++ b/FileDir.st Mon Oct 10 01:29:28 1994 +0100
@@ -21,7 +21,7 @@
COPYRIGHT (c) 1989 by Claus Gittinger
All Rights Reserved
-$Header: /cvs/stx/stx/libbasic/Attic/FileDir.st,v 1.11 1994-08-05 00:54:45 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Attic/FileDir.st,v 1.12 1994-10-10 00:26:00 claus Exp $
'!
!FileDirectory class methodsFor:'documentation'!
@@ -42,7 +42,7 @@
version
"
-$Header: /cvs/stx/stx/libbasic/Attic/FileDir.st,v 1.11 1994-08-05 00:54:45 claus Exp $
+$Header: /cvs/stx/stx/libbasic/Attic/FileDir.st,v 1.12 1994-10-10 00:26:00 claus Exp $
"
!
@@ -72,7 +72,7 @@
rootDirectory
"create and return a new FileDirectory for the root directory"
- ^ (self basicNew) pathName:'/'
+ ^ (self basicNew) pathName:(OperatingSystem fileSeparator asString)
"
FileDirectory rootDirectory contents
@@ -110,9 +110,10 @@
"create and return a new FileDirectory for the directory with given name
in another FileDirectory"
- |baseName|
+ |baseName sep|
- ((name at:1) == $/) ifTrue:[
+ sep := OperatingSystem fileSeparator.
+ ((name at:1) == sep) ifTrue:[
^ self directoryNamed:name
].
(aFileDirectory isKindOf:FileDirectory) ifTrue:[
@@ -127,9 +128,9 @@
"
(name = '.') ifTrue:[^ aFileDirectory].
- (baseName = '/') ifFalse:[
- (baseName endsWith:'/') ifFalse:[
- baseName := baseName , '/'
+ (baseName = sep asString) ifFalse:[
+ (baseName endsWith:sep) ifFalse:[
+ baseName := baseName copyWith:sep
]
].
^ (self basicNew) pathName:(baseName , name)
@@ -164,7 +165,7 @@
"set my pathname; return nil if not a valid path; self otherwise"
pathName := dirName.
- (dirName startsWith:'/') ifFalse:[
+ (dirName startsWith:OperatingSystem fileSeparator) ifFalse:[
lazy := true
] ifTrue:[
(dirName includes:$.) ifTrue:[
@@ -226,7 +227,7 @@
|aStream command shortPathName fullPathName|
- (pathName = '/') ifTrue:[
+ (pathName = OperatingSystem fileSeparator asString) ifTrue:[
lazy := false.
^ self
].
@@ -299,16 +300,12 @@
(newName = '.') ifFalse:[
(newName = '..') ifFalse:[
- ((newName at:1) == $/) ifTrue:[
+ ((newName at:1) == OperatingSystem fileSeparator) ifTrue:[
realName := newName copyFrom:2
] ifFalse:[
realName := newName
].
- (realName startsWith:'/') ifTrue:[
- ^ OperatingSystem createDirectory:realName
- ] ifFalse:[
- ^ OperatingSystem createDirectory:(pathName , '/' , realName)
- ]
+ ^ OperatingSystem createDirectory:(self class fullPathNameOf:realName in:pathName)
]
].
^ false
@@ -317,10 +314,7 @@
removeFile:fileName
"remove the file 'fileName' from myself; return true if successful"
- (fileName startsWith:'/') ifTrue:[
- ^ OperatingSystem removeFile:fileName
- ].
- ^ OperatingSystem removeFile:(pathName , '/' , fileName)
+ ^ OperatingSystem removeFile:(self class fullPathNameOf:fileName in:pathName).
!
removeDirectory:dirName
@@ -328,15 +322,11 @@
If the directory is not empty, the containing files/directories are also
removed."
- |absPath|
+ |path|
- (dirName startsWith:'/') ifTrue:[
- absPath := dirName
- ] ifFalse:[
- absPath := pathName , '/' , dirName
- ].
- (OperatingSystem removeDirectory:absPath) ifTrue:[^ true].
- ^ OperatingSystem recursiveRemoveDirectory:absPath
+ path := self class fullPathNameOf:dirName in:pathName.
+ (OperatingSystem removeDirectory:path) ifTrue:[^ true].
+ ^ OperatingSystem recursiveRemoveDirectory:path
!
remove:aFileOrDirectoryName
@@ -344,11 +334,7 @@
|path|
- (aFileOrDirectoryName startsWith:'/') ifTrue:[
- path := aFileOrDirectoryName
- ] ifFalse:[
- path := (pathName , '/' , aFileOrDirectoryName)
- ].
+ path := self class fullPathNameOf:aFileOrDirectoryName in:pathName.
(OperatingSystem isDirectory:path) ifTrue:[
^ OperatingSystem removeDirectory:path
].
@@ -360,16 +346,8 @@
|path1 path2|
- (oldFileName startsWith:'/') ifTrue:[
- path1 := oldFileName
- ] ifFalse:[
- path1 := (pathName , '/' , oldFileName)
- ].
- (newFileName startsWith:'/') ifTrue:[
- path2 := newFileName
- ] ifFalse:[
- path2 := (pathName , '/' , newFileName)
- ].
+ path1 := self class fullPathNameOf:oldFileName in:pathName.
+ path2 := self class fullPathNameOf:newFileName in:pathName.
^ OperatingSystem linkFile:path1 to:path2
!
@@ -378,17 +356,18 @@
|path1 path2|
- (oldFileName startsWith:'/') ifTrue:[
- path1 := oldFileName
- ] ifFalse:[
- path1 := (pathName , '/' , oldFileName)
+ path1 := self class fullPathNameOf:oldFileName in:pathName.
+ path2 := self class fullPathNameOf:newFileName in:pathName.
+ ^ OperatingSystem renameFile:path1 to:path2
+! !
+
+!FileDirectory class methodsFor:'private'!
+
+fullPathNameOf:name in:path
+ (name startsWith:OperatingSystem fileSeparator) ifTrue:[
+ ^ name
].
- (newFileName startsWith:'/') ifTrue:[
- path2 := newFileName
- ] ifFalse:[
- path2 := (pathName , '/' , newFileName)
- ].
- ^ OperatingSystem renameFile:path1 to:path2
+ ^ path , OperatingSystem fileSeparator asString , name
! !
!FileDirectory methodsFor:'queries'!
@@ -403,7 +382,11 @@
"return true if this directory exists"
^ OperatingSystem isDirectory:pathName
- "(FileDirectory directoryNamed:'fooBar') exists"
+
+ "
+ (FileDirectory directoryNamed:'fooBar') exists
+ (FileDirectory directoryNamed:'/tmp') exists
+ "
!
isEmpty
@@ -420,19 +403,13 @@
"return an array filled with file info for the file 'aFileName';
return nil if such a file does not exist"
- (name startsWith:'/') ifTrue:[
- ^ OperatingSystem infoOf:name
- ].
- ^ OperatingSystem infoOf:(pathName , '/' , name)
+ ^ OperatingSystem infoOf:(self class fullPathNameOf:name in:pathName)
!
timeOfLastChange:name
"return the timeStamp of a file in myself"
- (name startsWith:'/') ifTrue:[
- ^ OperatingSystem timeOfLastChange:name
- ].
- ^ OperatingSystem timeOfLastChange:(pathName , '/' , name)
+ ^ OperatingSystem timeOfLastChange:(self class fullPathNameOf:name in:pathName)
!
timeOfLastChange
@@ -441,78 +418,53 @@
^ OperatingSystem timeOfLastChange:pathName
!
-accessModeOf:aFileName
+accessModeOf:name
"return the access-mode bits (rwxrwxrwx) of a file in myself"
- (aFileName startsWith:'/') ifTrue:[
- ^ OperatingSystem accessModeOf:aFileName
- ].
- ^ OperatingSystem accessModeOf:(pathName , '/' , aFileName)
+ ^ OperatingSystem accessModeOf:(self class fullPathNameOf:name in:pathName)
!
-changeAccessModeOf:aFileName to:modeBits
+changeAccessModeOf:name to:modeBits
"set the access-mode bits (rwxrwxrwx) of a file in myself"
- (aFileName startsWith:'/') ifTrue:[
- ^ OperatingSystem changeAccessModeOf:aFileName
- to:modeBits
- ].
- ^ OperatingSystem changeAccessModeOf:(pathName , '/' , aFileName)
+ ^ OperatingSystem changeAccessModeOf:(self class fullPathNameOf:name in:pathName)
to:modeBits
!
-typeOf:aFileName
+typeOf:name
"return the symbolic type of a file in myself"
- (aFileName startsWith:'/') ifTrue:[
- ^ OperatingSystem typeOf:aFileName
- ].
- ^ OperatingSystem typeOf:(pathName , '/' , aFileName)
+ ^ OperatingSystem typeOf:(self class fullPathNameOf:name in:pathName)
!
exists:name
"return true, if the given name exists in myself"
- (name startsWith:'/') ifTrue:[
- ^ OperatingSystem isValidPath:name
- ].
- ^ OperatingSystem isValidPath:(pathName , '/' , name)
+ ^ OperatingSystem isValidPath:(self class fullPathNameOf:name in:pathName)
!
isDirectory:name
"return true, if the given name is that of a directory in myself"
- (name startsWith:'/') ifTrue:[
- ^ OperatingSystem isDirectory:name
- ].
- ^ OperatingSystem isDirectory:(pathName , '/' , name)
+ ^ OperatingSystem isDirectory:(self class fullPathNameOf:name in:pathName)
!
isReadable:name
"return true, if the given file is readable"
- (name startsWith:'/') ifTrue:[
- ^ OperatingSystem isReadable:name
- ].
- ^ OperatingSystem isReadable:(pathName , '/' , name)
+ ^ OperatingSystem isReadable:(self class fullPathNameOf:name in:pathName)
!
isWritable:name
"return true, if the given file is readable"
- (name startsWith:'/') ifTrue:[
- ^ OperatingSystem isWritable:name
- ].
- ^ OperatingSystem isWritable:(pathName , '/' , name)
+ ^ OperatingSystem isWritable:(self class fullPathNameOf:name in:pathName)
!
isExecutable:name
"return true, if the given file is executable"
- (name startsWith:'/') ifTrue:[
- ^ OperatingSystem isExecutable:name
- ].
- ^ OperatingSystem isExecutable:(pathName , '/' , name)
+ ^ OperatingSystem isExecutable:(self class fullPathNameOf:name in:pathName)
! !
!FileDirectory methodsFor:'printing & storing'!