From 2eb4bcc28202d66eac0978d46abfdec1d3c15fe6 Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Thu, 5 Dec 2024 12:05:59 +0000
Subject: [PATCH] glnx-shutil: Cope with ENOENT even after recursing to create
 parents

If we try to create `link/content` where `link` is a dangling symlink,
recursing to create `link` will succeed (mkdirat fails with EEXIST,
which is explicitly ignored), but then mkdirat for `link/content` will
still fail. Fail gracefully instead of crashing out with an assertion
failure.

Resolves: GNOME/libglnx#1
Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 glnx-shutil.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/glnx-shutil.c b/glnx-shutil.c
index 5ebe7f888..5a6fd7cec 100644
--- a/glnx-shutil.c
+++ b/glnx-shutil.c
@@ -149,12 +149,10 @@ mkdir_p_at_internal (int              dfd,
  again:
   if (mkdirat (dfd, path, mode) == -1)
     {
-      if (errno == ENOENT)
+      if (errno == ENOENT && !did_recurse)
         {
           char *lastslash;
 
-          g_assert (!did_recurse);
-
           lastslash = strrchr (path, '/');
           if (lastslash == NULL)
             {
-- 
GitLab