Krolyxon
Commit 9812d60

Branches

Refs →

nsxiv9812d60

r_mkdir: don't truncate the path on error (#322)

currently, in case of error, r_mkdir will leave the path at a truncated
state.

a7d39b0ab8 is the commit that introduced this change, and in it the
error printing is moved from r_mkdir to the caller, which makes me think
it was probably intentional.

make it so that the function itself prints the error/warning
message and returns the path back to the caller unharmed.
Author
NRK
Date
2022-06-22 05:05 +0200
Parent
a67665a
Commit
9812d601c16fb243aac788abfeb9ea01a7870466

+10 −8

2 files changed

  1. M thumbs.c +1 −3
  2. M util.c +9 −5
M thumbs.c View
@@ -92,10 +92,8 @@ static void tns_cache_write(Imlib_Image im, const char *filepath, bool force)
9292 {
9393 if ((dirend = strrchr(cfile, '/')) != NULL) {
9494 *dirend = '\0';
95− if (r_mkdir(cfile) == -1) {
96− error(0, errno, "%s", cfile);
95+ if (r_mkdir(cfile) < 0)
9796 goto end;
98− }
9997 *dirend = '/';
10098 }
10199 imlib_context_set_image(im);
M util.c View
@@ -193,10 +193,11 @@ char* r_readdir(r_dir_t *rdir, bool skip_dotfiles)
193193
194194 int r_mkdir(char *path)
195195 {
196+ int rc = 0;
196197 char c, *s = path;
197198 struct stat st;
198199
199− while (*s != '\0') {
200+ while (*s != '\0' && rc == 0) {
200201 if (*s == '/') {
201202 s++;
202203 continue;
@@ -204,12 +205,15 @@ int r_mkdir(char *path)
204205 for (; *s != '\0' && *s != '/'; s++);
205206 c = *s;
206207 *s = '\0';
207− if (mkdir(path, 0755) == -1)
208− if (errno != EEXIST || stat(path, &st) == -1 || !S_ISDIR(st.st_mode))
209− return -1;
208+ if (mkdir(path, 0755) == -1) {
209+ if (errno != EEXIST || stat(path, &st) == -1 || !S_ISDIR(st.st_mode)) {
210+ error(0, errno, "%s", path);
211+ rc = -1;
212+ }
213+ }
210214 *s = c;
211215 }
212− return 0;
216+ return rc;
213217 }
214218
215219 void construct_argv(char **argv, unsigned int len, ...)