summaryrefslogtreecommitdiff
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
parent77e15c72869033fbef27fed0856a7f251c0b3a07 (diff)
downloadpatch-7fae6755f4194423ba52add76f5cbdbffd26fe04.tar.gz
Create missing parent directories of temporary files
* src/util.c (make_tempfile): Create missing directories when necessary.
-rw-r--r--ChangeLog5
-rw-r--r--src/util.c10
2 files changed, 15 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 0f9dd53..bbe5fe7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
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);