Repository: borgbackup/borg

Issue:
borg-mount misses files that can be extracted through borg-extract
See jborg/attic#382

Reproduced this one with borg 1.0.5.  The order of the paths in `borg create` matters.  Notice the discrepancy between `borg mount` and `borg list` for archive `repo::2` in this example.

```
(borg-env) askalski@meki:~$ borg -V
borg 1.0.5
(borg-env) askalski@meki:~$ mkdir /tmp/issue382
(borg-env) askalski@meki:~$ cd /tmp/issue382
(borg-env) askalski@meki:/tmp/issue382$ mkdir -p fs/mnt mnt fakemount repo
(borg-env) askalski@meki:/tmp/issue382$ echo hello > fakemount/README
(borg-env) askalski@meki:/tmp/issue382$ sshfs localhost:/tmp/issue382/fakemount fs/mnt

(borg-env) askalski@meki:/tmp/issue382$ borg init -e none repo
(borg-env) askalski@meki:/tmp/issue382$ borg create --one-file-system repo::1 fs fs/mnt
(borg-env) askalski@meki:/tmp/issue382$ borg create --one-file-system repo::2 fs/mnt fs
(borg-env) askalski@meki:/tmp/issue382$ borg mount repo mnt

(borg-env) askalski@meki:/tmp/issue382$ find mnt -ls
        1      0 drwxr-xr-x   1 askalski askalski        0 Jul  8 19:31 mnt
        2      0 drwxr-xr-x   1 askalski askalski        0 Jul  8 19:31 mnt/1
  1000000      0 drwxrwxr-x   1 askalski askalski        0 Jul  8 19:30 mnt/1/fs
  1000097      0 drwxrwxr-x   1 askalski askalski        0 Jul  8 19:30 mnt/1/fs/mnt
  1000194      0 -rw-rw-r--   1 askalski askalski        6 Jul  8 19:30 mnt/1/fs/mnt/README
        3      0 drwxr-xr-x   1 askalski askalski        0 Jul  8 19:31 mnt/2
  1000577      0 drwxrwxr-x   1 askalski askalski        0 Jul  8 19:30 mnt/2/fs

(borg-env) askalski@meki:/tmp/issue382$ borg list repo::1
drwxrwxr-x askalski askalski        0 Fri, 2016-07-08 19:30:01 fs
drwxrwxr-x askalski askalski        0 Fri, 2016-07-08 19:30:10 fs/mnt
-rw-rw-r-- askalski askalski        6 Fri, 2016-07-08 19:30:10 fs/mnt/README

(borg-env) askalski@meki:/tmp/issue382$ borg list repo::2
drwxrwxr-x askalski askalski        0 Fri, 2016-07-08 19:30:10 fs/mnt
-rw-rw-r-- askalski askalski        6 Fri, 2016-07-08 19:30:10 fs/mnt/README
drwxrwxr-x askalski askalski        0 Fri, 2016-07-08 19:30:01 fs

(borg-env) askalski@meki:/tmp/issue382$ fusermount -u fs/mnt 
(borg-env) askalski@meki:/tmp/issue382$ fusermount -u mnt
```



Discussion:
Hiding somewhere in here https://github.com/borgbackup/borg/blob/1.0-maint/borg/fuse.py#L71

From a quick look I would say that this is the part where it goes wrong: https://github.com/borgbackup/borg/blob/1.0-maint/borg/fuse.py#L103 creating a inode for "fs" due to "fs/mnt" being processed "fs" / "mnt".  That inode is then replaced later by the explicit "fs" item IMHO.

I guess it should try _find_inode first before allocating a new one. Going to try that.


Resolving patch:
diff --git a/borg/fuse.py b/borg/fuse.py
--- a/borg/fuse.py
+++ b/borg/fuse.py
@@ -76,6 +76,16 @@ def process_archive(self, archive, prefix=[]):
             data = self.key.decrypt(key, chunk)
             unpacker.feed(data)
             for item in unpacker:
+                try:
+                    # This can happen if an archive was created with a command line like
+                    # $ borg create ... dir1/file dir1
+                    # In this case the code below will have created a default_dir inode for dir1 already.
+                    inode = self._find_inode(item[b'path'], prefix)
+                except KeyError:
+                    pass
+                else:
+                    self.items[inode] = item
+                    continue
                 segments = prefix + os.fsencode(os.path.normpath(item[b'path'])).split(b'/')
                 del item[b'path']
                 num_segments = len(segments)


Test patch: