[ostree] core: Use gsystem API for generating temporary names
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ostree] core: Use gsystem API for generating temporary names
- Date: Tue, 16 Jul 2013 12:57:33 +0000 (UTC)
commit 444234e7db1727c86cdd03499c232ad0f2c7cb64
Author: Colin Walters <walters verbum org>
Date: Tue Jul 16 08:50:31 2013 -0400
core: Use gsystem API for generating temporary names
Drops duplicated code.
src/libostree/ostree-core.c | 54 +------------------------------------------
1 files changed, 1 insertions(+), 53 deletions(-)
---
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c
index e6104dd..0749f04 100644
--- a/src/libostree/ostree-core.c
+++ b/src/libostree/ostree-core.c
@@ -1311,57 +1311,6 @@ ostree_create_file_from_input (GFile *dest_file,
return ret;
}
-static const char *
-get_default_tmp_prefix (void)
-{
- static char *tmpprefix = NULL;
-
- if (g_once_init_enter (&tmpprefix))
- {
- const char *prgname = g_get_prgname ();
- const char *p;
- char *prefix;
-
- p = strrchr (prgname, '/');
- if (p)
- prgname = p + 1;
-
- prefix = g_strdup_printf ("tmp-%s%u-", prgname, getuid ());
-
- g_once_init_leave (&tmpprefix, prefix);
- }
-
- return tmpprefix;
-}
-
-static char *
-create_tmp_name (const char *dirpath,
- const char *prefix,
- const char *suffix)
-{
- static const char table[] = "ABCEDEFGHIJKLMNOPQRSTUVWXYZabcedefghijklmnopqrstuvwxyz0123456789";
- GString *tmp_name = NULL;
- guint i;
-
- if (!prefix)
- prefix = get_default_tmp_prefix ();
- if (!suffix)
- suffix = "tmp";
-
- tmp_name = g_string_new (dirpath);
- g_string_append_c (tmp_name, '/');
- g_string_append (tmp_name, prefix);
- for (i = 0; i < 8; i++)
- {
- int offset = g_random_int_range (0, sizeof (table) - 1);
- g_string_append_c (tmp_name, (guint8)table[offset]);
- }
- g_string_append_c (tmp_name, '.');
- g_string_append (tmp_name, suffix);
-
- return g_string_free (tmp_name, FALSE);
-}
-
gboolean
ostree_create_temp_file_from_input (GFile *dir,
const char *prefix,
@@ -1387,8 +1336,7 @@ ostree_create_temp_file_from_input (GFile *dir,
if (g_cancellable_set_error_if_cancelled (cancellable, error))
goto out;
- possible_name = create_tmp_name (gs_file_get_path_cached (dir),
- prefix, suffix);
+ possible_name = gsystem_fileutil_gen_tmp_name (prefix, suffix);
g_clear_object (&possible_file);
possible_file = g_file_get_child (dir, possible_name);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]