prune: add new flag --static-deltas-only
authorGiuseppe Scrivano <gscrivan@redhat.com>
Tue, 15 Dec 2015 10:32:05 +0000 (11:32 +0100)
committerGiuseppe Scrivano <gscrivan@redhat.com>
Fri, 18 Dec 2015 10:21:57 +0000 (11:21 +0100)
When specified, only the static deltas files are pruned.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
doc/ostree-prune.xml
src/ostree/ot-builtin-prune.c

index 03d7fc5c659302c50f593d8d80ea91dbd2a6fb82..9e8cc87300b2dc60b5164cf911da48b3471de099 100644 (file)
@@ -104,6 +104,15 @@ Boston, MA 02111-1307, USA.
                     Only traverse DEPTH (integer) parents for each commit (default: -1=infinite).
                 </para></listitem>
             </varlistentry>
+
+            <varlistentry>
+                <term><option>--static-deltas-only</option>=DEPTH</term>
+
+                <listitem><para>
+                  Change the behaviour of --keep-younger-than and --delete-commit to prune only
+                  the static deltas files.
+                </para></listitem>
+            </varlistentry>
         </variablelist>
     </refsect1>
 
index 104736ece5df488012b5aa6d818c75092d8d9028..0b843c98184773275b0acb403ccb926676953cee 100644 (file)
@@ -29,6 +29,7 @@
 #include "parse-datetime.h"
 
 static gboolean opt_no_prune;
+static gboolean opt_static_deltas_only;
 static gint opt_depth = -1;
 static gboolean opt_refs_only;
 static char *opt_delete_commit;
@@ -40,6 +41,7 @@ static GOptionEntry options[] = {
   { "depth", 0, 0, G_OPTION_ARG_INT, &opt_depth, "Only traverse DEPTH parents for each commit (default: -1=infinite)", "DEPTH" },
   { "delete-commit", 0, 0, G_OPTION_ARG_STRING, &opt_delete_commit, "Specify a commit to delete", "COMMIT" },
   { "keep-younger-than", 0, 0, G_OPTION_ARG_STRING, &opt_keep_younger_than, "Prune all commits older than the specified date", "DATE" },
+  { "static-deltas-only", 0, 0, G_OPTION_ARG_NONE, &opt_static_deltas_only, "Change the behavior of delete-commit and keep-younger-than to prune only static deltas" },
   { NULL }
 };
 
@@ -124,8 +126,16 @@ prune_commits_keep_younger_than_date (OstreeRepo *repo, const char *date, GCance
       commit_timestamp = ostree_commit_get_timestamp (commit);
       if (commit_timestamp < ts.tv_sec)
         {
-          if (!ostree_repo_delete_object (repo, OSTREE_OBJECT_TYPE_COMMIT, checksum, cancellable, error))
-            goto out;
+          if (opt_static_deltas_only)
+            {
+              if(!ostree_repo_prune_static_deltas (repo, checksum, cancellable, error))
+                goto out;
+            }
+          else
+            {
+              if (!ostree_repo_delete_object (repo, OSTREE_OBJECT_TYPE_COMMIT, checksum, cancellable, error))
+                goto out;
+            }
         }
     }
 
@@ -162,8 +172,13 @@ ostree_builtin_prune (int argc, char **argv, GCancellable *cancellable, GError *
           ot_util_usage_error (context, "Cannot specify both --delete-commit and --no-prune", error);
           goto out;
         }
-      if (!delete_commit (repo, opt_delete_commit, cancellable, error))
-        goto out;
+        if (opt_static_deltas_only)
+          {
+            if(!ostree_repo_prune_static_deltas (repo, opt_delete_commit, cancellable, error))
+              goto out;
+          }
+        else if (!delete_commit (repo, opt_delete_commit, cancellable, error))
+          goto out;
     }
   if (opt_keep_younger_than)
     {