diff options
author | Adam Spragg <adam@spra.gg> | 2022-05-16 14:25:16 +0100 |
---|---|---|
committer | Adam Spragg <adam@spra.gg> | 2022-05-18 17:19:40 +0100 |
commit | 96df5969b11b9a64f95c0c28347154b06cfc9d15 (patch) | |
tree | d6e7caa88adb474e32acc4992dc1787b12e88878 /src | |
parent | 0ae5e697e83fef2f200dfdcf16caebc8a15a9681 (diff) |
Add -r/--format option to pick the format to save as
Only version 0 is supported here.
Diffstat (limited to 'src')
-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 |
4 files changed, 20 insertions, 6 deletions
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 */ |