help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] Including files


From: J Pfersich
Subject: Re: [Help-smalltalk] Including files
Date: Sun, 10 Sep 2006 14:09:35 -0600

It's pretty close to what I've done, I just never got around to creating the diffs. I have more touch methods. And my touch methods don't raise an exception when the file doesn't exist.

st> File touch: 'banbang.txt' !
Object: File error: No such file or directory
File class(Object)>>#primError:
SystemExceptions.FileError(Exception)>>#defaultAction
optimized [] in Exception class>>#coreException
SystemExceptions.FileError(Signal)>>#activateHandler:
SystemExceptions.FileError(Exception)>>#signal
SystemExceptions.FileError class(Exception class)>>#signal:
File class>>#checkError:
File class>>#checkError
VFS.RealFileHandler>>#lastAccessTime:lastModifyTime:
File>>#lastAccessTime:lastModifyTime:
File>>#touch
File class>>#touch:
UndefinedObject>>#executeStatements
nil
st>


The touch utility creates the file unless you specify nocreate.

It's not that hard to create primitives, is it?

BTW, when is a new tarball going to be created? Will it be 2.3 or 2.2.1?

At 09:42 AM 9/8/2006 +0200, Paolo Bonzini wrote:

man utime says it's POSIX. I'd be in favour of adding #utime and
removing #touch if anyone cared to do the work ;)
Like this? I will commit this as soon as you confirm it's what you could have done.
Like this I meant.

Paolo


--- orig/kernel/File.st
+++ mod/kernel/File.st
@@ -251,6 +251,18 @@ size
     ^vfsHandler size
 !

+lastAccessTime: aDateTime
+    "Update the last access time of the file corresponding to the receiver,
+     to be aDateTime."
+    vfsHandler lastAccessTime: aDateTime lastModifyTime: self lastModifyTime
+!
+
+lastAccessTime: accessDateTime lastModifyTime: modifyDateTime
+    "Update the timestamps of the file corresponding to the receiver, to be
+     accessDateTime and modifyDateTime."
+    vfsHandler lastAccessTime: accessDateTime lastModifyTime: modifyDateTime
+!
+
 lastAccessTime
     "Answer the last access time of the file identified by the receiver"
     ^vfsHandler lastAccessTime
@@ -272,6 +284,12 @@ creationTime
     ^vfsHandler creationTime
 !

+lastModifyTime: aDateTime
+    "Update the last modification timestamp of the file corresponding to the
+     receiver, to be aDateTime."
+    vfsHandler lastAccessTime: self lastAccessTime lastModifyTime: aDateTime
+!
+
 lastModifyTime
     "Answer the last modify time of the file identified by the receiver
     (the `last modify time' has to do with the actual file contents)."
@@ -381,8 +399,10 @@ contents
 !

 touch
-    "Update the timestamp of the file with the given path name."
-    (self openDescriptor: FileStream append) close
+    "Update the timestamp of the file corresponding to the receiver."
+    | now |
+    now := DateTime now.
+    self lastAccessTime: now lastModifyTime: now
 !

 open: mode


--- orig/kernel/VFS.st
+++ mod/kernel/VFS.st
@@ -168,6 +168,9 @@ rewindDir: dirObject

 !RealFileHandler class methodsFor: 'C call-outs'!

+setTimeFor: file atime: atimeSeconds mtime: mtimeSeconds
+    <cCall: 'utime' returning: #int args: #(#string #long #long)>!
+
 working
     <cCall: 'getCurDirName' returning: #stringOut args: #()>! !

@@ -357,6 +360,12 @@ isAccessible

 !VFSHandler methodsFor: 'file operations'!

+lastAccessTime: accessDateTime lastModifyTime: modifyDateTime
+    "Set the receiver's timestamps to be accessDateTime and modifyDateTime.
+     If your file system does not support distinct access and modification
+     times, you should discard accessDateTime."
+    self subclassResponsibility!
+
 open: class mode: mode ifFail: aBlock
     "Open the receiver in the given mode (as answered by FileStream's
     class constant methods)"
@@ -518,6 +527,14 @@ isExecutable

 !RealFileHandler methodsFor: 'file operations'!

+lastAccessTime: accessDateTime lastModifyTime: modifyDateTime
+    "Set the receiver's timestamps to be accessDateTime and modifyDateTime."
+    self class
+       setTimeFor: self realFileName
+       atime: (self secondsFromDateTime: accessDateTime)
+       mtime: (self secondsFromDateTime: modifyDateTime).
+    File checkError!
+
 open: class mode: mode ifFail: aBlock
     "Open the receiver in the given mode (as answered by FileStream's
     class constant methods)"
@@ -541,9 +558,16 @@ renameTo: newFileName

 !RealFileHandler methodsFor: 'private'!

-getDateAndTime: time
+secondsFromDateTime: aDateTime
     "Private - Convert a time expressed in seconds from 1/1/2000 to
      an array of two Smalltalk Date and Time objects"
+    ^(aDateTime asSeconds - Epoch asSeconds)
+       - (aDateTime offset asSeconds - Epoch offset asSeconds)
+!
+
+getDateAndTime: time
+    "Private - Convert a time expressed in seconds from 1/1/2000 to
+     a Smalltalk DateTime object."

     ^(Epoch + (Duration seconds: time))
        offset: (Duration seconds: Time timezoneBias)


--- orig/libgst/cint.c
+++ mod/libgst/cint.c
@@ -200,6 +200,9 @@ static OOP classify_type_symbol (OOP sym
 static int get_errno (void);

 /* Encapsulate binary incompatibilities between various C libraries.  */
+static int my_utime (const char *name,
+                    long new_atime,
+                    long new_mtime);
 static int my_stat (const char *name,
                    gst_stat * out);
 static int my_lstat (const char *name,
@@ -306,6 +309,22 @@ get_errno (void)
 }

 int
+my_utime (const char *name,
+         long new_atime,
+         long new_mtime)
+{
+  struct timeval times[2];
+  int result;
+  times[0].tv_sec = new_atime + 86400 * 10957;
+  times[1].tv_sec = new_mtime + 86400 * 10957;
+  times[0].tv_usec = times[1].tv_usec = 0;
+  result = utimes (name, times);
+  if (!result)
+    errno = 0;
+  return (result);
+}
+
+int
 my_stat (const char *name,
        gst_stat * out)
 {
@@ -497,6 +516,7 @@ _gst_init_cfuncs (void)
   _gst_define_cfunc ("strerror", strerror);
   _gst_define_cfunc ("stat", my_stat);
   _gst_define_cfunc ("lstat", my_lstat);
+  _gst_define_cfunc ("utime", my_utime);

   _gst_define_cfunc ("opendir", my_opendir);
   _gst_define_cfunc ("closedir", closedir);



_______________________________________________
help-smalltalk mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/help-smalltalk





reply via email to

[Prev in Thread] Current Thread [Next in Thread]