diff options
author | midipix <writeonce@midipix.org> | 2024-05-30 22:45:00 +0000 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2024-05-30 22:45:00 +0000 |
commit | ee80f814e924d7e84e02b290f5f8796d6c4b05be (patch) | |
tree | 8c78b3821a7daa042fd572083c1aa8f5cc9654af /src/internal | |
parent | 55da8fe4b7c34589e14af92421077f906f65a592 (diff) | |
download | tpax-ee80f814e924d7e84e02b290f5f8796d6c4b05be.tar.bz2 tpax-ee80f814e924d7e84e02b290f5f8796d6c4b05be.tar.xz |
driver: implemented and integrated the -t (preserve atime) command-line option.
Diffstat (limited to 'src/internal')
-rw-r--r-- | src/internal/tpax_driver_impl.h | 1 | ||||
-rw-r--r-- | src/internal/tpax_ftime_impl.c | 48 | ||||
-rw-r--r-- | src/internal/tpax_ftime_impl.h | 24 |
3 files changed, 73 insertions, 0 deletions
diff --git a/src/internal/tpax_driver_impl.h b/src/internal/tpax_driver_impl.h index 1345c32..1e898e9 100644 --- a/src/internal/tpax_driver_impl.h +++ b/src/internal/tpax_driver_impl.h @@ -45,6 +45,7 @@ enum app_tags { TAG_NORECURSE, TAG_STRICT_PATH, TAG_PURE_PATH, + TAG_PRESERVE_ATIME, }; struct tpax_dirent { diff --git a/src/internal/tpax_ftime_impl.c b/src/internal/tpax_ftime_impl.c new file mode 100644 index 0000000..19c6d7b --- /dev/null +++ b/src/internal/tpax_ftime_impl.c @@ -0,0 +1,48 @@ +/**************************************************************/ +/* tpax: a topological pax implementation */ +/* Copyright (C) 2020--2024 SysDeer Technologies, LLC */ +/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */ +/**************************************************************/ + +#include <time.h> +#include <sys/time.h> +#include <sys/stat.h> + +#include "tpax_ftime_impl.h" +#include "tpax_driver_impl.h" +#include "tpax_visibility_impl.h" + +tpax_hidden void tpax_ftime_restore( + const struct tpax_driver_ctx * dctx, + int fd, + const struct stat * refst) +{ + struct timespec ts[2]; + + if (dctx->cctx->drvflags & TPAX_DRIVER_PRESERVE_ATIME) { + ts[0].tv_sec = refst->st_atim.tv_sec; + ts[0].tv_nsec = refst->st_atim.tv_nsec; + } else { + ts[0].tv_nsec = UTIME_OMIT; + } + + if (dctx->cctx->drvflags & TPAX_DRIVER_PRESERVE_MTIME) { + ts[1].tv_sec = refst->st_mtim.tv_sec; + ts[1].tv_nsec = refst->st_mtim.tv_nsec; + } else { + ts[1].tv_nsec = UTIME_OMIT; + } + + if ((ts[0].tv_nsec != UTIME_OMIT) || (ts[1].tv_nsec != UTIME_OMIT)) { + futimens(fd,ts); + } +} + +tpax_hidden void tpax_ftime_restore_and_close( + const struct tpax_driver_ctx * dctx, + int fd, + const struct stat * refst) +{ + tpax_ftime_restore(dctx,fd,refst); + close(fd); +} diff --git a/src/internal/tpax_ftime_impl.h b/src/internal/tpax_ftime_impl.h new file mode 100644 index 0000000..2d0e981 --- /dev/null +++ b/src/internal/tpax_ftime_impl.h @@ -0,0 +1,24 @@ +/**************************************************************/ +/* tpax: a topological pax implementation */ +/* Copyright (C) 2020--2024 SysDeer Technologies, LLC */ +/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */ +/**************************************************************/ + +#ifndef TPAX_FTIME_IMPL_H +#define TPAX_FTIME_IMPL_H + +#include <time.h> +#include <sys/time.h> +#include <sys/stat.h> + +#include "tpax_driver_impl.h" + +void tpax_ftime_restore( + const struct tpax_driver_ctx *, + int fd, const struct stat *); + +void tpax_ftime_restore_and_close( + const struct tpax_driver_ctx *, + int fd, const struct stat *); + +#endif |