diff options
author | Colin Walters <walters@verbum.org> | 2013-01-06 06:42:04 -0500 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2013-01-06 06:42:04 -0500 |
commit | fe898ee93bdc8a625c460876c8b49428c8977219 (patch) | |
tree | 77e9f9b737538e477de3e44000728cd3ccc34915 | |
parent | b4e8a2ae8684fab55efe74a7fd4b872c934475fd (diff) | |
download | libgsystem-fe898ee93bdc8a625c460876c8b49428c8977219.tar.gz |
fileutils: Add chown() wrapper
And while we're here, fix up chmod() wrapper to handle EINTR, and not
prefix the error message (since the others don't).
-rw-r--r-- | gsystem-file-utils.c | 62 | ||||
-rw-r--r-- | gsystem-file-utils.h | 6 |
2 files changed, 63 insertions, 5 deletions
diff --git a/gsystem-file-utils.c b/gsystem-file-utils.c index 6d53a6b..8e5b4dc 100644 --- a/gsystem-file-utils.c +++ b/gsystem-file-utils.c @@ -480,6 +480,48 @@ gs_file_unlink (GFile *path, } /** + * gs_file_chown: + * @path: Path to file + * @owner: UNIX owner + * @group: UNIX group + * @cancellable: a #GCancellable + * @error: a #GError + * + * Merely wraps UNIX chown(). + * + * Returns: %TRUE on success, %FALSE on error + */ +gboolean +gs_file_chown (GFile *path, + guint32 owner, + guint32 group, + GCancellable *cancellable, + GError **error) +{ + gboolean ret = FALSE; + int res; + + if (g_cancellable_set_error_if_cancelled (cancellable, error)) + return FALSE; + + do + res = chown (gs_file_get_path_cached (path), owner, group); + while (G_UNLIKELY (res != 0 && errno == EINTR)); + + if (res < 0) + { + int errsv = errno; + g_set_error_literal (error, G_IO_ERROR, g_io_error_from_errno (errsv), + g_strerror (errsv)); + goto out; + } + + ret = TRUE; + out: + return ret; +} + +/** * gs_file_chmod: * @path: Path to file * @mode: UNIX mode @@ -496,17 +538,27 @@ gs_file_chmod (GFile *path, GCancellable *cancellable, GError **error) { + gboolean ret = FALSE; + int res; + if (g_cancellable_set_error_if_cancelled (cancellable, error)) return FALSE; - if (chmod (gs_file_get_path_cached (path), mode) < 0) + do + res = chmod (gs_file_get_path_cached (path), mode); + while (G_UNLIKELY (res != 0 && errno == EINTR)); + + if (res < 0) { int errsv = errno; - g_set_error (error, G_IO_ERROR, g_io_error_from_errno (errsv), - "Failed to chmod %s: ", gs_file_get_path_cached (path)); - return FALSE; + g_set_error_literal (error, G_IO_ERROR, g_io_error_from_errno (errsv), + g_strerror (errsv)); + goto out; } - return TRUE; + + ret = TRUE; + out: + return ret; } /** diff --git a/gsystem-file-utils.h b/gsystem-file-utils.h index abd8e7c..b88ce31 100644 --- a/gsystem-file-utils.h +++ b/gsystem-file-utils.h @@ -58,6 +58,12 @@ gboolean gs_file_unlink (GFile *path, GCancellable *cancellable, GError **error); +gboolean gs_file_chown (GFile *path, + guint32 owner, + guint32 group, + GCancellable *cancellable, + GError **error); + gboolean gs_file_chmod (GFile *path, guint mode, GCancellable *cancellable, |