Skip to content
Snippets Groups Projects
Commit e16bdc7e authored by Colin Walters's avatar Colin Walters
Browse files

Merge branch 'shutil-rm-rf-errprefix' into 'master'

shutil: Prefix error with path in rm_rf()

See merge request GNOME/libglnx!4
parents 1e9b3083 b1cb19b6
No related branches found
No related tags found
No related merge requests found
...@@ -24,8 +24,23 @@ ...@@ -24,8 +24,23 @@
#include <glnx-shutil.h> #include <glnx-shutil.h>
#include <glnx-errors.h> #include <glnx-errors.h>
#include <glnx-fdio.h>
#include <glnx-local-alloc.h> #include <glnx-local-alloc.h>
static gboolean
unlinkat_allow_noent (int dfd,
const char *path,
int flags,
GError **error)
{
if (unlinkat (dfd, path, flags) == -1)
{
if (errno != ENOENT)
return glnx_throw_errno_prefix (error, "unlinkat(%s)", path);
}
return TRUE;
}
static gboolean static gboolean
glnx_shutil_rm_rf_children (GLnxDirFdIterator *dfd_iter, glnx_shutil_rm_rf_children (GLnxDirFdIterator *dfd_iter,
GCancellable *cancellable, GCancellable *cancellable,
...@@ -51,16 +66,13 @@ glnx_shutil_rm_rf_children (GLnxDirFdIterator *dfd_iter, ...@@ -51,16 +66,13 @@ glnx_shutil_rm_rf_children (GLnxDirFdIterator *dfd_iter,
if (!glnx_shutil_rm_rf_children (&child_dfd_iter, cancellable, error)) if (!glnx_shutil_rm_rf_children (&child_dfd_iter, cancellable, error))
return FALSE; return FALSE;
if (unlinkat (dfd_iter->fd, dent->d_name, AT_REMOVEDIR) == -1) if (!glnx_unlinkat (dfd_iter->fd, dent->d_name, AT_REMOVEDIR, error))
return glnx_throw_errno_prefix (error, "unlinkat"); return FALSE;
} }
else else
{ {
if (unlinkat (dfd_iter->fd, dent->d_name, 0) == -1) if (!unlinkat_allow_noent (dfd_iter->fd, dent->d_name, 0, error))
{ return FALSE;
if (errno != ENOENT)
return glnx_throw_errno_prefix (error, "unlinkat");
}
} }
} }
...@@ -86,7 +98,6 @@ glnx_shutil_rm_rf_at (int dfd, ...@@ -86,7 +98,6 @@ glnx_shutil_rm_rf_at (int dfd,
{ {
dfd = glnx_dirfd_canonicalize (dfd); dfd = glnx_dirfd_canonicalize (dfd);
/* With O_NOFOLLOW first */ /* With O_NOFOLLOW first */
glnx_autofd int target_dfd = glnx_autofd int target_dfd =
openat (dfd, path, O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW); openat (dfd, path, O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_CLOEXEC | O_NOFOLLOW);
...@@ -100,8 +111,8 @@ glnx_shutil_rm_rf_at (int dfd, ...@@ -100,8 +111,8 @@ glnx_shutil_rm_rf_at (int dfd,
} }
else if (errsv == ENOTDIR || errsv == ELOOP) else if (errsv == ENOTDIR || errsv == ELOOP)
{ {
if (unlinkat (dfd, path, 0) != 0) if (!glnx_unlinkat (dfd, path, 0, error))
return glnx_throw_errno_prefix (error, "unlinkat"); return FALSE;
} }
else else
return glnx_throw_errno_prefix (error, "open(%s)", path); return glnx_throw_errno_prefix (error, "open(%s)", path);
...@@ -113,13 +124,10 @@ glnx_shutil_rm_rf_at (int dfd, ...@@ -113,13 +124,10 @@ glnx_shutil_rm_rf_at (int dfd,
return FALSE; return FALSE;
if (!glnx_shutil_rm_rf_children (&dfd_iter, cancellable, error)) if (!glnx_shutil_rm_rf_children (&dfd_iter, cancellable, error))
return FALSE; return glnx_prefix_error (error, "Removing %s", path);
if (unlinkat (dfd, path, AT_REMOVEDIR) == -1) if (!unlinkat_allow_noent (dfd, path, AT_REMOVEDIR, error))
{ return FALSE;
if (errno != ENOENT)
return glnx_throw_errno_prefix (error, "unlinkat");
}
} }
return TRUE; return TRUE;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment