[ostree] core: Use ot_gfile_get_path_cached() pervasively



commit a8735778f09b897330d4a48e44cb4c1e62442af5
Author: Colin Walters <walters verbum org>
Date:   Thu Nov 17 18:23:36 2011 -0500

    core: Use ot_gfile_get_path_cached() pervasively
    
    This requires no free() calls and is just better.

 src/libostree/ostree-checkout.c  |    7 +++----
 src/libostree/ostree-core.c      |    5 ++---
 src/libostree/ostree-repo-file.c |   30 ++++++++++++------------------
 src/libostree/ostree-repo.c      |   17 +++++++----------
 src/libotutil/ot-gio-utils.c     |    5 ++---
 src/libotutil/ot-variant-utils.c |    5 ++---
 src/ostree/ot-builtin-commit.c   |   10 ++++------
 src/ostree/ot-builtin-compose.c  |   14 ++++++--------
 8 files changed, 38 insertions(+), 55 deletions(-)
---
diff --git a/src/libostree/ostree-checkout.c b/src/libostree/ostree-checkout.c
index 0d58498..f992986 100644
--- a/src/libostree/ostree-checkout.c
+++ b/src/libostree/ostree-checkout.c
@@ -188,7 +188,7 @@ run_trigger (OstreeCheckout *self,
 {
   OstreeCheckoutPrivate *priv = GET_PRIVATE (self);
   gboolean ret = FALSE;
-  char *path = NULL;
+  const char *path = NULL;
   char *temp_path = NULL;
   char *rel_temp_path = NULL;
   GFile *temp_copy = NULL;
@@ -196,7 +196,7 @@ run_trigger (OstreeCheckout *self,
   GPtrArray *args = NULL;
   int estatus;
 
-  path = g_file_get_path (trigger);
+  path = ot_gfile_get_path_cached (trigger);
   basename = g_path_get_basename (path);
 
   args = g_ptr_array_new ();
@@ -217,7 +217,7 @@ run_trigger (OstreeCheckout *self,
     }
   else
     {
-      g_ptr_array_add (args, path);
+      g_ptr_array_add (args, (char*)path);
       g_ptr_array_add (args, NULL);
     }
       
@@ -239,7 +239,6 @@ run_trigger (OstreeCheckout *self,
   if (requires_chroot && temp_path)
     (void)unlink (temp_path);
     
-  g_free (path);
   g_free (basename);
   g_free (temp_path);
   g_free (rel_temp_path);
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c
index 6ce51ca..4e6fafc 100644
--- a/src/libostree/ostree-core.c
+++ b/src/libostree/ostree-core.c
@@ -462,7 +462,7 @@ ostree_pack_object (GOutputStream     *output,
                     GError          **error)
 {
   gboolean ret = FALSE;
-  char *path = NULL;
+  const char *path = NULL;
   GFileInfo *finfo = NULL;
   GFileInputStream *instream = NULL;
   gboolean pack_builder_initialized = FALSE;
@@ -471,7 +471,7 @@ ostree_pack_object (GOutputStream     *output,
   GVariant *xattrs = NULL;
   gsize bytes_written;
 
-  path = g_file_get_path (file);
+  path = ot_gfile_get_path_cached (file);
 
   finfo = g_file_query_info (file, "standard::type,standard::size,standard::is-symlink,standard::symlink-target,unix::*",
                              G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error);
@@ -590,7 +590,6 @@ ostree_pack_object (GOutputStream     *output,
   
   ret = TRUE;
  out:
-  g_free (path);
   g_clear_object (&finfo);
   g_clear_object (&instream);
   if (xattrs)
diff --git a/src/libostree/ostree-repo-file.c b/src/libostree/ostree-repo-file.c
index 8e5f0fe..2c6934a 100644
--- a/src/libostree/ostree-repo-file.c
+++ b/src/libostree/ostree-repo-file.c
@@ -106,10 +106,9 @@ ostree_repo_file_init (OstreeRepoFile *self)
 static gboolean
 set_error_noent (GFile *self, GError **error)
 {
-  char *path = g_file_get_path (self);
   g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
-               "No such file or directory: %s", path);
-  g_free (path);
+               "No such file or directory: %s",
+               ot_gfile_get_path_cached (self));
   return FALSE;
 }
 
@@ -515,13 +514,12 @@ static char *
 ostree_repo_file_get_uri (GFile *file)
 {
   OstreeRepoFile *self = OSTREE_REPO_FILE (file);
-  char *path;
+  const char *path;
   char *uri_path;
   char *ret;
 
-  path = g_file_get_path (file);
+  path = ot_gfile_get_path_cached (file);
   uri_path = g_filename_to_uri (path, NULL, NULL);
-  g_free (path);
   g_assert (g_str_has_prefix (uri_path, "file://"));
   ret = g_strconcat ("ostree://", self->commit, uri_path+strlen("file://"), NULL);
   g_free (uri_path);
@@ -609,14 +607,12 @@ ostree_repo_file_prefix_matches (GFile *parent,
 				 GFile *descendant)
 {
   const char *remainder;
-  char *parent_path;
-  char *descendant_path;
+  const char *parent_path;
+  const char *descendant_path;
 
-  parent_path = g_file_get_path (parent);
-  descendant_path = g_file_get_path (descendant);
+  parent_path = ot_gfile_get_path_cached (parent);
+  descendant_path = ot_gfile_get_path_cached (descendant);
   remainder = match_prefix (descendant_path, parent_path);
-  g_free (parent_path);
-  g_free (descendant_path);
   if (remainder != NULL && G_IS_DIR_SEPARATOR (*remainder))
     return TRUE;
   return FALSE;
@@ -627,14 +623,12 @@ ostree_repo_file_get_relative_path (GFile *parent,
 				    GFile *descendant)
 {
   const char *remainder;
-  char *parent_path;
-  char *descendant_path;
+  const char *parent_path;
+  const char *descendant_path;
 
-  parent_path = g_file_get_path (parent);
-  descendant_path = g_file_get_path (descendant);
+  parent_path = ot_gfile_get_path_cached (parent);
+  descendant_path = ot_gfile_get_path_cached (descendant);
   remainder = match_prefix (descendant_path, parent_path);
-  g_free (parent_path);
-  g_free (descendant_path);
   
   if (remainder != NULL && G_IS_DIR_SEPARATOR (*remainder))
     return g_strdup (remainder + 1);
diff --git a/src/libostree/ostree-repo.c b/src/libostree/ostree-repo.c
index 2d8e70d..dc8b0df 100644
--- a/src/libostree/ostree-repo.c
+++ b/src/libostree/ostree-repo.c
@@ -215,16 +215,15 @@ parse_rev_file (OstreeRepo     *self,
   if (g_str_has_prefix (rev, "ref: "))
     {
       GFile *ref;
-      char *ref_path;
+      const char *ref_path;
       char *ref_sha256;
       gboolean subret;
 
       ref = g_file_resolve_relative_path (priv->local_heads_dir, rev + 5);
-      ref_path = g_file_get_path (ref);
+      ref_path = ot_gfile_get_path_cached (ref);
 
       subret = parse_rev_file (self, ref_path, &ref_sha256, error);
       g_clear_object (&ref);
-      g_free (ref_path);
         
       if (!subret)
         {
@@ -263,7 +262,7 @@ ostree_repo_resolve_rev (OstreeRepo     *self,
   char *ret_rev = NULL;
   GFile *child = NULL;
   GFile *origindir = NULL;
-  char *child_path = NULL;
+  const char *child_path = NULL;
   GError *temp_error = NULL;
   GVariant *commit = NULL;
 
@@ -317,7 +316,7 @@ ostree_repo_resolve_rev (OstreeRepo     *self,
       else if (slash == NULL)
         {
           child = g_file_get_child (priv->local_heads_dir, rev);
-          child_path = g_file_get_path (child);
+          child_path = ot_gfile_get_path_cached (child);
         }
       else
         {
@@ -331,7 +330,7 @@ ostree_repo_resolve_rev (OstreeRepo     *self,
             }
           
           child = g_file_get_child (priv->remote_heads_dir, rev);
-          child_path = g_file_get_path (child);
+          child_path = ot_gfile_get_path_cached (child);
 
         }
       if (!ot_util_gfile_load_contents_utf8 (child, NULL, &ret_rev, NULL, &temp_error))
@@ -368,7 +367,6 @@ ostree_repo_resolve_rev (OstreeRepo     *self,
   g_free (tmp2);
   g_clear_object (&child);
   g_clear_object (&origindir);
-  g_free (child_path);
   g_free (ret_rev);
   return ret;
 }
@@ -1554,9 +1552,9 @@ iter_object_dir (OstreeRepo   *self,
   GError *temp_error = NULL;
   GFileEnumerator *enumerator = NULL;
   GFileInfo *file_info = NULL;
-  char *dirpath = NULL;
+  const char *dirpath = NULL;
 
-  dirpath = g_file_get_path (dir);
+  dirpath = ot_gfile_get_path_cached (dir);
 
   enumerator = g_file_enumerate_children (dir, OSTREE_GIO_FAST_QUERYINFO, 
                                           G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
@@ -1603,7 +1601,6 @@ iter_object_dir (OstreeRepo   *self,
 
   ret = TRUE;
  out:
-  g_free (dirpath);
   return ret;
 }
 
diff --git a/src/libotutil/ot-gio-utils.c b/src/libotutil/ot-gio-utils.c
index bae8037..adac61f 100644
--- a/src/libotutil/ot-gio-utils.c
+++ b/src/libotutil/ot-gio-utils.c
@@ -121,9 +121,9 @@ ot_util_read_file_noatime (GFile *file, GCancellable *cancellable, GError **erro
   GInputStream *ret = NULL;
   int fd;
   int flags = O_RDONLY;
-  char *path = NULL;
+  const char *path = NULL;
 
-  path = g_file_get_path (file);
+  path = ot_gfile_get_path_cached (file);
 #ifdef O_NOATIME
   flags |= O_NOATIME;
 #endif
@@ -137,7 +137,6 @@ ot_util_read_file_noatime (GFile *file, GCancellable *cancellable, GError **erro
   ret = (GInputStream*)g_unix_input_stream_new (fd, TRUE);
   
  out:
-  g_free (path);
   return ret;
 }
 
diff --git a/src/libotutil/ot-variant-utils.c b/src/libotutil/ot-variant-utils.c
index d450ed6..026275b 100644
--- a/src/libotutil/ot-variant-utils.c
+++ b/src/libotutil/ot-variant-utils.c
@@ -96,10 +96,10 @@ ot_util_variant_map (GFile *src,
 {
   gboolean ret = FALSE;
   GMappedFile *mfile = NULL;
-  char *path = NULL;
+  const char *path = NULL;
   GVariant *ret_variant = NULL;
 
-  path = g_file_get_path (src);
+  path = ot_gfile_get_path_cached (src);
   mfile = g_mapped_file_new (path, FALSE, error);
   if (!mfile)
     goto out;
@@ -121,6 +121,5 @@ ot_util_variant_map (GFile *src,
     g_variant_unref (ret_variant);
   if (mfile)
     g_mapped_file_unref (mfile);
-  g_free (path);
   return ret;
 }
diff --git a/src/ostree/ot-builtin-commit.c b/src/ostree/ot-builtin-commit.c
index 3d4d6b9..f12682e 100644
--- a/src/ostree/ot-builtin-commit.c
+++ b/src/ostree/ot-builtin-commit.c
@@ -82,7 +82,7 @@ find_write_child (const char *basepath,
   guint32 type;
   const char *name;
   char buf[1];
-  char *child_path = NULL;
+  const char *child_path = NULL;
   GString *child_trimmed_path = NULL;
   GFile *child = NULL;
   gsize bytes_written;
@@ -98,7 +98,7 @@ find_write_child (const char *basepath,
         goto out;
     }
 
-  child_path = g_file_get_path (child);
+  child_path = ot_gfile_get_path_cached (child);
   child_trimmed_path = g_string_new (child_path + strlen (basepath));
   if (!*(child_trimmed_path->str))
     {
@@ -122,7 +122,6 @@ find_write_child (const char *basepath,
  out:
   g_string_free (child_trimmed_path, TRUE);
   child_trimmed_path = NULL;
-  g_free (child_path);
   child_path = NULL;
   g_clear_object (&child);
   return ret;
@@ -171,16 +170,15 @@ find_thread (gpointer data)
 {
   FindThreadData *tdata = data;
   GError *error = NULL;
-  char *path;
+  const char *path;
   
-  path = g_file_get_path (tdata->dir);
+  path = ot_gfile_get_path_cached (tdata->dir);
   if (!find (path, tdata->dir, tdata->separator, tdata->out,
              tdata->cancellable, &error))
     {
       g_printerr ("%s", error->message);
       g_clear_error (&error);
     }
-  g_free (path);
   g_clear_object (&(tdata->dir));
   g_clear_object (&(tdata->out));
   return NULL;
diff --git a/src/ostree/ot-builtin-compose.c b/src/ostree/ot-builtin-compose.c
index b2cdb40..35856d0 100644
--- a/src/ostree/ot-builtin-compose.c
+++ b/src/ostree/ot-builtin-compose.c
@@ -80,8 +80,8 @@ merge_dir (GFile    *destination,
            GError  **error)
 {
   gboolean ret = FALSE;
-  char *dest_path = NULL;
-  char *src_path = NULL;
+  const char *dest_path = NULL;
+  const char *src_path = NULL;
   GError *temp_error = NULL;
   GFileInfo *src_fileinfo = NULL;
   GFileInfo *dest_fileinfo = NULL;
@@ -91,8 +91,8 @@ merge_dir (GFile    *destination,
   const char *name;
   guint32 type;
 
-  dest_path = g_file_get_path (destination);
-  src_path = g_file_get_path (src);
+  dest_path = ot_gfile_get_path_cached (destination);
+  src_path = ot_gfile_get_path_cached (src);
 
   dest_fileinfo = g_file_query_info (destination, OSTREE_GIO_FAST_QUERYINFO,
                                      G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
@@ -163,8 +163,6 @@ merge_dir (GFile    *destination,
 
   ret = TRUE;
  out:
-  g_free (dest_path);
-  g_free (src_path);
   g_clear_object (&src_fileinfo);
   g_clear_object (&dest_fileinfo);
   g_clear_object (&src_enum);
@@ -190,7 +188,7 @@ compose_branch_on_dir (OstreeRepo *repo,
   if (!ostree_repo_resolve_rev (repo, branch, FALSE, &branchrev, error))
     goto out;
   
-  destpath = g_file_get_path (destination);
+  destpath = g_strdup (ot_gfile_get_path_cached (destination));
   if (g_str_has_suffix (destpath, "/"))
     destpath[strlen (destpath) - 1] = '\0';
   branchpath = g_strconcat (destpath, "-tmp-checkout-", branchrev, NULL);
@@ -211,10 +209,10 @@ compose_branch_on_dir (OstreeRepo *repo,
  out:
   if (branchf)
     rm_rf (branchf);
+  g_free (destpath);
   g_clear_object (&enumerator);
   g_clear_object (&branchf);
   g_free (branchrev);
-  g_free (destpath);
   g_free (branchpath);
   return ret;
 }



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