pvfs: use utimes() instead of utime() to get better timestamp resolution
authorStefan Metzmacher <metze@samba.org>
Tue, 3 Jun 2008 11:32:04 +0000 (13:32 +0200)
committerStefan Metzmacher <metze@samba.org>
Tue, 3 Jun 2008 12:05:04 +0000 (14:05 +0200)
Note: that libreplace always provides utimes()

metze
(This used to be commit 61bad69e2d7f84e2c6d6fb82917cfa86b17f54b0)

source4/ntvfs/posix/pvfs_open.c
source4/ntvfs/posix/pvfs_setfileinfo.c

index a78d0a79c7dbd878d9c31317c5a237b1af607649..43203086f8711de7859cad828aa2388c6f81e7eb 100644 (file)
@@ -525,14 +525,14 @@ static int pvfs_handle_destructor(struct pvfs_file_handle *h)
        }
 
        if (h->write_time.update_on_close) {
-               struct utimbuf unix_times;
+               struct timeval tv[2];
 
-               unix_times.actime  = nt_time_to_unix(h->name->dos.access_time);
-               unix_times.modtime = nt_time_to_unix(h->write_time.close_time);
+               nttime_to_timeval(&tv[0], h->name->dos.access_time);
+               nttime_to_timeval(&tv[1], h->write_time.close_time);
 
-               if (unix_times.actime != 0 || unix_times.modtime != 0) {
-                       if (utime(h->name->full_name, &unix_times) == -1) {
-                               DEBUG(0,("pvfs_close: utime() failed '%s' - %s\n",
+               if (!timeval_is_zero(&tv[0]) || !timeval_is_zero(&tv[1])) {
+                       if (utimes(h->name->full_name, tv) == -1) {
+                               DEBUG(0,("pvfs_handle_destructor: utimes() failed '%s' - %s\n",
                                         h->name->full_name, strerror(errno)));
                        }
                }
index b0f636f99915e507d41668e14743a4b2bcf3a413..2cde5f42aae3172a3c707c3dd4e0f95c93973ee4 100644 (file)
@@ -273,7 +273,6 @@ NTSTATUS pvfs_setfileinfo(struct ntvfs_module_context *ntvfs,
                          union smb_setfileinfo *info)
 {
        struct pvfs_state *pvfs = ntvfs->private_data;
-       struct utimbuf unix_times;
        struct pvfs_file *f;
        struct pvfs_file_handle *h;
        struct pvfs_filename newstats;
@@ -437,21 +436,28 @@ NTSTATUS pvfs_setfileinfo(struct ntvfs_module_context *ntvfs,
        }
 
        /* possibly change the file timestamps */
-       ZERO_STRUCT(unix_times);
        if (newstats.dos.create_time != h->name->dos.create_time) {
                change_mask |= FILE_NOTIFY_CHANGE_CREATION;
        }
        if (newstats.dos.access_time != h->name->dos.access_time) {
-               unix_times.actime = nt_time_to_unix(newstats.dos.access_time);
                change_mask |= FILE_NOTIFY_CHANGE_LAST_ACCESS;
        }
        if (newstats.dos.write_time != h->name->dos.write_time) {
-               unix_times.modtime = nt_time_to_unix(newstats.dos.write_time);
                change_mask |= FILE_NOTIFY_CHANGE_LAST_WRITE;
        }
-       if (unix_times.actime != 0 || unix_times.modtime != 0) {
-               if (utime(h->name->full_name, &unix_times) == -1) {
-                       return pvfs_map_errno(pvfs, errno);
+       if ((change_mask & FILE_NOTIFY_CHANGE_LAST_ACCESS) ||
+           (change_mask & FILE_NOTIFY_CHANGE_LAST_WRITE)) {
+               struct timeval tv[2];
+
+               nttime_to_timeval(&tv[0], newstats.dos.access_time);
+               nttime_to_timeval(&tv[1], newstats.dos.write_time);
+
+               if (!timeval_is_zero(&tv[0]) || !timeval_is_zero(&tv[1])) {
+                       if (utimes(h->name->full_name, tv) == -1) {
+                               DEBUG(0,("pvfs_setfileinfo: utimes() failed '%s' - %s\n",
+                                        h->name->full_name, strerror(errno)));
+                               return pvfs_map_errno(pvfs, errno);
+                       }
                }
        }
        if (change_mask & FILE_NOTIFY_CHANGE_LAST_WRITE) {
@@ -594,7 +600,6 @@ NTSTATUS pvfs_setpathinfo(struct ntvfs_module_context *ntvfs,
        struct pvfs_filename *name;
        struct pvfs_filename newstats;
        NTSTATUS status;
-       struct utimbuf unix_times;
        uint32_t access_needed;
        uint32_t change_mask = 0;
        struct odb_lock *lck = NULL;
@@ -760,21 +765,28 @@ NTSTATUS pvfs_setpathinfo(struct ntvfs_module_context *ntvfs,
        }
 
        /* possibly change the file timestamps */
-       ZERO_STRUCT(unix_times);
        if (newstats.dos.create_time != name->dos.create_time) {
                change_mask |= FILE_NOTIFY_CHANGE_CREATION;
        }
        if (newstats.dos.access_time != name->dos.access_time) {
-               unix_times.actime = nt_time_to_unix(newstats.dos.access_time);
                change_mask |= FILE_NOTIFY_CHANGE_LAST_ACCESS;
        }
        if (newstats.dos.write_time != name->dos.write_time) {
-               unix_times.modtime = nt_time_to_unix(newstats.dos.write_time);
                change_mask |= FILE_NOTIFY_CHANGE_LAST_WRITE;
        }
-       if (unix_times.actime != 0 || unix_times.modtime != 0) {
-               if (utime(name->full_name, &unix_times) == -1) {
-                       return pvfs_map_errno(pvfs, errno);
+       if ((change_mask & FILE_NOTIFY_CHANGE_LAST_ACCESS) ||
+           (change_mask & FILE_NOTIFY_CHANGE_LAST_WRITE)) {
+               struct timeval tv[2];
+
+               nttime_to_timeval(&tv[0], newstats.dos.access_time);
+               nttime_to_timeval(&tv[1], newstats.dos.write_time);
+
+               if (!timeval_is_zero(&tv[0]) || !timeval_is_zero(&tv[1])) {
+                       if (utimes(name->full_name, tv) == -1) {
+                               DEBUG(0,("pvfs_setpathinfo: utimes() failed '%s' - %s\n",
+                                        name->full_name, strerror(errno)));
+                               return pvfs_map_errno(pvfs, errno);
+                       }
                }
        }
        if (change_mask & FILE_NOTIFY_CHANGE_LAST_WRITE) {