mirror of
https://github.com/MidnightCommander/mc
synced 2025-01-03 01:54:24 +03:00
utilvfs: abstract mc_timesbuf_t handling with own mc_timespec_t type
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
This commit is contained in:
parent
191108766f
commit
77e5913c02
@ -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
|
||||||
|
}
|
||||||
|
|
||||||
|
/* --------------------------------------------------------------------------------------------- */
|
||||||
|
@ -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_parse_filedate (int idx, time_t * t);
|
||||||
|
|
||||||
int vfs_utime (const char *path, mc_timesbuf_t *times);
|
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 ****************************************************************************/
|
/*** inline functions ****************************************************************************/
|
||||||
|
|
||||||
|
@ -95,6 +95,12 @@ typedef struct timespec mc_timesbuf_t[2];
|
|||||||
typedef struct utimbuf mc_timesbuf_t;
|
typedef struct utimbuf mc_timesbuf_t;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
typedef struct mc_timespec
|
||||||
|
{
|
||||||
|
time_t tv_sec;
|
||||||
|
long tv_nsec;
|
||||||
|
} mc_timespec_t;
|
||||||
|
|
||||||
/*** enums ***************************************************************************************/
|
/*** enums ***************************************************************************************/
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
|
@ -336,16 +336,11 @@ sftpfs_cb_utime (const vfs_path_t *vpath, mc_timesbuf_t *times)
|
|||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
GError *mcerror = NULL;
|
GError *mcerror = NULL;
|
||||||
|
mc_timespec_t atime, mtime;
|
||||||
|
|
||||||
#ifdef HAVE_UTIMENSAT
|
vfs_get_timespecs_from_timesbuf (times, &atime, &mtime);
|
||||||
time_t atime = (*times)[0].tv_sec;
|
rc = sftpfs_utime (vpath, atime.tv_sec, mtime.tv_sec, &mcerror);
|
||||||
time_t mtime = (*times)[1].tv_sec;
|
|
||||||
#else
|
|
||||||
time_t atime = times->actime;
|
|
||||||
time_t mtime = times->modtime;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
rc = sftpfs_utime (vpath, atime, mtime, &mcerror);
|
|
||||||
mc_error_message (&mcerror, NULL);
|
mc_error_message (&mcerror, NULL);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
@ -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
|
static int
|
||||||
shell_utime (const vfs_path_t *vpath, mc_timesbuf_t *times)
|
shell_utime (const vfs_path_t *vpath, mc_timesbuf_t *times)
|
||||||
{
|
{
|
||||||
char utcatime[16], utcmtime[16];
|
char utcatime[16], utcmtime[16];
|
||||||
char utcatime_w_nsec[30], utcmtime_w_nsec[30];
|
char utcatime_w_nsec[30], utcmtime_w_nsec[30];
|
||||||
time_t atime, mtime;
|
mc_timespec_t atime, mtime;
|
||||||
long atime_nsec, mtime_nsec;
|
|
||||||
struct tm *gmt;
|
struct tm *gmt;
|
||||||
const char *crpath;
|
const char *crpath;
|
||||||
char *rpath;
|
char *rpath;
|
||||||
@ -1499,31 +1470,32 @@ shell_utime (const vfs_path_t *vpath, mc_timesbuf_t *times)
|
|||||||
|
|
||||||
rpath = str_shell_escape (crpath);
|
rpath = str_shell_escape (crpath);
|
||||||
|
|
||||||
shell_get_atime (times, &atime, &atime_nsec);
|
vfs_get_timespecs_from_timesbuf (times, &atime, &mtime);
|
||||||
gmt = gmtime (&atime);
|
|
||||||
|
gmt = gmtime (&atime.tv_sec);
|
||||||
g_snprintf (utcatime, sizeof (utcatime), "%04d%02d%02d%02d%02d.%02d",
|
g_snprintf (utcatime, sizeof (utcatime), "%04d%02d%02d%02d%02d.%02d",
|
||||||
gmt->tm_year + 1900, gmt->tm_mon + 1, gmt->tm_mday,
|
gmt->tm_year + 1900, gmt->tm_mon + 1, gmt->tm_mday,
|
||||||
gmt->tm_hour, gmt->tm_min, gmt->tm_sec);
|
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",
|
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_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.tv_sec);
|
||||||
gmt = gmtime (&mtime);
|
|
||||||
g_snprintf (utcmtime, sizeof (utcmtime), "%04d%02d%02d%02d%02d.%02d",
|
g_snprintf (utcmtime, sizeof (utcmtime), "%04d%02d%02d%02d%02d.%02d",
|
||||||
gmt->tm_year + 1900, gmt->tm_mon + 1, gmt->tm_mday,
|
gmt->tm_year + 1900, gmt->tm_mon + 1, gmt->tm_mday,
|
||||||
gmt->tm_hour, gmt->tm_min, gmt->tm_sec);
|
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",
|
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_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));
|
me = VFS_CLASS (vfs_path_get_last_path_vfs (vpath));
|
||||||
|
|
||||||
ret = shell_send_command (me, super, OPT_FLUSH, SHELL_SUPER (super)->scr_utime,
|
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_TOUCHATIME=%s SHELL_TOUCHMTIME=%s SHELL_TOUCHATIME_W_NSEC=\"%s\" "
|
||||||
"SHELL_TOUCHMTIME_W_NSEC=\"%s\";\n", rpath, (long) atime,
|
"SHELL_TOUCHMTIME_W_NSEC=\"%s\";\n", rpath, (uintmax_t) atime.tv_sec,
|
||||||
(long) mtime, utcatime, utcmtime, utcatime_w_nsec, utcmtime_w_nsec);
|
(uintmax_t) mtime.tv_sec, utcatime, utcmtime, utcatime_w_nsec,
|
||||||
|
utcmtime_w_nsec);
|
||||||
|
|
||||||
g_free (rpath);
|
g_free (rpath);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user