From 529a3b830db7fcb3207d7bd7a857954fe883021a Mon Sep 17 00:00:00 2001
From: Eric Torres <erictorres4@protonmail.com>
Date: Tue, 16 Apr 2019 17:13:29 -0700
Subject: [PATCH] Add snapshot_symlink property

---
 rbackup/struct/repository.py | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/rbackup/struct/repository.py b/rbackup/struct/repository.py
index 499c2de..8163067 100644
--- a/rbackup/struct/repository.py
+++ b/rbackup/struct/repository.py
@@ -151,6 +151,14 @@ class Repository(Hierarchy):
         """
         return self.path / "data"
 
+    @property
+    def snapshot_symlink(self):
+        """
+        :return: the path of the symlink pointing to the most recent snapshot
+        :rtype: path-like object
+        """
+        return self.path / "current"
+
     @property
     def snapshots(self):
         """
@@ -169,7 +177,7 @@ class Repository(Hierarchy):
         return not self.snapshots
 
     def cleanup(self, *, remove_snapshots=False, remove_repo_dir=False):
-        """Clean up any filesystem references to this repository.
+        """Remove this repository from the filesystem.
         By default, no snapshots are deleted.
 
         :param remove_snapshots: delete the data directory of this repository
@@ -188,6 +196,7 @@ class Repository(Hierarchy):
         syslog.debug("Cleaning repository data")
 
         self.metadata_path.unlink()
+        self.snapshot_symlink.unlink()
         syslog.info("Removing repository metadata")
         syslog.debug(f"Repository metadata removed: {self.metadata_path}")
 
@@ -269,13 +278,11 @@ class Repository(Hierarchy):
         :param snapshot: the snapshot to create the symlink to
         :type snapshot: Snapshot object
         """
-        snapshot_symlink = self.path / "current"
-
         try:
-            snapshot_symlink.unlink()
+            self.snapshot_symlink.unlink()
         except FileNotFoundError:
             pass
         except PermissionError as e:
             syslog.error(e)
 
-        snapshot_symlink.symlink_to(snapshot)
+        self.snapshot_symlink.symlink_to(snapshot)