diff options
author | Philip Withnall <withnall@endlessm.com> | 2017-09-26 12:55:39 +0100 |
---|---|---|
committer | Philip Withnall <withnall@endlessm.com> | 2017-09-26 15:08:04 +0100 |
commit | e30154431d7eea6397e5502b175ba3b50330140f (patch) | |
tree | 79a0cfb620375c85c3efd9f97b100f91ce8d5605 /glnx-shutil.c | |
parent | 32a4293101ffe6f7dcbcf2856849b3549d468ea1 (diff) | |
download | libglnx-e30154431d7eea6397e5502b175ba3b50330140f.tar.gz |
shutil: Fix assertion failure in glnx_shutil_mkdir_p_at()
If the directory for @dfd is deleted after being opened,
glnx_shutil_mkdir_p_at() would fail with an assertion failure. Fix that,
and make it return an ENOENT error instead.
Add a unit test.
Signed-off-by: Philip Withnall <withnall@endlessm.com>
Reviewed-by: Colin Walters <walters@verbum.org>
Reviewed-by: Jonathan Lebon <jlebon@redhat.com>
https://github.com/ostreedev/ostree/issues/1215
Diffstat (limited to 'glnx-shutil.c')
-rw-r--r-- | glnx-shutil.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/glnx-shutil.c b/glnx-shutil.c index 9124d7a..8438b5d 100644 --- a/glnx-shutil.c +++ b/glnx-shutil.c @@ -148,7 +148,13 @@ mkdir_p_at_internal (int dfd, g_assert (!did_recurse); lastslash = strrchr (path, '/'); - g_assert (lastslash != NULL); + if (lastslash == NULL) + { + /* This can happen if @dfd was deleted between being opened and + * passed to mkdir_p_at_internal(). */ + return glnx_throw_errno_prefix (error, "mkdir(%s)", path); + } + /* Note we can mutate the buffer as we dup'd it */ *lastslash = '\0'; @@ -187,6 +193,9 @@ mkdir_p_at_internal (int dfd, * directory fd @dfd. * * See also glnx_ensure_dir() for a non-recursive version. + * + * This will return %G_IO_ERROR_NOT_FOUND if @dfd has been deleted since being + * opened. It may return other errors from mkdirat() in other situations. */ gboolean glnx_shutil_mkdir_p_at (int dfd, |