summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruen@suse.de>2010-12-04 23:05:00 +0100
committerAndreas Gruenbacher <agruen@suse.de>2010-12-04 23:05:00 +0100
commit7fae6755f4194423ba52add76f5cbdbffd26fe04 (patch)
tree1f67710556ff31cba059b084c4cdd8c1f5c8bf6a /src
parent77e15c72869033fbef27fed0856a7f251c0b3a07 (diff)
downloadpatch-7fae6755f4194423ba52add76f5cbdbffd26fe04.tar.gz
Create missing parent directories of temporary files
* src/util.c (make_tempfile): Create missing directories when necessary.
Diffstat (limited to 'src')
-rw-r--r--src/util.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index dc8d122..e03e48a 100644
--- a/src/util.c
+++ b/src/util.c
@@ -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);