hammer utility - Add force support to cleanup
[dragonfly.git] / sbin / hammer / cmd_cleanup.c
index 4bee7ea..8342684 100644 (file)
@@ -617,7 +617,11 @@ migrate_one_snapshot(int fd, const char *fpath,
                t = (time_t)-1;
                tid = (hammer_tid_t)(int64_t)-1;
 
-               ptr = fpath;
+               /* fpath may contain directory components */
+               if ((ptr = strrchr(fpath, '/')) != NULL)
+                       ++ptr;
+               else
+                       ptr = fpath;
                while (*ptr && *ptr != '-' && *ptr != '.')
                        ++ptr;
                if (*ptr)
@@ -649,6 +653,9 @@ migrate_one_snapshot(int fd, const char *fpath,
                        snprintf(snap->label, sizeof(snap->label),
                                 "migrated");
                        ++snapshot->count;
+               } else {
+                       printf("    non-canonical snapshot softlink: %s->%s\n",
+                              fpath, linkbuf);
                }
        }
 
@@ -717,6 +724,8 @@ dividing_slash(const char *path)
  * Periods in minutes, hours, or days are assumed to have been crossed
  * if the local time crosses a minute, hour, or day boundary regardless
  * of how close the last operation actually was.
+ *
+ * If ForceOpt is set always return true.
  */
 static int
 check_period(const char *snapshots_path, const char *cmd, int arg1,
@@ -733,6 +742,12 @@ check_period(const char *snapshots_path, const char *cmd, int arg1,
        localtime_r(savep, &tp1);
 
        /*
+        * Force run if -F
+        */
+       if (ForceOpt)
+               return(1);
+
+       /*
         * Retrieve the start time of the last successful operation.
         */
        asprintf(&check_path, "%s/.%s.period", snapshots_path, cmd);