FileDirectory.st
changeset 276 3b6d97620494
parent 202 40ca7cc6fb9c
child 308 f04744ef7b5d
--- a/FileDirectory.st	Tue Feb 21 02:07:07 1995 +0100
+++ b/FileDirectory.st	Wed Feb 22 02:14:51 1995 +0100
@@ -21,7 +21,7 @@
 COPYRIGHT (c) 1989 by Claus Gittinger
 	     All Rights Reserved
 
-$Header: /cvs/stx/stx/libbasic/FileDirectory.st,v 1.14 1994-11-17 14:17:28 claus Exp $
+$Header: /cvs/stx/stx/libbasic/FileDirectory.st,v 1.15 1995-02-22 01:13:17 claus Exp $
 '!
 
 !FileDirectory class methodsFor:'documentation'!
@@ -42,7 +42,7 @@
 
 version
 "
-$Header: /cvs/stx/stx/libbasic/FileDirectory.st,v 1.14 1994-11-17 14:17:28 claus Exp $
+$Header: /cvs/stx/stx/libbasic/FileDirectory.st,v 1.15 1995-02-22 01:13:17 claus Exp $
 "
 !
 
@@ -59,6 +59,7 @@
 	ST-80 provides a Filename class.
 	Therefore, Filename will take over much of the functionality in the near 
 	future.
+
 	Use instances of Filename if possible.
 "
 ! !
@@ -67,10 +68,16 @@
 
 initialize
     super initialize.
+    "/
+    "/ want to know about image restart
+    "/
     ObjectMemory addDependent:self
 !
 
 update:something
+    "/
+    "/ currentDirectory may be different when restarted
+    "/
     something == #restarted ifTrue:[
 	PathOfCurrentDirectory := nil
     ]
@@ -78,10 +85,22 @@
 
 !FileDirectory class methodsFor:'instance creation'!
 
+directoryNamed:name
+    "create and return a new FileDirectory for the directory
+     with given pathname"
+
+    ^ (self basicNew) pathName:name
+
+    "
+     (FileDirectory directoryNamed:'..') pathName
+     (FileDirectory directoryNamed:'../..') files
+    "
+!
+
 rootDirectory
     "create and return a new FileDirectory for the root directory"
 
-    ^ (self basicNew) pathName:(OperatingSystem fileSeparator asString)
+    ^ self directoryNamed:(OperatingSystem fileSeparator asString)
 
     "
      FileDirectory rootDirectory contents
@@ -93,7 +112,7 @@
 currentDirectory
     "create and return a new FileDirectory for the current directory"
 
-    ^ (self basicNew) pathName:'.'
+    ^ self directoryNamed:'.'
 
     "
      FileDirectory currentDirectory contents
@@ -103,18 +122,6 @@
     "
 !
 
-directoryNamed:name
-    "create and return a new FileDirectory for the directory
-     with given pathname"
-
-    ^ (self basicNew) pathName:name
-
-    "
-     (FileDirectory directoryNamed:'..') pathName
-     (FileDirectory directoryNamed:'../..') files
-    "
-!
-
 directoryNamed:name in:aFileDirectory
     "create and return a new FileDirectory for the directory with given name
      in another FileDirectory"
@@ -142,7 +149,19 @@
 	    baseName := baseName copyWith:sep
 	]
     ].
-    ^ (self basicNew) pathName:(baseName , name)
+    ^ self directoryNamed:(baseName , name)
+! !
+
+!FileDirectory class methodsFor:'private'!
+
+fullPathNameOf:name in:path
+    |sep|
+
+    sep := OperatingSystem fileSeparator asString.
+    (name startsWith:sep) ifTrue:[
+	^ name
+    ].
+    ^ path , sep , name
 ! !
 
 !FileDirectory methodsFor:'accessing'!
@@ -196,9 +215,7 @@
     self do:[:name |
 	coll add:name
     ].
-    (coll size ~~ 0) ifTrue:[
-	coll sort
-    ].
+    coll sort.
     ^ coll
 !
 
@@ -211,9 +228,7 @@
     self directoriesDo:[:name |
 	coll add:name
     ].
-    (coll size ~~ 0) ifTrue:[
-	coll sort
-    ].
+    coll sort.
     ^ coll
 !
 
@@ -226,7 +241,8 @@
     self filesDo:[:name |
 	coll add:name
     ].
-    ^ coll sort
+    coll sort.
+    ^ coll
 ! !
 
 !FileDirectory methodsFor:'converting'!
@@ -240,7 +256,7 @@
 asFilename:someFile
     "return a filename for a file named someFile in myself"
 
-    ^ self pathName asFilename construct:someFile
+    ^ self asFilename construct:someFile
 ! !
 
 !FileDirectory methodsFor:'private'!
@@ -311,6 +327,10 @@
     (shortPathName = '.') ifTrue:[
 	PathOfCurrentDirectory := fullPathName
     ]
+!
+
+pathNameOf:fileName
+    ^ self class fullPathNameOf:fileName in:pathName
 ! !
 
 !FileDirectory methodsFor:'basic'!
@@ -328,7 +348,7 @@
 	    ] ifFalse:[
 		realName := newName
 	    ].
