updated: [master] [77e5913] utilvfs: abstract mc_timesbuf_t handling with own mc_timespec_t type

1 view
Skip to first unread message

Yury V. Zaytsev

unread,
Jul 28, 2024, 4:01:39 AM7/28/24
to mc-co...@googlegroups.com
The following commit has been merged in the master branch:
commit 77e5913c0226b98799f86a53d4b3cb92642100d1
Author: Yury V. Zaytsev <yu...@shurup.com>
Date: Fri May 31 20:58:26 2024 +0200

utilvfs: abstract mc_timesbuf_t handling with own mc_timespec_t type

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

diff --git a/lib/vfs/utilvfs.c b/lib/vfs/utilvfs.c
index 8f4e05c..f9a8398 100644
--- a/lib/vfs/utilvfs.c
+++ b/lib/vfs/utilvfs.c
@@ -388,3 +388,21 @@ 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)
+{
+#ifdef HAVE_UTIMENSAT
+ atime->tv_sec = (*times)[0].tv_sec;
+ atime->tv_nsec = (*times)[0].tv_nsec;
+ mtime->tv_sec = (*times)[1].tv_sec;
+ mtime->tv_nsec = (*times)[1].tv_nsec;
+#else
+ atime->tv_sec = times->actime;
+ atime->tv_nsec = 0;
+ mtime->tv_sec = times->modtime;
+ mtime->tv_nsec = 0;
+#endif
+}
+
+/* --------------------------------------------------------------------------------------------- */
diff --git a/lib/vfs/utilvfs.h b/lib/vfs/utilvfs.h
index a203b78..49e6bc4 100644
--- a/lib/vfs/utilvfs.h
+++ b/lib/vfs/utilvfs.h
@@ -61,6 +61,8 @@ 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);
+void vfs_get_timespecs_from_timesbuf (mc_timesbuf_t *times, mc_timespec_t *atime,
+ mc_timespec_t *mtime);

/*** inline functions ****************************************************************************/

diff --git a/lib/vfs/vfs.h b/lib/vfs/vfs.h
index 0a55c98..55e9530 100644
--- a/lib/vfs/vfs.h
+++ b/lib/vfs/vfs.h
@@ -95,6 +95,12 @@ typedef struct timespec mc_timesbuf_t[2];
typedef struct utimbuf mc_timesbuf_t;
#endif

+typedef struct mc_timespec
+{
+ time_t tv_sec;
+ long tv_nsec;
+} mc_timespec_t;
+
/*** enums ***************************************************************************************/

typedef enum
diff --git a/src/vfs/sftpfs/sftpfs.c b/src/vfs/sftpfs/sftpfs.c
index fcc9347..e3936a3 100644
--- a/src/vfs/sftpfs/sftpfs.c
+++ b/src/vfs/sftpfs/sftpfs.c
@@ -336,16 +336,11 @@ sftpfs_cb_utime (const vfs_path_t *vpath, mc_timesbuf_t *times)
{
int rc;
GError *mcerror = NULL;
+ mc_timespec_t atime, mtime;

-#ifdef HAVE_UTIMENSAT
- time_t atime = (*times)[0].tv_sec;
- time_t mtime = (*times)[1].tv_sec;
-#else
- time_t atime = times->actime;
- time_t mtime = times->modtime;
-#endif
+ vfs_get_timespecs_from_timesbuf (times, &atime, &mtime);
+ rc = sftpfs_utime (vpath, atime.tv_sec, mtime.tv_sec, &mcerror);

- rc = sftpfs_utime (vpath, atime, mtime, &mcerror);
mc_error_message (&mcerror, NULL);
return rc;
}
diff --git a/src/vfs/shell/shell.c b/src/vfs/shell/shell.c
index 96fe4fc..dc053cd 100644
--- a/src/vfs/shell/shell.c
+++ b/src/vfs/shell/shell.c
@@ -1451,41 +1451,12 @@ shell_chown (const vfs_path_t *vpath, uid_t owner, gid_t group)

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

