URI: 
       Enable support for repository locking - dedup - deduplicating backup program
  HTML git clone git://bitreich.org/dedup/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/dedup/
   DIR Log
   DIR Files
   DIR Refs
   DIR Tags
   DIR README
   DIR LICENSE
       ---
   DIR commit 0c04bdbe93b0bda78e8122d1a4a418f6f2fa7ad2
   DIR parent bc78bdef16f48f02b707bce0f5989f6fcdb175ef
  HTML Author: sin <sin@2f30.org>
       Date:   Sun,  5 May 2019 20:23:38 +0100
       
       Enable support for repository locking
       
       Diffstat:
         M TODO                                |       1 -
         M dup-check.c                         |       6 ++++++
         M dup-gc.c                            |       6 ++++++
         M dup-init.c                          |       6 ++++++
         M dup-pack.c                          |       6 ++++++
         M dup-rm.c                            |       7 ++++++-
         M dup-unpack.c                        |       6 ++++++
       
       7 files changed, 36 insertions(+), 2 deletions(-)
       ---
   DIR diff --git a/TODO b/TODO
       @@ -1,5 +1,4 @@
        Use a ring buffer in the chunker (avoid memmove() call)
        pledge/unveil support
       -Use flock() to avoid corruption
        Ability to fetch key from dedicated fd so it never touches disk
        Use pread/pwrite to avoid lseek() calls
   DIR diff --git a/dup-check.c b/dup-check.c
       @@ -12,6 +12,7 @@
        #include "block.h"
        #include "config.h"
        #include "key.h"
       +#include "lock.h"
        #include "snap.h"
        
        int verbose;
       @@ -49,6 +50,7 @@ main(int argc, char *argv[])
                struct bparam bpar;
                char *keyfile = NULL;
                char *repo = ".";
       +        int lfd;
        
                ARGBEGIN {
                case 'k':
       @@ -89,6 +91,8 @@ main(int argc, char *argv[])
                             repo) >= sizeof(bpath))
                        errx(1, "snprintf: %s: path too long", bpath);
        
       +        if ((lfd = lockrepo(repo)) < 0)
       +                errx(1, "failed to lock repository");
                if (sopen(spath, S_READ, 0600, &sctx) < 0)
                        serr("sopen: %s", spath);
                if (bopen(bpath, B_READ, 0600, &bpar, &bctx) <0)
       @@ -100,6 +104,8 @@ main(int argc, char *argv[])
                        berr("bclose: %s", bpath);
                if (sclose(sctx) < 0)
                        serr("sclose: %s", spath);
       +        if (unlockrepo(lfd) < 0)
       +                errx(1, "failed to unlock repository");
                
                return 0;
        }
   DIR diff --git a/dup-gc.c b/dup-gc.c
       @@ -12,6 +12,7 @@
        #include "block.h"
        #include "config.h"
        #include "key.h"
       +#include "lock.h"
        #include "snap.h"
        
        int verbose;
       @@ -33,6 +34,7 @@ main(int argc, char *argv[])
                struct bparam bpar;
                char *keyfile = NULL;
                char *repo;
       +        int lfd;
        
                ARGBEGIN {
                case 'k':
       @@ -75,11 +77,15 @@ main(int argc, char *argv[])
                             repo, STORAGEPATH) >= sizeof(path))
                        errx(1, "snprintf: %s: path too long", path);
        
       +        if ((lfd = lockrepo(repo)) < 0)
       +                errx(1, "failed to lock repository");
                if (bopen(path, B_RDWR, 0600, &bpar, &bctx) < 0)
                        berr("bopen: %s", path);
                if (bgc(bctx) < 0)
                        berr("bgc: %s", path);
                if (bclose(bctx) < 0)
                        berr("bclose: %s", path);
       +        if (unlockrepo(lfd) < 0)
       +                errx(1, "failed to unlock repository");
                return 0;
        }
   DIR diff --git a/dup-init.c b/dup-init.c
       @@ -12,6 +12,7 @@
        #include "block.h"
        #include "config.h"
        #include "key.h"
       +#include "lock.h"
        #include "misc.h"
        #include "snap.h"
        
       @@ -35,6 +36,7 @@ main(int argc, char *argv[])
                struct bparam bpar;
                char *keyfile = NULL;
                char *repo;
       +        int lfd;
        
                bpar.calgo = bparamdef()->calgo;
                bpar.ealgo = bparamdef()->ealgo;
       @@ -91,11 +93,15 @@ main(int argc, char *argv[])
        
                if (mkdir(repo, 0700) < 0)
                        err(1, "mkdir: %s", repo);
       +        if ((lfd = lockrepo(repo)) < 0)
       +                errx(1, "failed to lock repository");
                if (mkdir(spath, 0700) < 0)
                        err(1, "mkdir: %s", spath);
                if (bcreat(bpath, 0600, &bpar, &bctx) < 0)
                        berr("bcreat: %s", bpath);
                if (bclose(bctx) < 0)
                        berr("bclose: %s", bpath);
       +        if (unlockrepo(lfd) < 0)
       +                errx(1, "failed to unlock repository");
                return 0;
        }
   DIR diff --git a/dup-pack.c b/dup-pack.c
       @@ -13,6 +13,7 @@
        #include "chunker.h"
        #include "config.h"
        #include "key.h"
       +#include "lock.h"
        #include "snap.h"
        
        int verbose;
       @@ -63,6 +64,7 @@ main(int argc, char *argv[])
                struct bparam bpar;
                char *keyfile = NULL;
                char *repo = ".";
       +        int lfd;
        
                ARGBEGIN {
                case 'k':
       @@ -103,6 +105,8 @@ main(int argc, char *argv[])
                             repo) >= sizeof(bpath))
                        errx(1, "snprintf: %s: path too long", bpath);
        
       +        if ((lfd = lockrepo(repo)) < 0)
       +                errx(1, "failed to lock repository");
                if (screat(spath, 0600, &sctx) < 0)
                        serr("screat: %s", spath);
                if (bopen(bpath, B_RDWR, 0600, &bpar, &bctx) <0)
       @@ -114,5 +118,7 @@ main(int argc, char *argv[])
                        berr("bclose: %s", bpath);
                if (sclose(sctx) < 0)
                        serr("sclose: %s", spath);
       +        if (unlockrepo(lfd) < 0)
       +                errx(1, "failed to unlock repository");
                return 0;
        }
   DIR diff --git a/dup-rm.c b/dup-rm.c
       @@ -12,6 +12,7 @@
        #include "block.h"
        #include "config.h"
        #include "key.h"
       +#include "lock.h"
        #include "snap.h"
        
        int verbose;
       @@ -49,6 +50,7 @@ main(int argc, char *argv[])
                struct bparam bpar;
                char *keyfile = NULL;
                char *repo = ".";
       +        int lfd;
        
                ARGBEGIN {
                case 'k':
       @@ -89,6 +91,8 @@ main(int argc, char *argv[])
                             repo) >= sizeof(bpath))
                        errx(1, "snprintf: %s: path too long", bpath);
        
       +        if ((lfd = lockrepo(repo)) < 0)
       +                errx(1, "failed to lock repository");
                if (sopen(spath, S_READ, 0600, &sctx) < 0)
                        serr("sopen: %s", spath);
                if (bopen(bpath, B_RDWR, 0600, &bpar, &bctx) <0)
       @@ -100,9 +104,10 @@ main(int argc, char *argv[])
                        berr("bclose: %s", bpath);
                if (sclose(sctx) < 0)
                        serr("sclose: %s", spath);
       -
                if (unlink(spath) < 0)
                        err(1, "unlink: %s", spath);
       +        if (unlockrepo(lfd) < 0)
       +                errx(1, "failed to unlock repository");
                
                return 0;
        }
   DIR diff --git a/dup-unpack.c b/dup-unpack.c
       @@ -12,6 +12,7 @@
        #include "block.h"
        #include "config.h"
        #include "key.h"
       +#include "lock.h"
        #include "misc.h"
        #include "snap.h"
        
       @@ -59,6 +60,7 @@ main(int argc, char *argv[])
                struct bparam bpar;
                char *keyfile = NULL;
                char *repo = ".";
       +        int lfd;
        
                ARGBEGIN {
                case 'k':
       @@ -99,6 +101,8 @@ main(int argc, char *argv[])
                             repo) >= sizeof(bpath))
                        errx(1, "snprintf: %s: path too long", bpath);
        
       +        if ((lfd = lockrepo(repo)) < 0)
       +                errx(1, "failed to lock repository");
                if (sopen(spath, S_READ, 0600, &sctx) < 0)
                        serr("sopen: %s", spath);
                if (bopen(bpath, B_READ, 0600, &bpar, &bctx) <0)
       @@ -110,6 +114,8 @@ main(int argc, char *argv[])
                        berr("bclose: %s", bpath);
                if (sclose(sctx) < 0)
                        serr("sclose: %s", spath);
       +        if (unlockrepo(lfd) < 0)
       +                errx(1, "failed to unlock repository");
                
                return 0;
        }