-	    ^ OperatingSystem createDirectory:(self class fullPathNameOf:realName in:pathName)
+	    ^ OperatingSystem createDirectory:(self pathNameOf:realName)
 	]
     ].
     ^ false
@@ -337,7 +357,7 @@
 removeFile:fileName
     "remove the file 'fileName' from myself; return true if successful"
 
-    ^ OperatingSystem removeFile:(self class fullPathNameOf:fileName in:pathName).
+    ^ OperatingSystem removeFile:(self pathNameOf:fileName).
 !
 
 removeDirectory:dirName
@@ -347,7 +367,7 @@
 
     |path|
 
-    path := self class fullPathNameOf:dirName in:pathName.
+    path := self pathNameOf:dirName.
     (OperatingSystem removeDirectory:path) ifTrue:[^ true].
     ^ OperatingSystem recursiveRemoveDirectory:path
 !
@@ -357,7 +377,7 @@
 
     |path|
 
-    path := self class fullPathNameOf:aFileOrDirectoryName in:pathName.
+    path := self pathNameOf:aFileOrDirectoryName.
     (OperatingSystem isDirectory:path) ifTrue:[
 	^ OperatingSystem removeDirectory:path
     ].
@@ -369,8 +389,8 @@
 
     |path1 path2|
 
-    path1 := self class fullPathNameOf:oldFileName in:pathName.
-    path2 := self class fullPathNameOf:newFileName in:pathName.
+    path1 := self pathNameOf:oldFileName.
+    path2 := self pathNameOf:newFileName.
     ^ OperatingSystem linkFile:path1 to:path2
 !
 
@@ -379,20 +399,11 @@
 
     |path1 path2|
 
-    path1 := self class fullPathNameOf:oldFileName in:pathName.
-    path2 := self class fullPathNameOf:newFileName in:pathName.
+    path1 := self pathNameOf:oldFileName.
+    path2 := self pathNameOf:newFileName.
     ^ OperatingSystem renameFile:path1 to:path2
 ! !
 
-!FileDirectory class methodsFor:'private'!
-
-fullPathNameOf:name in:path
-    (name startsWith:OperatingSystem fileSeparator) ifTrue:[
-	^ name
-    ].
-    ^ path , OperatingSystem fileSeparator asString , name
-! !
-
 !FileDirectory methodsFor:'queries'!
 
 id
@@ -426,13 +437,13 @@
     "return an array filled with file info for the file 'aFileName';
      return nil if such a file does not exist"
 
-    ^ OperatingSystem infoOf:(self class fullPathNameOf:name in:pathName)
+    ^ OperatingSystem infoOf:(self pathNameOf:name)
 !
 
 timeOfLastChange:name
     "return the timeStamp of a file in myself"
 
-    ^ OperatingSystem timeOfLastChange:(self class fullPathNameOf:name in:pathName)
+    ^ OperatingSystem timeOfLastChange:(self pathNameOf:name)
 !
 
 timeOfLastChange
@@ -444,50 +455,49 @@
 accessModeOf:name
     "return the access-mode bits (rwxrwxrwx) of a file in myself"
 
-    ^ OperatingSystem accessModeOf:(self class fullPathNameOf:name in:pathName)
+    ^ OperatingSystem accessModeOf:(self pathNameOf:name)
 !
 
 changeAccessModeOf:name to:modeBits
     "set the access-mode bits (rwxrwxrwx) of a file in myself"
 
-    ^ OperatingSystem changeAccessModeOf:(self class fullPathNameOf:name in:pathName)
-				      to:modeBits
+    ^ OperatingSystem changeAccessModeOf:(self pathNameOf:name) to:modeBits
 !
 
 typeOf:name
     "return the symbolic type of a file in myself"
 
-    ^ OperatingSystem typeOf:(self class fullPathNameOf:name in:pathName)
+    ^ OperatingSystem typeOf:(self pathNameOf:name)
 !
 
 exists:name
     "return true, if the given name exists in myself"
 
-    ^ OperatingSystem isValidPath:(self class fullPathNameOf:name in:pathName)
+    ^ OperatingSystem isValidPath:(self pathNameOf:name)
 !
 
 isDirectory:name
     "return true, if the given name is that of a directory in myself"
 
-    ^ OperatingSystem isDirectory:(self class fullPathNameOf:name in:pathName)
+    ^ OperatingSystem isDirectory:(self pathNameOf:name)
 !
 
 isReadable:name
     "return true, if the given file is readable"
 
-    ^ OperatingSystem isReadable:(self class fullPathNameOf:name in:pathName)
+    ^ OperatingSystem isReadable:(self pathNameOf:name)
 !
 
 isWritable:name
     "return true, if the given file is readable"
 
-    ^ OperatingSystem isWritable:(self class fullPathNameOf:name in:pathName)
+    ^ OperatingSystem isWritable:(self pathNameOf:name)
 !
 
 isExecutable:name
     "return true, if the given file is executable"
 
-    ^ OperatingSystem isExecutable:(self class fullPathNameOf:name in:pathName)
+    ^ OperatingSystem isExecutable:(self pathNameOf:name)
 ! !
 
 !FileDirectory methodsFor:'printing & storing'!