The following commit has been merged in the master branch:
commit fc6fef6d8369fa682f5980fece9f0e481f3c2e15
Author: Guillem Jover <[email protected]>
Date:   Thu Jul 8 07:48:31 2010 +0200

    dpkg-divert: Refactor writable directory check into a new function

diff --git a/src/divertcmd.c b/src/divertcmd.c
index 3991181..6e559c9 100644
--- a/src/divertcmd.c
+++ b/src/divertcmd.c
@@ -155,12 +155,26 @@ file_stat(struct file *f)
                f->stat_state = file_stat_nofile;
 }
 
-static bool
-check_rename(struct file *src, struct file *dst)
+static void
+check_writable_dir(struct file *f)
 {
        struct varbuf tmpname = VARBUF_INIT;
        int tmpfd;
 
+       varbufprintf(&tmpname, "%s%s", f->name, ".dpkg-divert.tmp");
+
+       tmpfd = creat(tmpname.buf, 0600);
+       if (tmpfd < 0)
+               ohshite(_("error checking '%s'"), f->name);
+       close(tmpfd);
+       unlink(tmpname.buf);
+
+       varbuf_destroy(&tmpname);
+}
+
+static bool
+check_rename(struct file *src, struct file *dst)
+{
        file_stat(src);
 
        /* If the source file is not present and we are not going to do
@@ -179,26 +193,8 @@ check_rename(struct file *src, struct file *dst)
         * succeeds, we assume a writable filesystem.
         */
 
-       varbufprintf(&tmpname, "%s%s", src->name, ".dpkg-divert.tmp");
-
-       tmpfd = creat(tmpname.buf, 0600);
-       if (tmpfd >= 0) {
-               close(tmpfd);
-               unlink(tmpname.buf);
-       } else
-               ohshite(_("error checking '%s'"), src->name);
-
-       varbufreset(&tmpname);
-       varbufprintf(&tmpname, "%s%s", dst->name, ".dpkg-divert.tmp");
-
-       tmpfd = creat(tmpname.buf, 0600);
-       if (tmpfd >= 0) {
-               close(tmpfd);
-               unlink(tmpname.buf);
-       } else
-               ohshite(_("error checking '%s'"), dst->name);
-
-       varbuf_destroy(&tmpname);
+       check_writable_dir(src);
+       check_writable_dir(dst);
 
        if (src->stat_state == file_stat_valid &&
            dst->stat_state == file_stat_valid &&

-- 
dpkg's main repository


-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to