aboutsummaryrefslogtreecommitdiff
path: root/lib/fstree
diff options
context:
space:
mode:
Diffstat (limited to 'lib/fstree')
-rw-r--r--lib/fstree/add_by_path.c1
-rw-r--r--lib/fstree/fstree_from_dir.c14
-rw-r--r--lib/fstree/fstree_from_file.c6
-rw-r--r--lib/fstree/mknode.c1
-rw-r--r--lib/fstree/node_stat.c3
5 files changed, 21 insertions, 4 deletions
diff --git a/lib/fstree/add_by_path.c b/lib/fstree/add_by_path.c
index eaa0925..7e0a4ce 100644
--- a/lib/fstree/add_by_path.c
+++ b/lib/fstree/add_by_path.c
@@ -77,6 +77,7 @@ tree_node_t *fstree_add_generic(fstree_t *fs, const char *path,
child->uid = sb->st_uid;
child->gid = sb->st_gid;
child->mode = sb->st_mode;
+ child->mod_time = sb->st_mtime;
child->data.dir->created_implicitly = false;
return child;
}
diff --git a/lib/fstree/fstree_from_dir.c b/lib/fstree/fstree_from_dir.c
index 29911f4..ad75006 100644
--- a/lib/fstree/fstree_from_dir.c
+++ b/lib/fstree/fstree_from_dir.c
@@ -43,7 +43,7 @@ fail:
return NULL;
}
-static int populate_dir(fstree_t *fs, tree_node_t *root)
+static int populate_dir(fstree_t *fs, tree_node_t *root, bool keep_time_stamps)
{
char *extra = NULL;
struct dirent *ent;
@@ -92,6 +92,12 @@ static int populate_dir(fstree_t *fs, tree_node_t *root)
goto fail;
}
+ if (!keep_time_stamps) {
+ sb.st_atim = fs->defaults.st_atim;
+ sb.st_mtim = fs->defaults.st_mtim;
+ sb.st_ctim = fs->defaults.st_ctim;
+ }
+
n = fstree_mknode(fs, root, ent->d_name, strlen(ent->d_name),
extra, &sb);
if (n == NULL) {
@@ -110,7 +116,7 @@ static int populate_dir(fstree_t *fs, tree_node_t *root)
if (pushd(n->name))
return -1;
- if (populate_dir(fs, n))
+ if (populate_dir(fs, n, keep_time_stamps))
return -1;
if (popd())
@@ -127,14 +133,14 @@ fail:
return -1;
}
-int fstree_from_dir(fstree_t *fs, const char *path)
+int fstree_from_dir(fstree_t *fs, const char *path, bool keep_time_stamps)
{
int ret;
if (pushd(path))
return -1;
- ret = populate_dir(fs, fs->root);
+ ret = populate_dir(fs, fs->root, keep_time_stamps);
if (popd())
ret = -1;
diff --git a/lib/fstree/fstree_from_file.c b/lib/fstree/fstree_from_file.c
index 901e431..91a922b 100644
--- a/lib/fstree/fstree_from_file.c
+++ b/lib/fstree/fstree_from_file.c
@@ -66,6 +66,9 @@ static int add_file(fstree_t *fs, const char *filename, size_t line_num,
sb.st_uid = basic->st_uid;
sb.st_gid = basic->st_gid;
sb.st_mode = basic->st_mode;
+ sb.st_atim = basic->st_atim;
+ sb.st_mtim = basic->st_mtim;
+ sb.st_ctim = basic->st_ctim;
return add_generic(fs, filename, line_num, path, &sb, extra);
}
@@ -119,6 +122,9 @@ static int handle_line(fstree_t *fs, const char *filename,
size_t i;
memset(&sb, 0, sizeof(sb));
+ sb.st_mtime = fs->defaults.st_mtime;
+ sb.st_atime = fs->defaults.st_atime;
+ sb.st_ctime = fs->defaults.st_ctime;
/* isolate keyword */
for (i = 0; isalpha(line[i]); ++i)
diff --git a/lib/fstree/mknode.c b/lib/fstree/mknode.c
index 4b4cdfd..7d09fbd 100644
--- a/lib/fstree/mknode.c
+++ b/lib/fstree/mknode.c
@@ -43,6 +43,7 @@ tree_node_t *fstree_mknode(fstree_t *fs, tree_node_t *parent, const char *name,
n->uid = sb->st_uid;
n->gid = sb->st_gid;
n->mode = sb->st_mode;
+ n->mod_time = sb->st_mtime;
switch (sb->st_mode & S_IFMT) {
case S_IFDIR:
diff --git a/lib/fstree/node_stat.c b/lib/fstree/node_stat.c
index 8f62a0f..a28cae8 100644
--- a/lib/fstree/node_stat.c
+++ b/lib/fstree/node_stat.c
@@ -13,6 +13,9 @@ void fstree_node_stat(fstree_t *fs, tree_node_t *node, struct stat *sb)
sb->st_nlink = 1;
sb->st_uid = node->uid;
sb->st_gid = node->gid;
+ sb->st_mtime = node->mod_time;
+ sb->st_atime = node->mod_time;
+ sb->st_ctime = node->mod_time;
switch (node->mode & S_IFMT) {
case S_IFDIR: