[ostree] core: Clean up stale packfiles



commit 3f23ac156ae236496d0141d8d1be9ac9149180f8
Author: Colin Walters <walters verbum org>
Date:   Tue Apr 3 23:45:28 2012 -0400

    core: Clean up stale packfiles

 src/libostree/ostree-repo.c |   58 +++++++++++++++++++++++++++++++++++++++++++
 src/libostree/ostree-repo.h |    5 +++
 2 files changed, 63 insertions(+), 0 deletions(-)
---
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index 04e9f97..849af01 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -1839,6 +1839,7 @@ ostree_repo_resync_cached_remote_pack_indexes (OstreeRepo       *self,
   GFile *cache_path = NULL;
   GFile *superindex_cache_path = NULL;
   GPtrArray *index_files = NULL;
+  GPtrArray *data_files = NULL;
   GHashTable *new_pack_indexes = NULL;
   GHashTableIter hash_iter;
   gpointer key, value;
@@ -1919,6 +1920,28 @@ ostree_repo_resync_cached_remote_pack_indexes (OstreeRepo       *self,
   superindex_cache_path = g_file_get_child (cache_path, "index");
   if (!ot_util_variant_save (superindex_cache_path, superindex_variant, cancellable, error))
     goto out;
+
+  /* Now also delete stale pack files */
+
+  if (!list_files_in_dir_matching (cache_path,
+                                   "ostpack-", ".data",
+                                   &data_files, 
+                                   cancellable, error))
+    goto out;
+  
+  for (i = 0; i < data_files->len; i++)
+    {
+      GFile *data_file = data_files->pdata[i];
+
+      g_free (pack_checksum);
+      pack_checksum = get_checksum_from_pack_name (ot_gfile_get_basename_cached (data_file));
+
+      if (!g_hash_table_lookup (new_pack_indexes, pack_checksum))
+        {
+          if (!ot_gfile_unlink (data_file, cancellable, error))
+            goto out;
+        }
+    }
       
   ret = TRUE;
   ot_transfer_out_value (out_cached_indexes, &ret_cached_indexes);
@@ -1936,6 +1959,41 @@ ostree_repo_resync_cached_remote_pack_indexes (OstreeRepo       *self,
   return ret;
 }
 
+gboolean
+ostree_repo_clean_cached_remote_pack_data (OstreeRepo       *self,
+                                           const char       *remote_name,
+                                           GCancellable     *cancellable,
+                                           GError          **error)
+{
+  gboolean ret = FALSE;
+  GFile *cache_path = NULL;
+  GPtrArray *data_files = NULL;
+  guint i;
+
+  if (!ensure_remote_cache_dir (self, remote_name, &cache_path, cancellable, error))
+    goto out;
+
+  if (!list_files_in_dir_matching (cache_path,
+                                   "ostpack-", ".data",
+                                   &data_files, 
+                                   cancellable, error))
+    goto out;
+
+  for (i = 0; i < data_files->len; i++)
+    {
+      GFile *data_file = data_files->pdata[i];
+      
+      if (!ot_gfile_unlink (data_file, cancellable, error))
+        goto out;
+    }
+
+  ret = TRUE;
+ out:
+  g_clear_object (&cache_path);
+  ot_clear_ptrarray (&data_files);
+  return ret;
+}
+
 /**
  * Load the index for pack @pack_checksum from cache directory for
  * @remote_name.
diff --git a/src/libostree/ostree-repo.h b/src/libostree/ostree-repo.h
index a424496..05a916d 100644
--- a/src/libostree/ostree-repo.h
+++ b/src/libostree/ostree-repo.h
@@ -248,6 +248,11 @@ gboolean     ostree_repo_resync_cached_remote_pack_indexes (OstreeRepo       *se
                                                             GCancellable     *cancellable,
                                                             GError          **error);
 
+gboolean     ostree_repo_clean_cached_remote_pack_data (OstreeRepo       *self,
+                                                        const char       *remote_name,
+                                                        GCancellable     *cancellable,
+                                                        GError          **error);
+
 gboolean     ostree_repo_map_cached_remote_pack_index (OstreeRepo       *self,
                                                        const char       *remote_name,
                                                        const char       *pack_checksum,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]