summaryrefslogtreecommitdiffhomepage
path: root/src/internal/tpax_ftime_impl.c
blob: 19c6d7bcfbcc8aa593882ac56e260e40d05e32eb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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);
}