This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch master
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=16f696213370484cc1930071a31481bd7dc87262

commit 16f696213370484cc1930071a31481bd7dc87262
Author: Guillem Jover <[email protected]>
AuthorDate: Sun Dec 29 03:49:38 2019 +0100

    libdpkg: Add new atomic file flag to create the base path when missing
---
 debian/changelog       | 1 +
 lib/dpkg/atomic-file.c | 8 ++++++++
 lib/dpkg/atomic-file.h | 1 +
 3 files changed, 10 insertions(+)

diff --git a/debian/changelog b/debian/changelog
index d005a956e..644593e5e 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -131,6 +131,7 @@ dpkg (1.20.0) UNRELEASED; urgency=medium
     - start-stop-daemon: Close the notification socket in the child.
     - libdpkg: Fix memory leaks in zlib and bz2 decompression functions.
     - libdpkg: Add new dir_make_path() and dir_make_path_parent() functions.
+    - libdpkg: Add new atomic file flag to create the base path when missing.
   * Build system:
     - Bump minimal Perl version to 5.24.1.
     - Add a serial versioning to the m4 files.
diff --git a/lib/dpkg/atomic-file.c b/lib/dpkg/atomic-file.c
index 20b1fb37e..be7a33ef5 100644
--- a/lib/dpkg/atomic-file.c
+++ b/lib/dpkg/atomic-file.c
@@ -30,6 +30,7 @@
 
 #include <dpkg/i18n.h>
 #include <dpkg/dpkg.h>
+#include <dpkg/dir.h>
 #include <dpkg/atomic-file.h>
 
 #define ATOMIC_FILE_NEW_EXT "-new"
@@ -53,6 +54,13 @@ void
 atomic_file_open(struct atomic_file *file)
 {
        file->fp = fopen(file->name_new, "w");
+       if (file->fp == NULL && file->flags & ATOMIC_FILE_MKPATH) {
+               if (dir_make_path_parent(file->name, 0755) < 0)
+                       ohshite(_("cannot create base directory for %s"),
+                               file->name);
+
+               file->fp = fopen(file->name_new, "w");
+       }
        if (file->fp == NULL)
                ohshite(_("unable to create new file '%.250s'"),
                        file->name_new);
diff --git a/lib/dpkg/atomic-file.h b/lib/dpkg/atomic-file.h
index 50c1b7ed8..2fd13b758 100644
--- a/lib/dpkg/atomic-file.h
+++ b/lib/dpkg/atomic-file.h
@@ -35,6 +35,7 @@ DPKG_BEGIN_DECLS
 
 enum atomic_file_flags {
        ATOMIC_FILE_BACKUP      = DPKG_BIT(0),
+       ATOMIC_FILE_MKPATH      = DPKG_BIT(1),
 };
 
 struct atomic_file {

-- 
Dpkg.Org's dpkg

Reply via email to