[libgsystem] Add API to create a directory with mode
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgsystem] Add API to create a directory with mode
- Date: Sun, 9 Dec 2012 22:02:07 +0000 (UTC)
commit a98e4be8ef5c57b8f79f896b7bf13142499a17c3
Author: Colin Walters <walters verbum org>
Date: Sun Dec 9 16:40:26 2012 -0500
Add API to create a directory with mode
Will be used by ostree.
gsystem-file-utils.c | 29 +++++++++++++++++++++++++++++
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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]