aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-08-11 00:31:17 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-08-11 00:31:17 +0200
commiteb01ccca21a9a2e1693b28871f65934e8931e3bf (patch)
tree2a2c76e4bbb3668fdf4e0aa667c80519c76b01f4
parentb3c3401aee91bc2ff46ba0eab0ceb88c78cb5bbb (diff)
Replace fstree_from_dir boolean with flag field
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
-rw-r--r--difftool/fscompare.c4
-rw-r--r--include/fstree.h6
-rw-r--r--lib/fstree/fstree_from_dir.c10
-rw-r--r--mkfs/mkfs.c11
4 files changed, 21 insertions, 10 deletions
diff --git a/difftool/fscompare.c b/difftool/fscompare.c
index 3f00a5c..6717610 100644
--- a/difftool/fscompare.c
+++ b/difftool/fscompare.c
@@ -104,10 +104,10 @@ int main(int argc, char **argv)
if (fstree_init(&bfs, 512, NULL))
goto out_afs;
- if (fstree_from_dir(&afs, first_path, true))
+ if (fstree_from_dir(&afs, first_path, DIR_SCAN_KEEP_TIME))
goto out_bfs;
- if (fstree_from_dir(&bfs, second_path, true))
+ if (fstree_from_dir(&bfs, second_path, DIR_SCAN_KEEP_TIME))
goto out_bfs;
tree_node_sort_recursive(afs.root);
diff --git a/include/fstree.h b/include/fstree.h
index dbc76db..a6fbd3e 100644
--- a/include/fstree.h
+++ b/include/fstree.h
@@ -35,6 +35,10 @@ enum {
FILE_FLAG_BLOCKS_ARE_DUPLICATE = 0x04,
};
+enum {
+ DIR_SCAN_KEEP_TIME = 0x01,
+};
+
/* Encapsulates a set of key-value pairs attached to a tree_node_t */
struct tree_xattr_t {
/* Number of key-value pairs */
@@ -271,7 +275,7 @@ int fstree_from_file(fstree_t *fs, const char *filename, FILE *fp);
Returns 0 on success, prints errors to stderr.
*/
-int fstree_from_dir(fstree_t *fs, const char *path, bool keep_time_stamps);
+int fstree_from_dir(fstree_t *fs, const char *path, unsigned int flags);
/* Add labels from an SELinux labeling file to all tree nodes.
Returns 0 on success. Internally prints errors to stderr. */
diff --git a/lib/fstree/fstree_from_dir.c b/lib/fstree/fstree_from_dir.c
index a216226..0c56148 100644
--- a/lib/fstree/fstree_from_dir.c
+++ b/lib/fstree/fstree_from_dir.c
@@ -52,7 +52,7 @@ fail:
return NULL;
}
-static int populate_dir(fstree_t *fs, tree_node_t *root, bool keep_time_stamps)
+static int populate_dir(fstree_t *fs, tree_node_t *root, unsigned int flags)
{
char *extra = NULL;
struct dirent *ent;
@@ -101,7 +101,7 @@ static int populate_dir(fstree_t *fs, tree_node_t *root, bool keep_time_stamps)
goto fail;
}
- if (!keep_time_stamps)
+ if (!(flags & DIR_SCAN_KEEP_TIME))
sb.st_mtim = fs->defaults.st_mtim;
n = fstree_mknode(fs, root, ent->d_name, strlen(ent->d_name),
@@ -122,7 +122,7 @@ static int populate_dir(fstree_t *fs, tree_node_t *root, bool keep_time_stamps)
if (pushd(n->name))
return -1;
- if (populate_dir(fs, n, keep_time_stamps))
+ if (populate_dir(fs, n, flags))
return -1;
if (popd())
@@ -139,14 +139,14 @@ fail:
return -1;
}
-int fstree_from_dir(fstree_t *fs, const char *path, bool keep_time_stamps)
+int fstree_from_dir(fstree_t *fs, const char *path, unsigned int flags)
{
int ret;
if (pushd(path))
return -1;
- ret = populate_dir(fs, fs->root, keep_time_stamps);
+ ret = populate_dir(fs, fs->root, flags);
if (popd())
ret = -1;
diff --git a/mkfs/mkfs.c b/mkfs/mkfs.c
index 79dded9..8b8ecc3 100644
--- a/mkfs/mkfs.c
+++ b/mkfs/mkfs.c
@@ -68,11 +68,18 @@ static int pack_files(data_writer_t *data, fstree_t *fs, options_t *opt)
static int read_fstree(fstree_t *fs, options_t *opt)
{
+ unsigned int flags;
FILE *fp;
int ret;
- if (opt->infile == NULL)
- return fstree_from_dir(fs, opt->packdir, opt->keep_time);
+ if (opt->infile == NULL) {
+ flags = 0;
+
+ if (opt->keep_time)
+ flags |= DIR_SCAN_KEEP_TIME;
+
+ return fstree_from_dir(fs, opt->packdir, flags);
+ }
fp = fopen(opt->infile, "rb");
if (fp == NULL) {