|
50 | 50 | pipeline, |
51 | 51 | ) |
52 | 52 | from os import ( |
| 53 | + curdir, |
| 54 | + pardir, |
53 | 55 | sep, |
54 | 56 | uname, |
55 | 57 | ) |
56 | 58 | from os.path import ( |
57 | | - abspath, |
58 | 59 | dirname, |
| 60 | + expanduser, |
| 61 | + isabs, |
59 | 62 | isdir, |
60 | 63 | join, |
61 | 64 | realpath, |
@@ -234,7 +237,6 @@ def isDir(directory): |
234 | 237 | def _findRoot(directory, repository): |
235 | 238 | """Find the root of the btrfs file system containing the given directory.""" |
236 | 239 | assert directory |
237 | | - assert directory == abspath(directory) |
238 | 240 |
|
239 | 241 | # Note that we have no guard here against an empty directory as input |
240 | 242 | # or later because of a dirname invocation. However, the show command |
@@ -509,7 +511,6 @@ def sync(subvolumes, src, dst): |
509 | 511 | def _restore(subvolume, src, dst, snapshots, snapshots_only): |
510 | 512 | """Restore a snapshot/subvolume by transferal from another repository.""" |
511 | 513 | snapshot = _findMostRecent(snapshots, subvolume) |
512 | | - subvolume = realpath(subvolume) |
513 | 514 |
|
514 | 515 | # In case the given source repository does not contain any snapshots |
515 | 516 | # for the given subvolume we cannot do anything but signal that to |
@@ -552,7 +553,7 @@ def restore(subvolumes, src, dst, snapshots_only=False): |
552 | 553 | snapshots = src.snapshots() |
553 | 554 |
|
554 | 555 | for subvolume in subvolumes: |
555 | | - _restore(subvolume, src, dst, snapshots, snapshots_only) |
| 556 | + _restore(realpath(subvolume), src, dst, snapshots, snapshots_only) |
556 | 557 |
|
557 | 558 |
|
558 | 559 | def _diff(snapshot, subvolume, repository): |
@@ -618,18 +619,31 @@ def _untrail(path): |
618 | 619 | return path |
619 | 620 |
|
620 | 621 |
|
| 622 | +def _relativize(path): |
| 623 | + """Adjust a relative path to make it point to the current directory.""" |
| 624 | + if expanduser(path) == path and\ |
| 625 | + not path.startswith(curdir) and\ |
| 626 | + not path.startswith(pardir) and\ |
| 627 | + not isabs(path): |
| 628 | + return join(curdir, path) |
| 629 | + |
| 630 | + return path |
| 631 | + |
| 632 | + |
621 | 633 | class RepositoryBase: |
622 | 634 | """This class represents the base class for repositories for snapshots.""" |
623 | 635 | def __init__(self, directory, filters=None, read_err=True, |
624 | 636 | remote_cmd=None): |
625 | 637 | """Initialize the object and bind it to the given directory.""" |
626 | | - # We always work with absolute paths here. |
627 | | - directory = abspath(directory) |
628 | | - |
629 | 638 | self._filters = filters |
630 | 639 | self._read_err = read_err |
631 | 640 | self._remote_cmd = remote_cmd |
632 | | - self._directory = _trail(directory) |
| 641 | + # In order to properly handle relative paths correctly we need them |
| 642 | + # to start with the system's indicator for the current directory. |
| 643 | + # TODO: We could use a better story for path handling. The main |
| 644 | + # concern are probably character based path comparisons (for |
| 645 | + # prefixes, for instance). |
| 646 | + self._directory = _trail(_relativize(directory)) |
633 | 647 |
|
634 | 648 | def snapshots(self): |
635 | 649 | """Retrieve a list of snapshots in this repository.""" |
@@ -690,7 +704,7 @@ class Repository(RepositoryBase): |
690 | 704 | def __init__(self, directory, *args, **kwargs): |
691 | 705 | """Initialize the repository, query its root in the btrfs file system.""" |
692 | 706 | super().__init__(directory, *args, **kwargs) |
693 | | - self._root = _findRoot(abspath(directory), self) |
| 707 | + self._root = _findRoot(_untrail(self._directory), self) |
694 | 708 |
|
695 | 709 |
|
696 | 710 | def snapshots(self): |
@@ -732,7 +746,7 @@ def purge(self, subvolumes, duration): |
732 | 746 | snapshots = self.snapshots() |
733 | 747 |
|
734 | 748 | for subvolume in subvolumes: |
735 | | - _purge(subvolume, self, duration, snapshots) |
| 749 | + _purge(realpath(subvolume), self, duration, snapshots) |
736 | 750 |
|
737 | 751 |
|
738 | 752 | def diff(self, snapshot, subvolume): |
|
0 commit comments