Repository: borgbackup/borg

Issue:
crash with 1.1.0b6 on borg create with --no-cache-sync
```
Local Exception
Traceback (most recent call last):
  File "borg/archiver.py", line 4063, in main
  File "borg/archiver.py", line 3991, in run
  File "borg/archiver.py", line 146, in wrapper
  File "borg/archiver.py", line 514, in do_create
  File "borg/archiver.py", line 479, in create_inner
  File "borg/archiver.py", line 579, in _process
  File "borg/archiver.py", line 579, in _process
  File "borg/archiver.py", line 579, in _process
  File "borg/archiver.py", line 579, in _process
  File "borg/archiver.py", line 579, in _process
  File "borg/archiver.py", line 579, in _process
  File "borg/archiver.py", line 579, in _process
  File "borg/archiver.py", line 557, in _process
  File "borg/archive.py", line 990, in process_file
  File "borg/archive.py", line 936, in chunk_file
  File "borg/cache.py", line 1005, in chunk_incref
  File "borg/archive.py", line 61, in update
TypeError: unsupported operand type(s) for +=: 'int' and 'NoneType'

Platform: Linux server 4.8.0-58-generic #63~16.04.1-Ubuntu SMP Mon Jun 26 18:08:51 UTC 2017 x86_64 x86_64
Linux: debian stretch/sid
Borg: 1.1.0b6  Python: CPython 3.5.3
PID: 27736  CWD: /usr/local/bin
sys.argv: ['borg-1.1', 'create', '-v', '--list', '--filter=AME', '--compression', 'auto,lzma,6',
 '--stats', '--no-cache-sync', '--chunker-params', '17,23,20,4095',
 'ssh://borg@server/./repo::myserver-2017-07-22-00:13:07', '/mnt/rootfs/',
 '--exclude-caches', ...]
SSH_ORIGINAL_COMMAND: None
```



Discussion:

Resolving patch:
diff --git a/src/borg/archive.py b/src/borg/archive.py
--- a/src/borg/archive.py
+++ b/src/borg/archive.py
@@ -936,7 +936,7 @@ def chunk_processor(data):
                 # if we created part files, we have referenced all chunks from the part files,
                 # but we also will reference the same chunks also from the final, complete file:
                 for chunk in item.chunks:
-                    cache.chunk_incref(chunk.id, stats)
+                    cache.chunk_incref(chunk.id, stats, size=chunk.size)
 
     def process_stdin(self, path, cache):
         uid, gid = 0, 0
diff --git a/src/borg/cache.py b/src/borg/cache.py
--- a/src/borg/cache.py
+++ b/src/borg/cache.py
@@ -877,12 +877,12 @@ def seen_chunk(self, id, size=None):
                             id, stored_size, size))
         return refcount
 
-    def chunk_incref(self, id, stats):
+    def chunk_incref(self, id, stats, size=None):
         if not self.txn_active:
             self.begin_txn()
-        count, size, csize = self.chunks.incref(id)
-        stats.update(size, csize, False)
-        return ChunkListEntry(id, size, csize)
+        count, _size, csize = self.chunks.incref(id)
+        stats.update(_size, csize, False)
+        return ChunkListEntry(id, _size, csize)
 
     def chunk_decref(self, id, stats, wait=True):
         if not self.txn_active:
@@ -979,7 +979,7 @@ def add_chunk(self, id, chunk, stats, overwrite=False, wait=True):
         size = len(chunk)
         refcount = self.seen_chunk(id, size)
         if refcount:
-            return self.chunk_incref(id, stats, size_=size)
+            return self.chunk_incref(id, stats, size=size)
         data = self.key.encrypt(chunk)
         csize = len(data)
         self.repository.put(id, data, wait=wait)
@@ -998,15 +998,16 @@ def seen_chunk(self, id, size=None):
             self.chunks[id] = entry._replace(size=size)
         return entry.refcount
 
-    def chunk_incref(self, id, stats, size_=None):
+    def chunk_incref(self, id, stats, size=None):
         if not self._txn_active:
             self._begin_txn()
-        count, size, csize = self.chunks.incref(id)
-        stats.update(size or size_, csize, False)
-        # When size is 0 and size_ is not given, then this chunk has not been locally visited yet (seen_chunk with
+        count, _size, csize = self.chunks.incref(id)
+        # When _size is 0 and size is not given, then this chunk has not been locally visited yet (seen_chunk with
         # size or add_chunk); we can't add references to those (size=0 is invalid) and generally don't try to.
-        assert size or size_
-        return ChunkListEntry(id, size or size_, csize)
+        size = _size or size
+        assert size
+        stats.update(size, csize, False)
+        return ChunkListEntry(id, size, csize)
 
     def chunk_decref(self, id, stats, wait=True):
         if not self._txn_active:


Test patch: