From 7d303c64e1aaff5c12feacef6797fdc97752cbee Mon Sep 17 00:00:00 2001 From: Thomas Nikolajsen Date: Thu, 17 Jul 2008 23:50:02 +0000 Subject: [PATCH] MFC: following 4 commits: undo(1) doc fixes: - sync usage() to undo.1 - improve wording a bit in a few places Update `-t' flag; now it is always transaction-id. Add logic to warn of possible renames, and clearly state when failures may be due to prior renames. Change -h to -a (-a for 'all'), which is a more obvious option name. Add missing space and newline to error message. --- usr.bin/undo/undo.1 | 38 ++++++++++++++++++++------------------ usr.bin/undo/undo.c | 48 +++++++++++++++++++++++++++++------------------- 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/usr.bin/undo/undo.1 b/usr.bin/undo/undo.1 index 0ee7e73df9..2b5e6f4754 100644 --- a/usr.bin/undo/undo.1 +++ b/usr.bin/undo/undo.1 @@ -30,7 +30,7 @@ .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $DragonFly: src/usr.bin/undo/undo.1,v 1.2 2008/06/03 12:40:09 swildner Exp $ +.\" $DragonFly: src/usr.bin/undo/undo.1,v 1.2.2.1 2008/07/17 23:50:02 thomas Exp $ .Dd May 31, 2008 .Dt UNDO 1 .Os @@ -39,17 +39,16 @@ .Nd Undo changes made to files on HAMMER filesystems .Sh SYNOPSIS .Nm -.Op Fl dDhiuv +.Op Fl adDiuv .Op Fl o Ar outfile -.Op Fl t Ar {s,m,h,d} -.Op Fl t Ar {s,m,h,d} -.Ar file1 -.Ar ... +.Op Fl t Ar transaction-id +.Op Fl t Ar transaction-id +.Ar .Sh DESCRIPTION The .Nm utility acquires an older version of the specified files and can output -them stdout, generate a file with the previous contents, or generate +them to stdout, generate a file with the previous contents, or generate a diff to stdout. A history can also be generated. .Pp The options are as follows: @@ -60,13 +59,13 @@ Generate a unified diff from the older version to the current version. Generate a unified diff from the current version to the older version. .It Fl i Generate a single line giving the transaction id and converted timestamp -of the version of the file requested, rather then dumping the contents +of the version of the file requested, rather than dumping the contents of the file. -.It Fl h +.It Fl a Iterate through the file's entire history generating undo files, diffs, -output, etc. Execute the generation op for each version. +output, etc. Execute the generation operation for each version. .It Fl u -Output to a file synthesized from the input filename postfixed with ".undo". +Output to a file with name synthesized from the input filename postfixed with ".undo". If not specified output is either to stdout or, if a single file argument is given, the file specified by the .Fl o @@ -86,16 +85,18 @@ each file path. When used with multiple files '%%' must be used in the specification to indicate a '%'. When used with a single file the .Ar outfile string is used verbatim. -.It Fl t Ar {s,m,h,d} -Specify how far to go back relative to the current time. A HAMMER -transaction id (0x16chars) may also be specified. If not specified +.It Fl t Ar transaction-id +Specify how far to go back in time, by giving a HAMMER +transaction id (0x16chars). If not specified the program will attempt to locate the most recent version of the file(s) prior to the current version. This option does not apply if -.Fl h +.Fl a is specified. -.It Fl t Ar {s,m,h,d} -A second time specification may be given when the +.Pp +A second +.Fl t +specification may be given when the .Fl d or .Fl D @@ -122,4 +123,5 @@ utility first appeared in .Sh BUGS HAMMER only synchronizes information to disk every 30 seconds or so and a quick file create / delete is done entirely in system memory and cannot -be undone. This can be worked around by running 'hammer synctid '. +be undone. This can be worked around by running +.Dq Ar hammer synctid Op filesystem . diff --git a/usr.bin/undo/undo.c b/usr.bin/undo/undo.c index d44536317c..2109230cdf 100644 --- a/usr.bin/undo/undo.c +++ b/usr.bin/undo/undo.c @@ -31,7 +31,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/usr.bin/undo/undo.c,v 1.2 2008/06/24 17:40:24 dillon Exp $ + * $DragonFly: src/usr.bin/undo/undo.c,v 1.2.2.1 2008/07/17 23:50:02 thomas Exp $ */ /* * UNDO - retrieve an older version of a file. @@ -58,7 +58,8 @@ static void dogenerate(const char *filename, const char *outFileName, const char *outFilePostfix, int mult, int idx, enum undo_type type, struct hammer_ioc_hist_entry ts1, - struct hammer_ioc_hist_entry ts2); + struct hammer_ioc_hist_entry ts2, + int force); static struct hammer_ioc_hist_entry find_recent(const char *filename); static struct hammer_ioc_hist_entry @@ -89,7 +90,7 @@ main(int ac, char **av) cmd = CMD_DUMP; type = TYPE_FILE; - while ((c = getopt(ac, av, "dDhiuvo:t:")) != -1) { + while ((c = getopt(ac, av, "adDiuvo:t:")) != -1) { switch(c) { case 'd': if (type != TYPE_FILE) @@ -106,7 +107,7 @@ main(int ac, char **av) usage(); type = TYPE_HISTORY; break; - case 'h': + case 'a': cmd = CMD_ITERATEALL; break; case 'u': @@ -177,7 +178,7 @@ main(int ac, char **av) switch(cmd) { case CMD_DUMP: dogenerate(*av, outFileName, outFilePostfix, - mult, -1, type, ts1, ts2); + mult, -1, type, ts1, ts2, 1); break; case CMD_ITERATEALL: doiterate(*av, outFileName, outFilePostfix, @@ -233,12 +234,12 @@ doiterate(const char *orig_filename, const char *outFileName, dogenerate(orig_filename, outFileName, outFilePostfix, mult, i, type, - tid_ary[i], tid_max); + tid_ary[i], tid_max, 0); } else { dogenerate(orig_filename, outFileName, outFilePostfix, mult, i, type, - tid_ary[i], tid_ary[i+1]); + tid_ary[i], tid_ary[i+1], 0); } } @@ -260,7 +261,8 @@ dogenerate(const char *filename, const char *outFileName, const char *outFilePostfix, int mult, int idx, enum undo_type type, struct hammer_ioc_hist_entry ts1, - struct hammer_ioc_hist_entry ts2) + struct hammer_ioc_hist_entry ts2, + int force) { struct stat st; const char *elm; @@ -282,12 +284,20 @@ dogenerate(const char *filename, const char *outFileName, ts1 = find_recent(filename); asprintf(&ipath1, "%s@@0x%016llx", filename, ts1.tid); if (lstat(ipath1, &st) < 0) { - if (VerboseOpt) { + free(ipath1); + asprintf(&ipath1, "%s", filename); + if (force == 0 || lstat(ipath1, &st) < 0) { fprintf(stderr, "Cannot locate src/historical " - "idx=%d %s\n", - idx, ipath1); + "idx=%d %s@@0x%016llx,\n" + "the file may have been renamed " + "in the past.\n", + idx, filename, ts1.tid); + goto done; } - goto done; + fprintf(stderr, + "WARNING: %s was renamed at some point in the past,\n" + "attempting to continue with current version\n", + filename); } if (ts2.tid == 0) { @@ -614,17 +624,17 @@ timestamp(hammer_ioc_hist_entry_t hen) static void usage(void) { - fprintf(stderr, "undo [-dDhiuv] [-t n{s,m,h,d}] [-t n...] " - "file1....fileN\n"); - fprintf(stderr, " -d Forward diff\n" + fprintf(stderr, "undo [-adDiuv] [-o outfile] " + "[-t transaction-id] [-t transaction-id] file...\n" + " -a Iterate all historical segments\n" + " -d Forward diff\n" " -D Reverse diff\n" " -i Dump history transaction ids\n" - " -h Iterate all historical segments\n" " -u Generate .undo files\n" " -v Verbose\n" - " -t spec Retrieve as of n secs,mins,etc ago\n" - " (a second one to diff two versions)\n" - " (a 0x TID may also be specified)\n"); + " -o file Output to the specified file\n" + " -t TID Retrieve as of transaction-id, TID\n" + " (a second `-t TID' to diff two versions)\n"); exit(1); } -- 2.11.4.GIT