-static void
-shell_get_atime (mc_timesbuf_t *times, time_t *sec, long *nsec)
-{
-#ifdef HAVE_UTIMENSAT
- *sec = (*times)[0].tv_sec;
- *nsec = (*times)[0].tv_nsec;
-#else
- *sec = times->actime;
- *nsec = 0;
-#endif
-}
-
-/* --------------------------------------------------------------------------------------------- */
-
-static void
-shell_get_mtime (mc_timesbuf_t *times, time_t *sec, long *nsec)
-{
-#ifdef HAVE_UTIMENSAT
- *sec = (*times)[1].tv_sec;
- *nsec = (*times)[1].tv_nsec;
-#else
- *sec = times->modtime;
- *nsec = 0;
-#endif
-}
-
-/* --------------------------------------------------------------------------------------------- */
-
static int
shell_utime (const vfs_path_t *vpath, mc_timesbuf_t *times)
{
char utcatime[16], utcmtime[16];
char utcatime_w_nsec[30], utcmtime_w_nsec[30];
- time_t atime, mtime;
- long atime_nsec, mtime_nsec;
+ mc_timespec_t atime, mtime;
struct tm *gmt;
const char *crpath;
char *rpath;
@@ -1499,31 +1470,32 @@ shell_utime (const vfs_path_t *vpath, mc_timesbuf_t *times)

rpath = str_shell_escape (crpath);

- shell_get_atime (times, &atime, &atime_nsec);
- gmt = gmtime (&atime);
+ vfs_get_timespecs_from_timesbuf (times, &atime, &mtime);
+
+ gmt = gmtime (&atime.tv_sec);
g_snprintf (utcatime, sizeof (utcatime), "%04d%02d%02d%02d%02d.%02d",
gmt->tm_year + 1900, gmt->tm_mon + 1, gmt->tm_mday,
gmt->tm_hour, gmt->tm_min, gmt->tm_sec);
g_snprintf (utcatime_w_nsec, sizeof (utcatime_w_nsec), "%04d-%02d-%02d %02d:%02d:%02d.%09ld",
gmt->tm_year + 1900, gmt->tm_mon + 1, gmt->tm_mday,
- gmt->tm_hour, gmt->tm_min, gmt->tm_sec, atime_nsec);
+ gmt->tm_hour, gmt->tm_min, gmt->tm_sec, atime.tv_nsec);

- shell_get_mtime (times, &mtime, &mtime_nsec);
- gmt = gmtime (&mtime);
+ gmt = gmtime (&mtime.tv_sec);
g_snprintf (utcmtime, sizeof (utcmtime), "%04d%02d%02d%02d%02d.%02d",
gmt->tm_year + 1900, gmt->tm_mon + 1, gmt->tm_mday,
gmt->tm_hour, gmt->tm_min, gmt->tm_sec);
g_snprintf (utcmtime_w_nsec, sizeof (utcmtime_w_nsec), "%04d-%02d-%02d %02d:%02d:%02d.%09ld",
gmt->tm_year + 1900, gmt->tm_mon + 1, gmt->tm_mday,
- gmt->tm_hour, gmt->tm_min, gmt->tm_sec, mtime_nsec);
+ gmt->tm_hour, gmt->tm_min, gmt->tm_sec, mtime.tv_nsec);

me = VFS_CLASS (vfs_path_get_last_path_vfs (vpath));

ret = shell_send_command (me, super, OPT_FLUSH, SHELL_SUPER (super)->scr_utime,
- "SHELL_FILENAME=%s SHELL_FILEATIME=%ld SHELL_FILEMTIME=%ld "
+ "SHELL_FILENAME=%s SHELL_FILEATIME=%ju SHELL_FILEMTIME=%ju "
"SHELL_TOUCHATIME=%s SHELL_TOUCHMTIME=%s SHELL_TOUCHATIME_W_NSEC=\"%s\" "
- "SHELL_TOUCHMTIME_W_NSEC=\"%s\";\n", rpath, (long) atime,
- (long) mtime, utcatime, utcmtime, utcatime_w_nsec, utcmtime_w_nsec);
+ "SHELL_TOUCHMTIME_W_NSEC=\"%s\";\n", rpath, (uintmax_t) atime.tv_sec,
+ (uintmax_t) mtime.tv_sec, utcatime, utcmtime, utcatime_w_nsec,
+ utcmtime_w_nsec);

g_free (rpath);


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