aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/fstree.h8
-rw-r--r--lib/fstree/fstree.c28
2 files changed, 36 insertions, 0 deletions
diff --git a/include/fstree.h b/include/fstree.h
index 23cf967..66a850e 100644
--- a/include/fstree.h
+++ b/include/fstree.h
@@ -200,6 +200,14 @@ tree_node_t *fstree_add_file(fstree_t *fs, const char *path, uint16_t mode,
const char *input);
/*
+ internally calls fstree_add or fstree_add_file depending on the given stat
+ structure and sets the link target for symlinks or input file for regular
+ files from the given extra string.
+*/
+tree_node_t *fstree_add_generic(fstree_t *fs, const char *path,
+ const struct stat *sb, const char *extra);
+
+/*
Add an extended attribute key value pair to a tree node.
Returns 0 on success, prints error to stderr on failure.
diff --git a/lib/fstree/fstree.c b/lib/fstree/fstree.c
index 91c32f8..3f6387a 100644
--- a/lib/fstree/fstree.c
+++ b/lib/fstree/fstree.c
@@ -178,6 +178,34 @@ tree_node_t *fstree_add_file(fstree_t *fs, const char *path, uint16_t mode,
return node;
}
+tree_node_t *fstree_add_generic(fstree_t *fs, const char *path,
+ const struct stat *sb, const char *extra)
+{
+ size_t payload = 0;
+ tree_node_t *node;
+
+ if (S_ISREG(sb->st_mode)) {
+ return fstree_add_file(fs, path, sb->st_mode, sb->st_uid,
+ sb->st_gid, sb->st_size, extra);
+ }
+
+ if (S_ISLNK(sb->st_mode))
+ payload = strlen(extra) + 1;
+
+ node = fstree_add(fs, path, sb->st_mode, sb->st_uid,
+ sb->st_gid, payload);
+ if (node == NULL)
+ return NULL;
+
+ if (S_ISLNK(sb->st_mode)) {
+ strcpy(node->data.slink_target, extra);
+ } else if (S_ISBLK(sb->st_mode) || S_ISCHR(sb->st_mode)) {
+ node->data.devno = sb->st_rdev;
+ }
+
+ return node;
+}
+
int fstree_add_xattr(fstree_t *fs, tree_node_t *node,
const char *key, const char *value)
{