core: Use ot_gfile_get_path_cached() pervasively
This requires no free() calls and is just better.
This commit is contained in:
parent
8a24861763
commit
a8735778f0
|
|
@ -188,7 +188,7 @@ run_trigger (OstreeCheckout *self,
|
||||||
{
|
{
|
||||||
OstreeCheckoutPrivate *priv = GET_PRIVATE (self);
|
OstreeCheckoutPrivate *priv = GET_PRIVATE (self);
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
char *path = NULL;
|
const char *path = NULL;
|
||||||
char *temp_path = NULL;
|
char *temp_path = NULL;
|
||||||
char *rel_temp_path = NULL;
|
char *rel_temp_path = NULL;
|
||||||
GFile *temp_copy = NULL;
|
GFile *temp_copy = NULL;
|
||||||
|
|
@ -196,7 +196,7 @@ run_trigger (OstreeCheckout *self,
|
||||||
GPtrArray *args = NULL;
|
GPtrArray *args = NULL;
|
||||||
int estatus;
|
int estatus;
|
||||||
|
|
||||||
path = g_file_get_path (trigger);
|
path = ot_gfile_get_path_cached (trigger);
|
||||||
basename = g_path_get_basename (path);
|
basename = g_path_get_basename (path);
|
||||||
|
|
||||||
args = g_ptr_array_new ();
|
args = g_ptr_array_new ();
|
||||||
|
|
@ -217,7 +217,7 @@ run_trigger (OstreeCheckout *self,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
g_ptr_array_add (args, path);
|
g_ptr_array_add (args, (char*)path);
|
||||||
g_ptr_array_add (args, NULL);
|
g_ptr_array_add (args, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -239,7 +239,6 @@ run_trigger (OstreeCheckout *self,
|
||||||
if (requires_chroot && temp_path)
|
if (requires_chroot && temp_path)
|
||||||
(void)unlink (temp_path);
|
(void)unlink (temp_path);
|
||||||
|
|
||||||
g_free (path);
|
|
||||||
g_free (basename);
|
g_free (basename);
|
||||||
g_free (temp_path);
|
g_free (temp_path);
|
||||||
g_free (rel_temp_path);
|
g_free (rel_temp_path);
|
||||||
|
|
|
||||||
|
|
@ -462,7 +462,7 @@ ostree_pack_object (GOutputStream *output,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
char *path = NULL;
|
const char *path = NULL;
|
||||||
GFileInfo *finfo = NULL;
|
GFileInfo *finfo = NULL;
|
||||||
GFileInputStream *instream = NULL;
|
GFileInputStream *instream = NULL;
|
||||||
gboolean pack_builder_initialized = FALSE;
|
gboolean pack_builder_initialized = FALSE;
|
||||||
|
|
@ -471,7 +471,7 @@ ostree_pack_object (GOutputStream *output,
|
||||||
GVariant *xattrs = NULL;
|
GVariant *xattrs = NULL;
|
||||||
gsize bytes_written;
|
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::*",
|
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);
|
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, cancellable, error);
|
||||||
|
|
@ -590,7 +590,6 @@ ostree_pack_object (GOutputStream *output,
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
out:
|
out:
|
||||||
g_free (path);
|
|
||||||
g_clear_object (&finfo);
|
g_clear_object (&finfo);
|
||||||
g_clear_object (&instream);
|
g_clear_object (&instream);
|
||||||
if (xattrs)
|
if (xattrs)
|
||||||
|
|
|
||||||
|
|
@ -106,10 +106,9 @@ ostree_repo_file_init (OstreeRepoFile *self)
|
||||||
static gboolean
|
static gboolean
|
||||||
set_error_noent (GFile *self, GError **error)
|
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,
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
|
||||||
"No such file or directory: %s", path);
|
"No such file or directory: %s",
|
||||||
g_free (path);
|
ot_gfile_get_path_cached (self));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -515,13 +514,12 @@ static char *
|
||||||
ostree_repo_file_get_uri (GFile *file)
|
ostree_repo_file_get_uri (GFile *file)
|
||||||
{
|
{
|
||||||
OstreeRepoFile *self = OSTREE_REPO_FILE (file);
|
OstreeRepoFile *self = OSTREE_REPO_FILE (file);
|
||||||
char *path;
|
const char *path;
|
||||||
char *uri_path;
|
char *uri_path;
|
||||||
char *ret;
|
char *ret;
|
||||||
|
|
||||||
path = g_file_get_path (file);
|
path = ot_gfile_get_path_cached (file);
|
||||||
uri_path = g_filename_to_uri (path, NULL, NULL);
|
uri_path = g_filename_to_uri (path, NULL, NULL);
|
||||||
g_free (path);
|
|
||||||
g_assert (g_str_has_prefix (uri_path, "file://"));
|
g_assert (g_str_has_prefix (uri_path, "file://"));
|
||||||
ret = g_strconcat ("ostree://", self->commit, uri_path+strlen("file://"), NULL);
|
ret = g_strconcat ("ostree://", self->commit, uri_path+strlen("file://"), NULL);
|
||||||
g_free (uri_path);
|
g_free (uri_path);
|
||||||
|
|
@ -609,14 +607,12 @@ ostree_repo_file_prefix_matches (GFile *parent,
|
||||||
GFile *descendant)
|
GFile *descendant)
|
||||||
{
|
{
|
||||||
const char *remainder;
|
const char *remainder;
|
||||||
char *parent_path;
|
const char *parent_path;
|
||||||
char *descendant_path;
|
const char *descendant_path;
|
||||||
|
|
||||||
parent_path = g_file_get_path (parent);
|
parent_path = ot_gfile_get_path_cached (parent);
|
||||||
descendant_path = g_file_get_path (descendant);
|
descendant_path = ot_gfile_get_path_cached (descendant);
|
||||||
remainder = match_prefix (descendant_path, parent_path);
|
remainder = match_prefix (descendant_path, parent_path);
|
||||||
g_free (parent_path);
|
|
||||||
g_free (descendant_path);
|
|
||||||
if (remainder != NULL && G_IS_DIR_SEPARATOR (*remainder))
|
if (remainder != NULL && G_IS_DIR_SEPARATOR (*remainder))
|
||||||
return TRUE;
|
return TRUE;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
@ -627,14 +623,12 @@ ostree_repo_file_get_relative_path (GFile *parent,
|
||||||
GFile *descendant)
|
GFile *descendant)
|
||||||
{
|
{
|
||||||
const char *remainder;
|
const char *remainder;
|
||||||
char *parent_path;
|
const char *parent_path;
|
||||||
char *descendant_path;
|
const char *descendant_path;
|
||||||
|
|
||||||
parent_path = g_file_get_path (parent);
|
parent_path = ot_gfile_get_path_cached (parent);
|
||||||
descendant_path = g_file_get_path (descendant);
|
descendant_path = ot_gfile_get_path_cached (descendant);
|
||||||
remainder = match_prefix (descendant_path, parent_path);
|
remainder = match_prefix (descendant_path, parent_path);
|
||||||
g_free (parent_path);
|
|
||||||
g_free (descendant_path);
|
|
||||||
|
|
||||||
if (remainder != NULL && G_IS_DIR_SEPARATOR (*remainder))
|
if (remainder != NULL && G_IS_DIR_SEPARATOR (*remainder))
|
||||||
return g_strdup (remainder + 1);
|
return g_strdup (remainder + 1);
|
||||||
|
|
|
||||||
|
|
@ -215,16 +215,15 @@ parse_rev_file (OstreeRepo *self,
|
||||||
if (g_str_has_prefix (rev, "ref: "))
|
if (g_str_has_prefix (rev, "ref: "))
|
||||||
{
|
{
|
||||||
GFile *ref;
|
GFile *ref;
|
||||||
char *ref_path;
|
const char *ref_path;
|
||||||
char *ref_sha256;
|
char *ref_sha256;
|
||||||
gboolean subret;
|
gboolean subret;
|
||||||
|
|
||||||
ref = g_file_resolve_relative_path (priv->local_heads_dir, rev + 5);
|
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);
|
subret = parse_rev_file (self, ref_path, &ref_sha256, error);
|
||||||
g_clear_object (&ref);
|
g_clear_object (&ref);
|
||||||
g_free (ref_path);
|
|
||||||
|
|
||||||
if (!subret)
|
if (!subret)
|
||||||
{
|
{
|
||||||
|
|
@ -263,7 +262,7 @@ ostree_repo_resolve_rev (OstreeRepo *self,
|
||||||
char *ret_rev = NULL;
|
char *ret_rev = NULL;
|
||||||
GFile *child = NULL;
|
GFile *child = NULL;
|
||||||
GFile *origindir = NULL;
|
GFile *origindir = NULL;
|
||||||
char *child_path = NULL;
|
const char *child_path = NULL;
|
||||||
GError *temp_error = NULL;
|
GError *temp_error = NULL;
|
||||||
GVariant *commit = NULL;
|
GVariant *commit = NULL;
|
||||||
|
|
||||||
|
|
@ -317,7 +316,7 @@ ostree_repo_resolve_rev (OstreeRepo *self,
|
||||||
else if (slash == NULL)
|
else if (slash == NULL)
|
||||||
{
|
{
|
||||||
child = g_file_get_child (priv->local_heads_dir, rev);
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|
@ -331,7 +330,7 @@ ostree_repo_resolve_rev (OstreeRepo *self,
|
||||||
}
|
}
|
||||||
|
|
||||||
child = g_file_get_child (priv->remote_heads_dir, rev);
|
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))
|
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_free (tmp2);
|
||||||
g_clear_object (&child);
|
g_clear_object (&child);
|
||||||
g_clear_object (&origindir);
|
g_clear_object (&origindir);
|
||||||
g_free (child_path);
|
|
||||||
g_free (ret_rev);
|
g_free (ret_rev);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
@ -1554,9 +1552,9 @@ iter_object_dir (OstreeRepo *self,
|
||||||
GError *temp_error = NULL;
|
GError *temp_error = NULL;
|
||||||
GFileEnumerator *enumerator = NULL;
|
GFileEnumerator *enumerator = NULL;
|
||||||
GFileInfo *file_info = 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,
|
enumerator = g_file_enumerate_children (dir, OSTREE_GIO_FAST_QUERYINFO,
|
||||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||||
|
|
@ -1603,7 +1601,6 @@ iter_object_dir (OstreeRepo *self,
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
out:
|
out:
|
||||||
g_free (dirpath);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -121,9 +121,9 @@ ot_util_read_file_noatime (GFile *file, GCancellable *cancellable, GError **erro
|
||||||
GInputStream *ret = NULL;
|
GInputStream *ret = NULL;
|
||||||
int fd;
|
int fd;
|
||||||
int flags = O_RDONLY;
|
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
|
#ifdef O_NOATIME
|
||||||
flags |= O_NOATIME;
|
flags |= O_NOATIME;
|
||||||
#endif
|
#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);
|
ret = (GInputStream*)g_unix_input_stream_new (fd, TRUE);
|
||||||
|
|
||||||
out:
|
out:
|
||||||
g_free (path);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -96,10 +96,10 @@ ot_util_variant_map (GFile *src,
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
GMappedFile *mfile = NULL;
|
GMappedFile *mfile = NULL;
|
||||||
char *path = NULL;
|
const char *path = NULL;
|
||||||
GVariant *ret_variant = 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);
|
mfile = g_mapped_file_new (path, FALSE, error);
|
||||||
if (!mfile)
|
if (!mfile)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
@ -121,6 +121,5 @@ ot_util_variant_map (GFile *src,
|
||||||
g_variant_unref (ret_variant);
|
g_variant_unref (ret_variant);
|
||||||
if (mfile)
|
if (mfile)
|
||||||
g_mapped_file_unref (mfile);
|
g_mapped_file_unref (mfile);
|
||||||
g_free (path);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ find_write_child (const char *basepath,
|
||||||
guint32 type;
|
guint32 type;
|
||||||
const char *name;
|
const char *name;
|
||||||
char buf[1];
|
char buf[1];
|
||||||
char *child_path = NULL;
|
const char *child_path = NULL;
|
||||||
GString *child_trimmed_path = NULL;
|
GString *child_trimmed_path = NULL;
|
||||||
GFile *child = NULL;
|
GFile *child = NULL;
|
||||||
gsize bytes_written;
|
gsize bytes_written;
|
||||||
|
|
@ -98,7 +98,7 @@ find_write_child (const char *basepath,
|
||||||
goto out;
|
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));
|
child_trimmed_path = g_string_new (child_path + strlen (basepath));
|
||||||
if (!*(child_trimmed_path->str))
|
if (!*(child_trimmed_path->str))
|
||||||
{
|
{
|
||||||
|
|
@ -122,7 +122,6 @@ find_write_child (const char *basepath,
|
||||||
out:
|
out:
|
||||||
g_string_free (child_trimmed_path, TRUE);
|
g_string_free (child_trimmed_path, TRUE);
|
||||||
child_trimmed_path = NULL;
|
child_trimmed_path = NULL;
|
||||||
g_free (child_path);
|
|
||||||
child_path = NULL;
|
child_path = NULL;
|
||||||
g_clear_object (&child);
|
g_clear_object (&child);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
@ -171,16 +170,15 @@ find_thread (gpointer data)
|
||||||
{
|
{
|
||||||
FindThreadData *tdata = data;
|
FindThreadData *tdata = data;
|
||||||
GError *error = NULL;
|
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,
|
if (!find (path, tdata->dir, tdata->separator, tdata->out,
|
||||||
tdata->cancellable, &error))
|
tdata->cancellable, &error))
|
||||||
{
|
{
|
||||||
g_printerr ("%s", error->message);
|
g_printerr ("%s", error->message);
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
}
|
}
|
||||||
g_free (path);
|
|
||||||
g_clear_object (&(tdata->dir));
|
g_clear_object (&(tdata->dir));
|
||||||
g_clear_object (&(tdata->out));
|
g_clear_object (&(tdata->out));
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
||||||
|
|
@ -80,8 +80,8 @@ merge_dir (GFile *destination,
|
||||||
GError **error)
|
GError **error)
|
||||||
{
|
{
|
||||||
gboolean ret = FALSE;
|
gboolean ret = FALSE;
|
||||||
char *dest_path = NULL;
|
const char *dest_path = NULL;
|
||||||
char *src_path = NULL;
|
const char *src_path = NULL;
|
||||||
GError *temp_error = NULL;
|
GError *temp_error = NULL;
|
||||||
GFileInfo *src_fileinfo = NULL;
|
GFileInfo *src_fileinfo = NULL;
|
||||||
GFileInfo *dest_fileinfo = NULL;
|
GFileInfo *dest_fileinfo = NULL;
|
||||||
|
|
@ -91,8 +91,8 @@ merge_dir (GFile *destination,
|
||||||
const char *name;
|
const char *name;
|
||||||
guint32 type;
|
guint32 type;
|
||||||
|
|
||||||
dest_path = g_file_get_path (destination);
|
dest_path = ot_gfile_get_path_cached (destination);
|
||||||
src_path = g_file_get_path (src);
|
src_path = ot_gfile_get_path_cached (src);
|
||||||
|
|
||||||
dest_fileinfo = g_file_query_info (destination, OSTREE_GIO_FAST_QUERYINFO,
|
dest_fileinfo = g_file_query_info (destination, OSTREE_GIO_FAST_QUERYINFO,
|
||||||
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS,
|
||||||
|
|
@ -163,8 +163,6 @@ merge_dir (GFile *destination,
|
||||||
|
|
||||||
ret = TRUE;
|
ret = TRUE;
|
||||||
out:
|
out:
|
||||||
g_free (dest_path);
|
|
||||||
g_free (src_path);
|
|
||||||
g_clear_object (&src_fileinfo);
|
g_clear_object (&src_fileinfo);
|
||||||
g_clear_object (&dest_fileinfo);
|
g_clear_object (&dest_fileinfo);
|
||||||
g_clear_object (&src_enum);
|
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))
|
if (!ostree_repo_resolve_rev (repo, branch, FALSE, &branchrev, error))
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
destpath = g_file_get_path (destination);
|
destpath = g_strdup (ot_gfile_get_path_cached (destination));
|
||||||
if (g_str_has_suffix (destpath, "/"))
|
if (g_str_has_suffix (destpath, "/"))
|
||||||
destpath[strlen (destpath) - 1] = '\0';
|
destpath[strlen (destpath) - 1] = '\0';
|
||||||
branchpath = g_strconcat (destpath, "-tmp-checkout-", branchrev, NULL);
|
branchpath = g_strconcat (destpath, "-tmp-checkout-", branchrev, NULL);
|
||||||
|
|
@ -211,10 +209,10 @@ compose_branch_on_dir (OstreeRepo *repo,
|
||||||
out:
|
out:
|
||||||
if (branchf)
|
if (branchf)
|
||||||
rm_rf (branchf);
|
rm_rf (branchf);
|
||||||
|
g_free (destpath);
|
||||||
g_clear_object (&enumerator);
|
g_clear_object (&enumerator);
|
||||||
g_clear_object (&branchf);
|
g_clear_object (&branchf);
|
||||||
g_free (branchrev);
|
g_free (branchrev);
|
||||||
g_free (destpath);
|
|
||||||
g_free (branchpath);
|
g_free (branchpath);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue