2
2
mirror of https://github.com/octoleo/restic.git synced 2024-11-23 05:12:10 +00:00
restic/internal
Alexander Neumann 83eb075e3a Resolve name collisions
At the moment when two items to be saved have the same directory name,
restic only saves the first one to the repo. Let's say we have a
structure like this:

    dir1
    └── subdir
        └── file
    dir2
    └── subdir
        └── file

When restic is run on `dir1/subdir` and `dir2/subdir`, it will only save
the first `subdir`:

    $ restic backup dir1/subdir dir2/subdir
    [...]

    $ restic ls -l latest
    drwxr-xr-x  1000   100      0 2017-08-27 20:56:39 /subdir
    -rw-r--r--  1000   100     17 2017-08-27 20:56:39 /subdir/file

That's obviously a bad thing, caused by an early decision to strip the
full path to the files/dirs to save and only leave the last directory.

This commit partly resolves this by handling colliding names and
resolving the conflicts. Restic will now append a counter to the file
(`-123`) until the conflict is resolved. So in the example above, we'll
end up with the following structure:

    $ restic ls -l latest
    drwxr-xr-x  1000   100      0 2017-08-27 20:56:39 /subdir
    -rw-r--r--  1000   100     17 2017-08-27 20:56:39 /subdir/file
    drwxr-xr-x  1000   100      0 2017-08-27 20:56:46 /subdir-1
    -rw-r--r--  1000   100     17 2017-08-27 20:56:46 /subdir-1/file

This partly addresses #549 and closes #1179.

At first I thought that the obvious correction would be to archive the
full path. But it turns out that collisions may still occur: Suppose you
have a file named `foo` in the current directory, and the parent directory
also contains a file `foo`. Archiving these with restic also causes a
collision, since restic strips the `../` from the first file:

    $ restic backup ../foo foo

This also happens with `tar`, which does not handle the collision and
will happily archive two files called `foo`.

So, the best way forward is to handle name collisions and archive the
whole path. The latter will be tackled in a separate PR.
2017-09-05 21:47:02 +02:00
..
archiver Resolve name collisions 2017-09-05 21:47:02 +02:00
backend Merge pull request #1182 from restic/fix-1167 2017-08-28 21:13:24 +02:00
checker Move restic package to internal/restic 2017-07-24 17:43:32 +02:00
crypto internal/crypto: small simplifications 2017-08-29 00:30:06 +02:00
debug Run goimports 2017-07-23 14:21:03 +02:00
errors Moves files 2017-07-23 14:19:13 +02:00
filter Smarter filter when children won't match 2017-08-16 15:25:02 +02:00
fs Run goimports 2017-07-23 14:21:03 +02:00
fuse Move restic package to internal/restic 2017-07-24 17:43:32 +02:00
hashing Moves files 2017-07-23 14:19:13 +02:00
index Move restic package to internal/restic 2017-07-24 17:43:32 +02:00
list Move restic package to internal/restic 2017-07-24 17:43:32 +02:00
migrations Move restic package to internal/restic 2017-07-24 17:43:32 +02:00
mock Move restic package to internal/restic 2017-07-24 17:43:32 +02:00
options Run goimports 2017-07-23 14:21:03 +02:00
pack Move restic package to internal/restic 2017-07-24 17:43:32 +02:00
pipe Run goimports 2017-07-23 14:21:03 +02:00
repository Move restic package to internal/restic 2017-07-24 17:43:32 +02:00
restic Merge pull request #1044 from lloeki/982-improve-restore 2017-09-04 21:51:12 +02:00
test internal: check error before deferring file Close() 2017-08-13 19:28:13 +02:00
walk Move restic package to internal/restic 2017-07-24 17:43:32 +02:00
worker Run goimports 2017-07-23 14:21:03 +02:00