Repository: borgbackup/borg

Issue:
port last-minute changes of 1.1.3 to master
https://github.com/borgbackup/borg/pull/3391/commits

Discussion:

Patch:
diff --git a/docs/3rd_party/README b/docs/3rd_party/README
new file mode 100644
index 00000000..1f7b9b6a
--- /dev/null
+++ b/docs/3rd_party/README
@@ -0,0 +1,5 @@
+Here we store 3rd party documentation, licenses, etc.
+
+Please note that all files inside the "borg" package directory (except the
+stuff excluded in setup.py) will be INSTALLED, so don't keep docs or licenses
+there.
diff --git a/src/borg/algorithms/blake2/COPYING b/docs/3rd_party/blake2/COPYING
similarity index 100%
rename from src/borg/algorithms/blake2/COPYING
rename to docs/3rd_party/blake2/COPYING
diff --git a/src/borg/algorithms/blake2/README.md b/docs/3rd_party/blake2/README.md
similarity index 100%
rename from src/borg/algorithms/blake2/README.md
rename to docs/3rd_party/blake2/README.md
diff --git a/src/borg/algorithms/crc32_slice_by_8.c b/src/borg/algorithms/crc32_slice_by_8.c
index b289fbb8..3ab0c840 100644
--- a/src/borg/algorithms/crc32_slice_by_8.c
+++ b/src/borg/algorithms/crc32_slice_by_8.c
@@ -332,14 +332,12 @@ uint32_t crc32_slice_by_8(const void* data, size_t length, uint32_t previousCrc3
   uint32_t crc = ~previousCrc32; // same as previousCrc32 ^ 0xFFFFFFFF
 
   const uint32_t* current;
-  const uint8_t* currentChar;
+  const uint8_t* currentChar = (const uint8_t*) data;
 
   // enabling optimization (at least -O2) automatically unrolls the inner for-loop
   const size_t Unroll = 4;
   const size_t BytesAtOnce = 8 * Unroll;
 
-  currentChar = (const uint8_t*) data;
-
   // wanted: 32 bit / 4 Byte alignment, compute leading, unaligned bytes length
   uintptr_t unaligned_length = (4 - (((uintptr_t) currentChar) & 3)) & 3;
   // process unaligned bytes, if any (standard algorithm)
diff --git a/src/borg/archiver.py b/src/borg/archiver.py
index a14d4af5..887cb772 100644
--- a/src/borg/archiver.py
+++ b/src/borg/archiver.py
@@ -3806,6 +3806,7 @@ def get_args(self, argv, cmd):
                 return forced_result
             # we only take specific options from the forced "borg serve" command:
             result.restrict_to_paths = forced_result.restrict_to_paths
+            result.restrict_to_repositories = forced_result.restrict_to_repositories
             result.append_only = forced_result.append_only
         return result
 
diff --git a/src/borg/fuse.py b/src/borg/fuse.py
index 52ed1ad6..a85684a0 100644
--- a/src/borg/fuse.py
+++ b/src/borg/fuse.py
@@ -362,7 +362,7 @@ def make_versioned_name(name, version, add_dir=False):
             return name + version_enc + ext
 
         if 'source' in item and hardlinkable(item.mode):
-            source = os.path.join(*item.source.split(os.sep)[stripped_components:])
+            source = os.sep.join(item.source.split(os.sep)[stripped_components:])
             chunks, link_target = hardlink_masters.get(item.source, (None, source))
             if link_target:
                 # Hard link was extracted previously, just link


Test patch:
diff --git a/src/borg/testsuite/archiver.py b/src/borg/testsuite/archiver.py
index a25cb5de..910b5372 100644
--- a/src/borg/testsuite/archiver.py
+++ b/src/borg/testsuite/archiver.py
@@ -3546,10 +3546,22 @@ def test_get_args():
     assert args.restrict_to_paths == ['/p1', '/p2']
     assert args.umask == 0o027
     assert args.log_level == 'info'
+    # similar, but with --restrict-to-repository
+    args = archiver.get_args(['borg', 'serve', '--restrict-to-repository=/r1', '--restrict-to-repository=/r2', ],
+                             'borg serve --info --umask=0027')
+    assert args.restrict_to_repositories == ['/r1', '/r2']
     # trying to cheat - break out of path restriction
     args = archiver.get_args(['borg', 'serve', '--restrict-to-path=/p1', '--restrict-to-path=/p2', ],
                              'borg serve --restrict-to-path=/')
     assert args.restrict_to_paths == ['/p1', '/p2']
+    # trying to cheat - break out of repository restriction
+    args = archiver.get_args(['borg', 'serve', '--restrict-to-repository=/r1', '--restrict-to-repository=/r2', ],
+                             'borg serve --restrict-to-repository=/')
+    assert args.restrict_to_repositories == ['/r1', '/r2']
+    # trying to cheat - break below repository restriction
+    args = archiver.get_args(['borg', 'serve', '--restrict-to-repository=/r1', '--restrict-to-repository=/r2', ],
+                             'borg serve --restrict-to-repository=/r1/below')
+    assert args.restrict_to_repositories == ['/r1', '/r2']
     # trying to cheat - try to execute different subcommand
     args = archiver.get_args(['borg', 'serve', '--restrict-to-path=/p1', '--restrict-to-path=/p2', ],
                              'borg init --encryption=repokey /')