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
This commit is contained in:
Colin Walters authored and Atomic Bot committed 2017-05-16 18:39:19 +00:00
1 parent 90cd7f7234
commit 9380dbb14d
7 files changed
+112 -131

No files matched your search

+25
View File
@@ -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,
+7
View File
@@ -21,6 +21,7 @@
#pragma once
#include "ot-unix-utils.h"
#include "libglnx.h"
G_BEGIN_DECLS
@@ -53,6 +54,12 @@ gboolean ot_openat_ignore_enoent (int dfd,
int *out_fd,
GError **error);
gboolean ot_dfd_iter_init_allow_noent (int dfd,
const char *path,
GLnxDirFdIterator *dfd_iter,
gboolean *out_exists,
GError **error);
GBytes *ot_file_mapat_bytes (int dfd,
const char *path,
GError **error);