Add logic to warn of possible renames, and clearly state when failures may
authorMatthew Dillon <dillon@dragonflybsd.org>
Wed, 16 Jul 2008 21:38:10 +0000 (21:38 +0000)
committerMatthew Dillon <dillon@dragonflybsd.org>
Wed, 16 Jul 2008 21:38:10 +0000 (21:38 +0000)
be due to prior renames.

Change -h to -a (-a for 'all'), which is a more obvious option name.

usr.bin/undo/undo.1
usr.bin/undo/undo.c

index dea40da..1376735 100644 (file)
@@ -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.4 2008/07/16 01:27:09 thomas Exp $
+.\" $DragonFly: src/usr.bin/undo/undo.1,v 1.5 2008/07/16 21:38:10 dillon Exp $
 .Dd May 31, 2008
 .Dt UNDO 1
 .Os
@@ -39,7 +39,7 @@
 .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 transaction-id
 .Op Fl t Ar transaction-id
@@ -61,7 +61,7 @@ Generate a unified diff from the current version to the older version.
 Generate a single line giving the transaction id and converted timestamp
 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 operation for each version.
 .It Fl u
@@ -91,7 +91,7 @@ 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.
 .Pp
 A second
index cdf27f4..372319a 100644 (file)
@@ -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.4 2008/07/16 01:27:09 thomas Exp $
+ * $DragonFly: src/usr.bin/undo/undo.c,v 1.5 2008/07/16 21:38:10 dillon 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,19 @@ 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, 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,12 +623,12 @@ timestamp(hammer_ioc_hist_entry_t hen)
 static void
 usage(void)
 {
-       fprintf(stderr, "undo [-dDhiuv] [-o outfile] [-t transaction-id] [-t transaction-id] "
-                       "file ...\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"
                        "    -o file  Output to the specified file\n"