diff options
author | Colin Walters <walters@verbum.org> | 2013-08-30 12:11:48 -0400 |
---|---|---|
committer | Colin Walters <walters@verbum.org> | 2013-08-30 12:12:12 -0400 |
commit | 1c1a7c15029176928534d28fb1fb5f17adf7c776 (patch) | |
tree | d6c225dedb5830a3afe46edf025981196dcefe5e | |
parent | 042d5a0eceb6701525b55126c29bea7067e7ec65 (diff) | |
download | libgsystem-1c1a7c15029176928534d28fb1fb5f17adf7c776.tar.gz |
fileutil: New gs_file_lchown() API
Needed for ostree to chown symbolic links.
-rw-r--r-- | gsystem-file-utils.c | 72 | ||||
-rw-r--r-- | gsystem-file-utils.h | 6 |
2 files changed, 60 insertions, 18 deletions
diff --git a/gsystem-file-utils.c b/gsystem-file-utils.c index 5ed6ed1..babae9d 100644 --- a/gsystem-file-utils.c +++ b/gsystem-file-utils.c @@ -937,6 +937,38 @@ gs_file_unlink (GFile *path, return TRUE; } +static gboolean +chown_internal (GFile *path, + gboolean dereference_links, + 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 + if (dereference_links) + res = chown (gs_file_get_path_cached (path), owner, group); + else + res = lchown (gs_file_get_path_cached (path), owner, group); + while (G_UNLIKELY (res != 0 && errno == EINTR)); + + if (res < 0) + { + _set_error_from_errno (error); + goto out; + } + + ret = TRUE; + out: + return ret; +} + /** * gs_file_chown: * @path: Path to file @@ -956,25 +988,29 @@ gs_file_chown (GFile *path, 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) - { - _set_error_from_errno (error); - goto out; - } + return chown_internal (path, TRUE, owner, group, cancellable, error); +} - ret = TRUE; - out: - return ret; +/** + * gs_file_lchown: + * @path: Path to file + * @owner: UNIX owner + * @group: UNIX group + * @cancellable: a #GCancellable + * @error: a #GError + * + * Merely wraps UNIX lchown(). + * + * Returns: %TRUE on success, %FALSE on error + */ +gboolean +gs_file_lchown (GFile *path, + guint32 owner, + guint32 group, + GCancellable *cancellable, + GError **error) +{ + return chown_internal (path, FALSE, owner, group, cancellable, error); } /** diff --git a/gsystem-file-utils.h b/gsystem-file-utils.h index aae9944..6075e60 100644 --- a/gsystem-file-utils.h +++ b/gsystem-file-utils.h @@ -111,6 +111,12 @@ gboolean gs_file_chown (GFile *path, GCancellable *cancellable, GError **error); +gboolean gs_file_lchown (GFile *path, + guint32 owner, + guint32 group, + GCancellable *cancellable, + GError **error); + gboolean gs_file_chmod (GFile *path, guint mode, GCancellable *cancellable, |