diff options
author | Colin Walters <walters@verbum.org> | 2017-05-16 10:51:40 -0400 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2017-05-16 18:39:19 +0000 |
commit | 9380dbb14d29de77a9fdd0b7bd7ff63bb0e0d441 (patch) | |
tree | 2e61a7ab93469c4bfb8c06be673d295a588386bd /src/libotutil/ot-fs-utils.c | |
parent | 90cd7f72344fc84da9d1f73189bdeebdcc4596aa (diff) | |
download | ostree-9380dbb14d29de77a9fdd0b7bd7ff63bb0e0d441.tar.gz |
lib: Add "open dfd iter handling noent" helper, port tree-wide
Follow up to a previous patch that addressed a double-close; I
realized we already had a helper for doing "open dfd iter, do nothing
if we get ENOENT". Raise it to libotuil, and port all consumers.
Closes: #863
Approved by: jlebon
Diffstat (limited to 'src/libotutil/ot-fs-utils.c')
-rw-r--r-- | src/libotutil/ot-fs-utils.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/libotutil/ot-fs-utils.c b/src/libotutil/ot-fs-utils.c index 8ba2cffb..529077fb 100644 --- a/src/libotutil/ot-fs-utils.c +++ b/src/libotutil/ot-fs-utils.c @@ -172,6 +172,31 @@ ot_openat_ignore_enoent (int dfd, return ret; } +/* Like glnx_dirfd_iterator_init_at(), but if %ENOENT, then set + * @out_exists to %FALSE, and return successfully. + */ +gboolean +ot_dfd_iter_init_allow_noent (int dfd, + const char *path, + GLnxDirFdIterator *dfd_iter, + gboolean *out_exists, + GError **error) +{ + glnx_fd_close int fd = glnx_opendirat_with_errno (dfd, path, TRUE); + if (fd < 0) + { + if (errno != ENOENT) + return glnx_throw_errno_prefix (error, "opendirat"); + *out_exists = FALSE; + return TRUE; + } + if (!glnx_dirfd_iterator_init_take_fd (fd, dfd_iter, error)) + return FALSE; + fd = -1; + *out_exists = TRUE; + return TRUE; +} + GBytes * ot_file_mapat_bytes (int dfd, const char *path, |