diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | src/util.c | 10 |
2 files changed, 15 insertions, 0 deletions
@@ -1,3 +1,8 @@ +2010-12-04 Andreas Gruenbacher <agruen@linbit.com> + + * src/util.c (make_tempfile): Create missing directories when + necessary. + 2010-10-29 Andreas Gruenbacher <agruen@suse.de> * src/util.c: USE_XATTR is defined to 0 or 1, so we need to use #if @@ -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); |