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 <yury@shurup.com>
This commit is contained in:
Yury V. Zaytsev 2024-05-31 20:06:36 +02:00
parent dbca937c55
commit 191108766f
4 changed files with 22 additions and 15 deletions

View File

@ -38,6 +38,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#if !defined (HAVE_UTIMENSAT) && defined (HAVE_UTIME_H)
#include <utime.h>
#endif
#include "lib/global.h" #include "lib/global.h"
#include "lib/unixcompat.h" #include "lib/unixcompat.h"
#include "lib/widget.h" /* message() */ #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
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -60,5 +60,8 @@ size_t vfs_parse_ls_lga_get_final_spaces (void);
gboolean vfs_parse_month (const char *str, struct tm *tim); gboolean vfs_parse_month (const char *str, struct tm *tim);
int vfs_parse_filedate (int idx, time_t * t); int vfs_parse_filedate (int idx, time_t * t);
int vfs_utime (const char *path, mc_timesbuf_t *times);
/*** inline functions ****************************************************************************/ /*** inline functions ****************************************************************************/
#endif #endif

View File

@ -26,6 +26,7 @@
*/ */
#include <config.h> #include <config.h>
#include <errno.h> #include <errno.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
@ -217,16 +218,7 @@ local_fsetflags (const vfs_path_t *vpath, unsigned long flags)
static int static int
local_utime (const vfs_path_t *vpath, mc_timesbuf_t *times) local_utime (const vfs_path_t *vpath, mc_timesbuf_t *times)
{ {
int ret; return vfs_utime (vfs_path_get_last_path_str (vpath), times);
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;
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */

View File

@ -349,11 +349,7 @@ sfs_chown (const vfs_path_t *vpath, uid_t owner, gid_t group)
static int static int
sfs_utime (const vfs_path_t *vpath, mc_timesbuf_t *times) sfs_utime (const vfs_path_t *vpath, mc_timesbuf_t *times)
{ {
#ifdef HAVE_UTIMENSAT return vfs_utime (sfs_redirect (vpath), times);
return utimensat (AT_FDCWD, sfs_redirect (vpath), *times, 0);
#else
return utime (sfs_redirect (vpath), times);
#endif
} }
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */