utilvfs: concentrate timesbuf handling in one place

Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
This commit is contained in:
Yury V. Zaytsev 2024-05-31 21:02:00 +02:00
parent 77e5913c02
commit c8e8f01faf
3 changed files with 19 additions and 17 deletions

View File

@ -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
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -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 ****************************************************************************/

View File

@ -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