From e63560f0c43e89bbd2309462cc0078647c9854ad Mon Sep 17 00:00:00 2001 From: Rob Weber Date: Mon, 30 Dec 2019 10:09:01 -0600 Subject: [PATCH] added a clean path function and applied it to rotate backups --- resources/lib/backup.py | 4 ++-- resources/lib/vfs.py | 19 +++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/resources/lib/backup.py b/resources/lib/backup.py index 65d036f..74103f8 100644 --- a/resources/lib/backup.py +++ b/resources/lib/backup.py @@ -465,9 +465,9 @@ class XbmcBackup: if(dirs[remove_num][0].split('.')[-1] == 'zip'): # this is a file, remove it that way - self.remote_vfs.rmfile(self.remote_vfs.root_path + dirs[remove_num][0]) + self.remote_vfs.rmfile(self.remote_vfs.clean_path(self.remote_base_path) + dirs[remove_num][0]) else: - self.remote_vfs.rmdir(self.remote_vfs.root_path + dirs[remove_num][0] + "/") + self.remote_vfs.rmdir(self.remote_vfs.clean_path(self.remote_base_path) + dirs[remove_num][0] + "/") remove_num = remove_num + 1 diff --git a/resources/lib/vfs.py b/resources/lib/vfs.py index eae31a9..d0df9ac 100644 --- a/resources/lib/vfs.py +++ b/resources/lib/vfs.py @@ -17,16 +17,19 @@ class Vfs: def __init__(self, rootString): self.set_root(rootString) + def clean_path(self, path): + # fix slashes + path = path.replace("\\", "/") + + # check if trailing slash is included + if(path[-1:] != '/'): + path = path + '/' + + return path + def set_root(self, rootString): old_root = self.root_path - self.root_path = rootString - - # fix slashes - self.root_path = self.root_path.replace("\\", "/") - - # check if trailing slash is included - if(self.root_path[-1:] != "/"): - self.root_path = self.root_path + "/" + self.root_path = self.clean_path(rootString) # return the old root return old_root