[ostree] core: Pick better names for tmpfiles if no prefix given



commit 90ccc7b2d28d0646a6dae6fc4f556687ac14d6c1
Author: Colin Walters <walters verbum org>
Date:   Fri Dec 21 11:07:50 2012 -0500

    core: Pick better names for tmpfiles if no prefix given
    
    Just makes it easier to track down where files came from.

 src/libostree/ostree-core.c |   25 ++++++++++++++++++++++++-
 1 files changed, 24 insertions(+), 1 deletions(-)
---
diff --git a/src/libostree/ostree-core.c b/src/libostree/ostree-core.c
index 6e494d4..09ce530 100644
--- a/src/libostree/ostree-core.c
+++ b/src/libostree/ostree-core.c
@@ -1260,6 +1260,29 @@ 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,
@@ -1270,7 +1293,7 @@ create_tmp_name (const char *dirpath,
   guint i;
 
   if (!prefix)
-    prefix = "tmp";
+    prefix = get_default_tmp_prefix ();
   if (!suffix)
     suffix = "tmp";
 



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