diff options
author | Colin Walters <walters@verbum.org> | 2013-07-16 08:45:46 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2013-07-16 08:45:46 -0400 |
commit | 4a41cb7911ac97eeac297a3177375b8198a433d2 (patch) | |
tree | 7b7d89faf3a61e6b1ba7b2765c3f8ff1ff3dfa4f | |
parent | b5e773410cddad83b2a2aba8c7c89c59c3e32dbe (diff) | |
download | libgsystem-4a41cb7911ac97eeac297a3177375b8198a433d2.tar.gz |
fileutil: Make API to generate temporary name public
It's used by ostree core too.
-rw-r--r-- | gsystem-file-utils.c | 17 | ||||
-rw-r--r-- | gsystem-file-utils.h | 3 |
2 files changed, 16 insertions, 4 deletions
diff --git a/gsystem-file-utils.c b/gsystem-file-utils.c index 2f57efa..69a2caf 100644 --- a/gsystem-file-utils.c +++ b/gsystem-file-utils.c @@ -312,9 +312,18 @@ get_default_tmp_prefix (void) return tmpprefix; } -static char * -gen_tmp_name (const char *prefix, - const char *suffix) +/** + * gsystem_fileutil_gen_tmp_name: + * @prefix: (allow-none): String prepended to the result + * @suffix: (allow-none): String suffixed to the result + * + * Generate a name suitable for use as a temporary file. This + * function does no I/O; it is not guaranteed that a file with that + * name does not exist. + */ +char * +gsystem_fileutil_gen_tmp_name (const char *prefix, + const char *suffix) { static const char table[] = "ABCEDEFGHIJKLMNOPQRSTUVWXYZabcedefghijklmnopqrstuvwxyz0123456789"; GString *str = g_string_new (""); @@ -356,7 +365,7 @@ linkcopy_internal_attempt (GFile *src, if (g_cancellable_set_error_if_cancelled (cancellable, error)) goto out; - tmp_name = gen_tmp_name (NULL, NULL); + tmp_name = gsystem_fileutil_gen_tmp_name (NULL, NULL); tmp_dest = g_file_get_child (dest_parent, tmp_name); res = link (gs_file_get_path_cached (src), gs_file_get_path_cached (tmp_dest)); diff --git a/gsystem-file-utils.h b/gsystem-file-utils.h index b553d7f..26ee878 100644 --- a/gsystem-file-utils.h +++ b/gsystem-file-utils.h @@ -52,6 +52,9 @@ gboolean gs_file_sync_data (GFile *file, GCancellable *cancellable, GError **error); +char * gsystem_fileutil_gen_tmp_name (const char *prefix, + const char *suffix); + gboolean gs_file_create (GFile *file, int mode, GOutputStream **out_stream, |