updated: [master] [1911087] Ticket #4542: fix support of timestamps with nanosecond precision on macOS

0 views
Skip to first unread message

Yury V. Zaytsev

unread,
Jul 28, 2024, 4:01:33 AMJul 28
to mc-co...@googlegroups.com
The following commit has been merged in the master branch:
commit 191108766f2363338ad718301d0f83db4fef51bb
Author: Yury V. Zaytsev <yu...@shurup.com>
Date: Fri May 31 20:06:36 2024 +0200

Ticket #4542: fix support of timestamps with nanosecond precision on macOS

utilvfs: isolate utime / utimensat calls in a helper function

Signed-off-by: Yury V. Zaytsev <yu...@shurup.com>

diff --git a/lib/vfs/utilvfs.c b/lib/vfs/utilvfs.c
index 5a9fa45..8f4e05c 100644
--- a/lib/vfs/utilvfs.c
+++ b/lib/vfs/utilvfs.c
@@ -38,6 +38,10 @@
#include <stdlib.h>
#include <string.h>

+#if !defined (HAVE_UTIMENSAT) && defined (HAVE_UTIME_H)
+#include <utime.h>
+#endif
+
#include "lib/global.h"
#include "lib/unixcompat.h"
#include "lib/widget.h" /* message() */
@@ -372,3 +376,15 @@ vfs_get_password (const char *msg)
}

/* --------------------------------------------------------------------------------------------- */
+
+int
+vfs_utime (const char *path, mc_timesbuf_t *times)
+{
+#ifdef HAVE_UTIMENSAT
+ return utimensat (AT_FDCWD, path, *times, AT_SYMLINK_NOFOLLOW);
+#else
+ return utime (path, times);
+#endif
+}
+
+/* --------------------------------------------------------------------------------------------- */
diff --git a/lib/vfs/utilvfs.h b/lib/vfs/utilvfs.h
index 362bd55..a203b78 100644
--- a/lib/vfs/utilvfs.h
+++ b/lib/vfs/utilvfs.h
@@ -60,5 +60,8 @@ size_t vfs_parse_ls_lga_get_final_spaces (void);
gboolean vfs_parse_month (const char *str, struct tm *tim);
int vfs_parse_filedate (int idx, time_t * t);

+int vfs_utime (const char *path, mc_timesbuf_t *times);
+
/*** inline functions ****************************************************************************/
+
#endif
diff --git a/src/vfs/local/local.c b/src/vfs/local/local.c
index 88450a5..3376465 100644
--- a/src/vfs/local/local.c
+++ b/src/vfs/local/local.c
@@ -26,6 +26,7 @@
*/

#include <config.h>
+
#include <errno.h>
#include <sys/types.h>
#include <unistd.h>
@@ -217,16 +218,7 @@ local_fsetflags (const vfs_path_t *vpath, unsigned long flags)
static int
local_utime (const vfs_path_t *vpath, mc_timesbuf_t *times)
{
- int ret;
- const char *path;
-
- path = vfs_path_get_last_path_str (vpath);
-#ifdef HAVE_UTIMENSAT
- ret = utimensat (AT_FDCWD, path, *times, AT_SYMLINK_NOFOLLOW);
-#else
- ret = utime (path, times);
-#endif
- return ret;
+ return vfs_utime (vfs_path_get_last_path_str (vpath), times);
}

/* --------------------------------------------------------------------------------------------- */
diff --git a/src/vfs/sfs/sfs.c b/src/vfs/sfs/sfs.c
index c7107f5..e3be15f 100644
--- a/src/vfs/sfs/sfs.c
+++ b/src/vfs/sfs/sfs.c
@@ -349,11 +349,7 @@ sfs_chown (const vfs_path_t *vpath, uid_t owner, gid_t group)
static int
sfs_utime (const vfs_path_t *vpath, mc_timesbuf_t *times)
{
-#ifdef HAVE_UTIMENSAT
- return utimensat (AT_FDCWD, sfs_redirect (vpath), *times, 0);
-#else
- return utime (sfs_redirect (vpath), times);
-#endif
+ return vfs_utime (sfs_redirect (vpath), times);
}

/* --------------------------------------------------------------------------------------------- */

--
Midnight Commander Development
Reply all
Reply to author
Forward
0 new messages