diff options
author | Colin Walters <walters@verbum.org> | 2012-12-09 16:40:26 -0500 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2012-12-09 17:01:30 -0500 |
commit | a98e4be8ef5c57b8f79f896b7bf13142499a17c3 (patch) | |
tree | b4abbb0e4b068d6cdfa917d8eaa28c71123b8338 | |
parent | aac3668399f8058877cf21ba35617ec4cfecd500 (diff) | |
download | libgsystem-a98e4be8ef5c57b8f79f896b7bf13142499a17c3.tar.gz |
Add API to create a directory with mode
Will be used by ostree.
-rw-r--r-- | gsystem-file-utils.c | 29 | ||||
-rw-r--r-- | gsystem-file-utils.h | 5 |
2 files changed, 34 insertions, 0 deletions
diff --git a/gsystem-file-utils.c b/gsystem-file-utils.c index 82d1d6b..209f87a 100644 --- a/gsystem-file-utils.c +++ b/gsystem-file-utils.c @@ -284,6 +284,35 @@ gs_file_ensure_directory (GFile *dir, } /** + * gs_file_ensure_directory_mode: + * @dir: Path to create as directory + * @mode: Create directory with these permissions + * @cancellable: a #GCancellable + * @error: a #GError + * + * Wraps UNIX mkdir() function with support for @cancellable, and + * uses @error instead of errno. + */ +gboolean +gs_file_ensure_directory_mode (GFile *dir, + guint mode, + GCancellable *cancellable, + GError **error) +{ + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return FALSE; + + if (mkdir (gs_file_get_path_cached (dir), mode) == -1 && errno != EEXIST) + { + int errsv = errno; + g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv), + "Failed to create %s: ", gs_file_get_path_cached (dir)); + return FALSE; + } + return TRUE; +} + +/** * gs_file_load_contents_utf8: * @file: Path to file whose contents must be UTF-8 * @cancellable: diff --git a/gsystem-file-utils.h b/gsystem-file-utils.h index fc85584..93aa568 100644 --- a/gsystem-file-utils.h +++ b/gsystem-file-utils.h @@ -50,6 +50,11 @@ gboolean gs_file_ensure_directory (GFile *dir, GCancellable *cancellable, GError **error); +gboolean gs_file_ensure_directory_mode (GFile *dir, + guint mode, + GCancellable *cancellable, + GError **error); + gchar *gs_file_load_contents_utf8 (GFile *file, GCancellable *cancellable, GError **error); |