diff options
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 10 |
1 files changed, 10 insertions, 0 deletions
@@ -1590,6 +1590,7 @@ int make_tempfile (char const **name, char letter, char const *real_name, int flags, mode_t mode) { + int try_makedirs_errno = ENOENT; char *template; if (real_name) @@ -1625,9 +1626,18 @@ make_tempfile (char const **name, char letter, char const *real_name, if (gen_tempname (template, 0, flags, GT_NOCREATE)) pfatal ("Can't create temporary file %s", template); + retry: fd = open (template, O_CREAT | O_EXCL | flags, mode); if (fd == -1) { + if (errno == try_makedirs_errno) + { + makedirs (template); + /* FIXME: When patch fails, this may leave around empty + directories. */ + try_makedirs_errno = 0; + goto retry; + } if (errno == EEXIST) continue; pfatal ("Can't create temporary file %s", template); |