From b875a11d244cb630d1503a117323bc8e88649988 Mon Sep 17 00:00:00 2001 From: ampli Date: Thu, 23 May 2024 18:37:50 +0300 Subject: [PATCH] xdg.c: make_dirpath(): Add error message if cannot create directory --- link-parser/lg_xdg.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/link-parser/lg_xdg.c b/link-parser/lg_xdg.c index 531a53ae1..955efc48d 100644 --- a/link-parser/lg_xdg.c +++ b/link-parser/lg_xdg.c @@ -108,12 +108,23 @@ static bool make_dirpath(const char *path) if (is_sep(p[-1])) continue; // Ignore directory separator sequences *p = '\0'; // Now dir is the path up to this point //prt_error("DEBUG: mkdir: '%s'\n", dir); - mkdir(dir, S_IRWXU); // Try to create the directory - if (stat(dir, &sb) != 0 || !S_ISDIR(sb.st_mode)) + if (mkdir(dir, S_IRWXU) == -1) { - prt_error("Error: Cannot create directory '%s'\n", dir); - free(dir); - return false; + int save_errno = errno; + if (errno == EEXIST) + { + if (stat(dir, &sb) != 0 || !S_ISDIR(sb.st_mode)) + goto mkdir_error; + errno = 0; + } +mkdir_error: + if (errno != 0) + { + prt_error("Error: Cannot create directory '%s': %s.\n", + dir, strerror(save_errno)); + free(dir); + return false; + } } *p = sep; }