Browse Source

Zero struct stat tv_nsec (if supported) whenever st is filled manually

Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
Yury V. Zaytsev 7 years ago
parent
commit
f0414be51d

+ 4 - 0
lib/vfs/direntry.c

@@ -976,7 +976,11 @@ vfs_s_default_stat (struct vfs_class *me, mode_t mode)
     st.st_blksize = 512;
 #endif
     st.st_size = 0;
+
     st.st_mtime = st.st_atime = st.st_ctime = time (NULL);
+#ifdef HAVE_STRUCT_STAT_ST_MTIM
+    st.st_atim.tv_nsec = st.st_mtim.tv_nsec = st.st_ctim.tv_nsec = 0;
+#endif
 
     vfs_adjust_stat (&st);
 

+ 4 - 0
lib/vfs/parse_ls_vga.c

@@ -809,6 +809,10 @@ vfs_parse_ls_lga (const char *p, struct stat * s, char **filename, char **linkna
         goto error;
     /* Use resulting time value */
     s->st_atime = s->st_ctime = s->st_mtime;
+#ifdef HAVE_STRUCT_STAT_ST_MTIM
+    s->st_atim.tv_nsec = s->st_mtim.tv_nsec = s->st_ctim.tv_nsec = 0;
+#endif
+
     /* s->st_dev and s->st_ino must be initialized by vfs_s_new_inode () */
 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
     s->st_blksize = 512;

+ 3 - 0
src/vfs/extfs/extfs.c

@@ -1099,6 +1099,9 @@ extfs_stat_move (struct stat *buf, const struct inode *inode)
     buf->st_atime = inode->atime;
     buf->st_mtime = inode->mtime;
     buf->st_ctime = inode->ctime;
+#ifdef HAVE_STRUCT_STAT_ST_MTIM
+    buf->st_atim.tv_nsec = buf->st_mtim.tv_nsec = buf->st_ctim.tv_nsec = 0;
+#endif
 }
 
 /* --------------------------------------------------------------------------------------------- */

+ 6 - 0
src/vfs/fish/fish.c

@@ -834,6 +834,9 @@ fish_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
                 if (vfs_parse_filedate (0, &ST.st_ctime) == 0)
                     break;
                 ST.st_atime = ST.st_mtime = ST.st_ctime;
+#ifdef HAVE_STRUCT_STAT_ST_MTIM
+                ST.st_atim.tv_nsec = ST.st_mtim.tv_nsec = ST.st_ctim.tv_nsec = 0;
+#endif
             }
             break;
         case 'D':
@@ -845,6 +848,9 @@ fish_dir_load (struct vfs_class *me, struct vfs_s_inode *dir, char *remote_path)
                             &tim.tm_mday, &tim.tm_hour, &tim.tm_min, &tim.tm_sec) != 6)
                     break;
                 ST.st_atime = ST.st_mtime = ST.st_ctime = mktime (&tim);
+#ifdef HAVE_STRUCT_STAT_ST_MTIM
+                ST.st_atim.tv_nsec = ST.st_mtim.tv_nsec = ST.st_ctim.tv_nsec = 0;
+#endif
             }
             break;
         case 'E':

+ 4 - 0
src/vfs/sftpfs/file.c

@@ -230,6 +230,10 @@ sftpfs_fstat (void *data, struct stat *buf, GError ** mcerror)
         buf->st_atime = attrs.atime;
         buf->st_mtime = attrs.mtime;
         buf->st_ctime = attrs.mtime;
+#ifdef HAVE_STRUCT_STAT_ST_MTIM
+        buf->st_atim.tv_nsec = buf->st_mtim.tv_nsec = buf->st_ctim.tv_nsec = 0;
+#endif
+
     }
 
     if ((attrs.flags & LIBSSH2_SFTP_ATTR_SIZE) != 0)

+ 6 - 0
src/vfs/sftpfs/internal.c

@@ -203,6 +203,9 @@ sftpfs_lstat (const vfs_path_t * vpath, struct stat *buf, GError ** mcerror)
         buf->st_atime = attrs.atime;
         buf->st_mtime = attrs.mtime;
         buf->st_ctime = attrs.mtime;
+#ifdef HAVE_STRUCT_STAT_ST_MTIM
+        buf->st_atim.tv_nsec = buf->st_mtim.tv_nsec = buf->st_ctim.tv_nsec = 0;
+#endif
     }
 
     if ((attrs.flags & LIBSSH2_SFTP_ATTR_SIZE) != 0)
@@ -286,6 +289,9 @@ sftpfs_stat (const vfs_path_t * vpath, struct stat *buf, GError ** mcerror)
         buf->st_atime = attrs.atime;
         buf->st_mtime = attrs.mtime;
         buf->st_ctime = attrs.mtime;
+#ifdef HAVE_STRUCT_STAT_ST_MTIM
+        buf->st_atim.tv_nsec = buf->st_mtim.tv_nsec = buf->st_ctim.tv_nsec = 0;
+#endif
     }
 
     if ((attrs.flags & LIBSSH2_SFTP_ATTR_SIZE) != 0)

+ 3 - 0
src/vfs/undelfs/undelfs.c

@@ -634,6 +634,9 @@ undelfs_stat_int (int inode_index, struct stat *buf)
     buf->st_atime = delarray[inode_index].dtime;
     buf->st_ctime = delarray[inode_index].dtime;
     buf->st_mtime = delarray[inode_index].dtime;
+#ifdef HAVE_STRUCT_STAT_ST_MTIM
+    buf->st_atim.tv_nsec = buf->st_mtim.tv_nsec = buf->st_ctim.tv_nsec = 0;
+#endif
     return 0;
 }
 

+ 12 - 0
tests/lib/vfs/vfs_parse_ls_lga.c

@@ -110,6 +110,11 @@ message (int flags, const char *title, const char *text, ...)
 static void
 fill_stat_struct (struct stat *etalon_stat, int iterator)
 {
+
+#ifdef HAVE_STRUCT_STAT_ST_MTIM
+    etalon_stat->st_atim.tv_nsec = etalon_stat->st_mtim.tv_nsec = etalon_stat->st_ctim.tv_nsec = 0;
+#endif
+
     switch (iterator)
     {
     case 0:
@@ -299,6 +304,13 @@ START_PARAMETRIZED_TEST (test_vfs_parse_ls_lga, test_vfs_parse_ls_lga_ds)
        mctest_assert_int_eq (etalon_stat.st_mtime, test_stat.st_mtime);
        mctest_assert_int_eq (etalon_stat.st_ctime, test_stat.st_ctime);
      */
+
+#ifdef HAVE_STRUCT_STAT_ST_MTIM
+    mctest_assert_int_eq (0, test_stat.st_atim.tv_nsec);
+    mctest_assert_int_eq (0, test_stat.st_mtim.tv_nsec);
+    mctest_assert_int_eq (0, test_stat.st_ctim.tv_nsec);
+#endif
+
 }
 /* *INDENT-OFF* */
 END_PARAMETRIZED_TEST