diff options
-rw-r--r-- | man1/metastore.1 | 9 | ||||
-rw-r--r-- | metastore.txt | 24 | ||||
-rw-r--r-- | src/metaentry.c | 15 | ||||
-rw-r--r-- | src/metaentry.h | 2 | ||||
-rw-r--r-- | src/metastore.c | 8 | ||||
-rw-r--r-- | src/settings.h | 1 |
6 files changed, 45 insertions, 14 deletions
diff --git a/man1/metastore.1 b/man1/metastore.1 index 063e3e3..d788161 100644 --- a/man1/metastore.1 +++ b/man1/metastore.1 @@ -67,6 +67,9 @@ Prevents metastore from omitting .git directories. .B \-f <file>, \-\-file <file> Causes the metadata to be saved, read from the specified file rather than ./.metadata. +.TP +.B \-r <foRmat>, \-\-format <foRmat> +Causes the metadata to be saved in format \fB<foRmat>\fR. See \fBFORMATS\fR below. .\" .SH PATHS If no path is specified, metastore will use the current directory as the basis @@ -75,6 +78,12 @@ Alternatively, one or more paths can be specified and they will each be examined. Later invocations should be made using the exact same paths to ensure that the stored metadata is interpreted correctly. .\" +.SH FORMATS +.TP +.B 0 +The original and default format, it is a compact binary representation of the +file metadata stored. +.\" .SH AUTHORS metastore was created by David Härdeman in 2007-2008. Now it is maintained by Przemysław Pawełczyk. diff --git a/metastore.txt b/metastore.txt index 7edb5a8..f3d7d55 100644 --- a/metastore.txt +++ b/metastore.txt @@ -9,11 +9,11 @@ SYNOPSIS metastore ACTION [OPTION...] [PATH...] DESCRIPTION - Stores or restores metadata (owner, group, permissions, xattrs and - optionally mtime) for a filesystem tree. This can be used to preserve - the metadata in situations where it is usually not stored (git and tar - for example) or as a tripwire like mechanism to detect any changes to - metadata. Note that e.g. SELinux stores its labels in xattrs so care + Stores or restores metadata (owner, group, permissions, xattrs and op‐ + tionally mtime) for a filesystem tree. This can be used to preserve the + metadata in situations where it is usually not stored (git and tar for + example) or as a tripwire like mechanism to detect any changes to meta‐ + data. Note that e.g. SELinux stores its labels in xattrs so care should be taken when applying stored metadata to make sure that system security is not compromised. @@ -72,13 +72,21 @@ OPTIONS Causes the metadata to be saved, read from the specified file rather than ./.metadata. + -r <foRmat>, --format <foRmat> + Causes the metadata to be saved in format <foRmat>. See FORMATS + below. + PATHS - If no path is specified, metastore will use the current directory as - the basis for the actions. This is the recommended way of executing - metastore. Alternatively, one or more paths can be specified and they + If no path is specified, metastore will use the current directory as + the basis for the actions. This is the recommended way of executing + metastore. Alternatively, one or more paths can be specified and they will each be examined. Later invocations should be made using the exact same paths to ensure that the stored metadata is interpreted correctly. +FORMATS + 0 The original and default format, it is a compact binary repre‐ + sentation of the file metadata stored. + AUTHORS metastore was created by David Härdeman in 2007-2008. Now it is main‐ tained by Przemysław Pawełczyk. All source code contributors are diff --git a/src/metaentry.c b/src/metaentry.c index 035901c..1eeed5b 100644 --- a/src/metaentry.c +++ b/src/metaentry.c @@ -434,9 +434,18 @@ mentries_tofile_v0(const struct metahash *mhash, FILE * to) /* Stores metaentries to a file */ void -mentries_tofile(const struct metahash *mhash, const char *path) +mentries_tofile(const struct metahash *mhash, const char *path, int format) { FILE *to; + char const * formatstr; + void(*tofile)(const struct metahash *, FILE *); + + switch (format) { + case 0: formatstr = VERSION_0; tofile = mentries_tofile_v0; break; + default: + msg(MSG_CRITICAL, "Unknown format %d\n", format); + exit(EXIT_FAILURE); + } to = fopen(path, "w"); if (!to) { @@ -446,9 +455,9 @@ mentries_tofile(const struct metahash *mhash, const char *path) } write_binary_string(SIGNATURE, SIGNATURELEN, to); - write_binary_string(VERSION_0, VERSIONLEN, to); + write_binary_string(formatstr, VERSIONLEN, to); - mentries_tofile_v0(mhash, to); + tofile(mhash, to); fclose(to); } diff --git a/src/metaentry.h b/src/metaentry.h index d5f209d..a6de66b 100644 --- a/src/metaentry.h +++ b/src/metaentry.h @@ -61,7 +61,7 @@ void mentries_recurse_path(const char *opath, struct metahash **mhash, msettings *st); /* Stores a metaentry list to a file */ -void mentries_tofile(const struct metahash *mhash, const char *path); +void mentries_tofile(const struct metahash *mhash, const char *path, int format); /* Creates a metaentry list from a file */ void mentries_fromfile(struct metahash **mhash, const char *path); diff --git a/src/metastore.c b/src/metastore.c index c6f48cf..2bc2a89 100644 --- a/src/metastore.c +++ b/src/metastore.c @@ -47,6 +47,7 @@ static struct metasettings settings = { .do_emptydirs = false, .do_removeemptydirs = false, .do_git = false, + .format = 0, }; /* Used to create lists of dirs / other files which are missing in the fs */ @@ -462,6 +463,7 @@ usage(const char *arg0, const char *message) " -E, --remove-empty-dirs Remove extra empty directories\n" " -g, --git Do not omit .git directories\n" " -f, --file=FILE Set metadata file (" METAFILE " by default)\n" +" -r, --format=fmt Set file format to save as\n" ); exit(message ? EXIT_FAILURE : EXIT_SUCCESS); @@ -482,6 +484,7 @@ static struct option long_options[] = { { "remove-empty-dirs", no_argument, NULL, 'E' }, { "git", no_argument, NULL, 'g' }, { "file", required_argument, NULL, 'f' }, + { "format", required_argument, NULL, 'r' }, { NULL, 0, NULL, 0 } }; @@ -498,7 +501,7 @@ main(int argc, char **argv) i = 0; while (1) { int option_index = 0; - c = getopt_long(argc, argv, "csadVhvqmeEgf:", + c = getopt_long(argc, argv, "csadVhvqmeEgf:r:", long_options, &option_index); if (c == -1) break; @@ -517,6 +520,7 @@ main(int argc, char **argv) break; case 'g': /* git */ settings.do_git = true; break; case 'f': /* file */ settings.metafile = optarg; break; + case 'r': /* format */ settings.format = atoi(optarg);break; default: usage(argv[0], "unknown option"); } @@ -568,7 +572,7 @@ main(int argc, char **argv) mentries_compare(real, stored, compare_print, &settings); break; case ACTION_SAVE: - mentries_tofile(real, settings.metafile); + mentries_tofile(real, settings.metafile, settings.format); break; case ACTION_APPLY: mentries_compare(real, stored, compare_fix, &settings); diff --git a/src/settings.h b/src/settings.h index b6baa50..048f281 100644 --- a/src/settings.h +++ b/src/settings.h @@ -27,6 +27,7 @@ struct metasettings { bool do_emptydirs; /* should empty dirs be recreated? */ bool do_removeemptydirs; /* should new empty dirs be removed? */ bool do_git; /* should .git dirs be processed? */ + int format; /* Metadata format version */ }; /* Convenient typedef for immutable settings */ |