diff options
-rw-r--r-- | metaentry.c | 2 | ||||
-rw-r--r-- | metastore.1 | 7 | ||||
-rw-r--r-- | metastore.c | 23 | ||||
-rw-r--r-- | metastore.h | 4 |
4 files changed, 28 insertions, 8 deletions
diff --git a/metaentry.c b/metaentry.c index c06fd3d..a557a93 100644 --- a/metaentry.c +++ b/metaentry.c @@ -576,7 +576,7 @@ mentry_compare(struct metaentry *left, struct metaentry *right, bool do_mtime) if ((left->mode & S_IFMT) != (right->mode & S_IFMT)) retval |= DIFF_TYPE; - if (do_mtime && strcmp(left->path, METAFILE) && + if (do_mtime && strcmp(left->path, metafile) && (left->mtime != right->mtime || left->mtimensec != right->mtimensec)) retval |= DIFF_MTIME; diff --git a/metastore.1 b/metastore.1 index eeecdc9..316f4b4 100644 --- a/metastore.1 +++ b/metastore.1 @@ -20,7 +20,8 @@ stored metadata to make sure that system security is not compromised. Shows the difference between the stored and real metadata. .TP .B -s, --save -Saves the current metadata to ./.metadata. +Saves the current metadata to ./.metadata or to the specified file +(see --file option below). .TP .B -a, --apply Attempts to apply the stored metadata to the file system. @@ -46,6 +47,10 @@ Also attempts to recreate missing empty directories. May be useful where empty directories are not tracked (e.g. by git or cvs). Only works in combination with the \fBapply\fR option. This is currently an experimental feature. +.TP +.B -f <file>, --file <file> +Causes the metadata to be saved, read from the specified file rather +than ./.metadata. .\" .SH PATHS If no path is specified, metastore will use the current directory as the basis diff --git a/metastore.c b/metastore.c index fdc634d..473c180 100644 --- a/metastore.c +++ b/metastore.c @@ -31,6 +31,9 @@ #include "utils.h" #include "metaentry.h" +/* Used to store the path to the file containing the metadata */ +char *metafile = METAFILE; + /* Used to indicate whether mtimes should be corrected */ static bool do_mtime = false; @@ -339,6 +342,7 @@ usage(const char *arg0, const char *message) " -q, --quiet\t\tPrint less verbose messages\n" " -m, --mtime\t\tAlso take mtime into account for diff or apply\n" " -e, --empty-dirs\tRecreate missing empty directories (experimental)\n" + " -f <file>, --file <file>\tSet metadata file\n" ); exit(message ? EXIT_FAILURE : EXIT_SUCCESS); @@ -354,6 +358,7 @@ static struct option long_options[] = { {"quiet", 0, 0, 0}, {"mtime", 0, 0, 0}, {"empty-dirs", 0, 0, 0}, + {"file", required_argument, 0, 0}, {0, 0, 0, 0} }; @@ -370,7 +375,7 @@ main(int argc, char **argv, char **envp) i = 0; while (1) { int option_index = 0; - c = getopt_long(argc, argv, "csahvqme", + c = getopt_long(argc, argv, "csahvqmef", long_options, &option_index); if (c == -1) break; @@ -388,6 +393,9 @@ main(int argc, char **argv, char **envp) } else if (!strcmp("empty-dirs", long_options[option_index].name)) { do_emptydirs = true; + } else if (!strcmp("file", + long_options[option_index].name)) { + metafile = optarg; } else { action |= (1 << option_index); i++; @@ -421,6 +429,9 @@ main(int argc, char **argv, char **envp) case 'e': do_emptydirs = true; break; + case 'f': + metafile = optarg; + break; default: usage(argv[0], "unknown option"); } @@ -437,10 +448,10 @@ main(int argc, char **argv, char **envp) /* Perform action */ switch (action) { case ACTION_DIFF: - mentries_fromfile(&stored, METAFILE); + mentries_fromfile(&stored, metafile); if (!stored) { msg(MSG_CRITICAL, "Failed to load metadata from %s\n", - METAFILE); + metafile); exit(EXIT_FAILURE); } @@ -474,14 +485,14 @@ main(int argc, char **argv, char **envp) exit(EXIT_FAILURE); } - mentries_tofile(real, METAFILE); + mentries_tofile(real, metafile); break; case ACTION_APPLY: - mentries_fromfile(&stored, METAFILE); + mentries_fromfile(&stored, metafile); if (!stored) { msg(MSG_CRITICAL, "Failed to load metadata from %s\n", - METAFILE); + metafile); exit(EXIT_FAILURE); } diff --git a/metastore.h b/metastore.h index 7bc7868..74debb8 100644 --- a/metastore.h +++ b/metastore.h @@ -32,3 +32,7 @@ #define ACTION_SAVE 0x02 #define ACTION_APPLY 0x04 #define ACTION_HELP 0x08 + +/* Used to store the name of the file containing the metadata */ +extern char *metafile; + |