help-smalltalk
[Top][All Lists]
Advanced

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

Re: [Help-smalltalk] Including files


From: Paolo Bonzini
Subject: Re: [Help-smalltalk] Including files
Date: Fri, 08 Sep 2006 09:42:33 +0200
User-agent: Thunderbird 1.5.0.5 (Macintosh/20060719)

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);




reply via email to

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