diff options
author | Phillip Lougher <phillip@squashfs.org.uk> | 2014-06-22 02:34:43 +0100 |
---|---|---|
committer | Phillip Lougher <phillip@squashfs.org.uk> | 2014-06-22 02:34:43 +0100 |
commit | dcc0dfe2b85a81bd68e8836c8bb0446e0b15ac13 (patch) | |
tree | 53243a37ec87b428ea55ee66627ec5feb9dd6e85 | |
parent | 5282a3c0570a62b53157143aafb59418ae9bf257 (diff) | |
download | squashfs-tools-dcc0dfe2b85a81bd68e8836c8bb0446e0b15ac13.tar.gz |
actions: add new exists() test operator for symbolic links
Add new exists() operator that tests whether the file pointed
to by the symlink exists (in the source filesystem).
This can be used to exclude symlinks in the filesystem which are
dangling.
Note, this operator does not attempt to determine if the referenced
file is inside or outside of the filesystem being squashed.
Other additional test operators will be added to do that.
Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
-rw-r--r-- | squashfs-tools/action.c | 18 | ||||
-rw-r--r-- | squashfs-tools/action.h | 1 | ||||
-rw-r--r-- | squashfs-tools/mksquashfs.c | 2 |
3 files changed, 20 insertions, 1 deletions
diff --git a/squashfs-tools/action.c b/squashfs-tools/action.c index 359daa7..eea84bf 100644 --- a/squashfs-tools/action.c +++ b/squashfs-tools/action.c @@ -2232,6 +2232,23 @@ static int exec_fn(struct atom *atom, struct action_data *action_data) } +/* + * Symbolic link specific test code + */ +static int exists_fn(struct atom *atom, struct action_data *action_data) +{ + /* + * exists operates on symlinks only, other files by definition + * exist + */ + if (!(action_data->buf->st_mode & ACTION_LNK)) + return 1; + + /* dereference the symlink, and return TRUE if it exists */ + return access(action_data->pathname, F_OK) == 0; +} + + #ifdef SQUASHFS_TRACE static void dump_parse_tree(struct expr *expr) { @@ -2328,6 +2345,7 @@ static struct test_entry test_table[] = { { "false", 0, false_fn, NULL}, { "file", 1, file_fn, parse_file_arg}, { "exec", 1, exec_fn, NULL}, + { "exists", 0, exists_fn, NULL}, { "", -1 } }; diff --git a/squashfs-tools/action.h b/squashfs-tools/action.h index 599e2da..a2809ce 100644 --- a/squashfs-tools/action.h +++ b/squashfs-tools/action.h @@ -181,6 +181,7 @@ struct type_entry { #define ACTION_ALL_LNK (S_IFDIR | S_IFREG | S_IFBLK | S_IFCHR | S_IFSOCK | \ S_IFIFO | S_IFLNK) #define ACTION_ALL (S_IFDIR | S_IFREG | S_IFBLK | S_IFCHR | S_IFSOCK | S_IFIFO) +#define ACTION_LNK S_IFLNK struct action_entry { char *name; diff --git a/squashfs-tools/mksquashfs.c b/squashfs-tools/mksquashfs.c index d12b8d2..87bebee 100644 --- a/squashfs-tools/mksquashfs.c +++ b/squashfs-tools/mksquashfs.c @@ -4976,7 +4976,7 @@ void calculate_queue_sizes(int mem, int *readq, int *fragq, int *bwriteq, #define VERSION() \ - printf("mksquashfs version 4.3-git (2014/06/15)\n");\ + printf("mksquashfs version 4.3-git (2014/06/21)\n");\ printf("copyright (C) 2014 Phillip Lougher "\ "<phillip@squashfs.org.uk>\n\n"); \ printf("This program is free software; you can redistribute it and/or"\ |