Browse Source

utilvfs: concentrate timesbuf handling in one place

Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
Yury V. Zaytsev 9 months ago
parent
commit
c8e8f01faf
3 changed files with 19 additions and 17 deletions
  1. 14 0
      lib/vfs/utilvfs.c
  2. 1 0
      lib/vfs/utilvfs.h
  3. 4 17
      src/filemanager/file.c

+ 14 - 0
lib/vfs/utilvfs.c

@@ -406,3 +406,17 @@ vfs_get_timespecs_from_timesbuf (mc_timesbuf_t *times, mc_timespec_t *atime, mc_
 }
 
 /* --------------------------------------------------------------------------------------------- */
+
+void
+vfs_get_timesbuf_from_stat (const struct stat *sb, mc_timesbuf_t *times)
+{
+#ifdef HAVE_UTIMENSAT
+    (*times)[0] = sb->st_atim;
+    (*times)[1] = sb->st_mtim;
+#else
+    times->actime = sb->st_atime;
+    times->modtime = sb->st_mtime;
+#endif
+}
+
+/* --------------------------------------------------------------------------------------------- */

+ 1 - 0
lib/vfs/utilvfs.h

@@ -63,6 +63,7 @@ int vfs_parse_filedate (int idx, time_t * t);
 int vfs_utime (const char *path, mc_timesbuf_t *times);
 void vfs_get_timespecs_from_timesbuf (mc_timesbuf_t *times, mc_timespec_t *atime,
                                       mc_timespec_t *mtime);
+void vfs_get_timesbuf_from_stat (const struct stat *sb, mc_timesbuf_t *times);
 
 /*** inline functions ****************************************************************************/
 

+ 4 - 17
src/filemanager/file.c

@@ -67,6 +67,7 @@
 #include "lib/strutil.h"
 #include "lib/util.h"
 #include "lib/vfs/vfs.h"
+#include "lib/vfs/utilvfs.h"
 #include "lib/widget.h"
 
 #include "src/setup.h"
@@ -927,20 +928,6 @@ check_same_file (const char *a, const struct stat *ast, const char *b, const str
     return TRUE;
 }
 
-/* --------------------------------------------------------------------------------------------- */
-
-static void
-get_times (const struct stat *sb, mc_timesbuf_t *times)
-{
-#ifdef HAVE_UTIMENSAT
-    (*times)[0] = sb->st_atim;
-    (*times)[1] = sb->st_mtim;
-#else
-    times->actime = sb->st_atime;
-    times->modtime = sb->st_mtime;
-#endif
-}
-
 /* --------------------------------------------------------------------------------------------- */
 /* {{{ Query/status report routines */
 
@@ -1297,7 +1284,7 @@ move_file_file (const WPanel *panel, file_op_total_context_t *tctx, file_op_cont
                 {
                     mc_timesbuf_t times;
 
-                    get_times (&src_stat, &times);
+                    vfs_get_timesbuf_from_stat (&src_stat, &times);
                     mc_utime (dst_vpath, &times);
                 }
                 goto retry_src_remove;
@@ -2375,7 +2362,7 @@ copy_file_file (file_op_total_context_t *tctx, file_op_context_t *ctx,
         }
     }
 
-    get_times (&src_stat, &times);
+    vfs_get_timesbuf_from_stat (&src_stat, &times);
 
     if (!ctx->do_append)
     {
@@ -3232,7 +3219,7 @@ copy_dir_dir (file_op_total_context_t *tctx, file_op_context_t *ctx, const char
         if (attrs_ok)
             mc_fsetflags (dst_vpath, attrs);
 
-        get_times (&src_stat, &times);
+        vfs_get_timesbuf_from_stat (&src_stat, &times);
         mc_utime (dst_vpath, &times);
     }
     else