check that path is within root folder of set

This commit is contained in:
Rob Weber 2019-08-22 13:07:03 -05:00
parent 061fd3efed
commit 3ee2cb0414
2 changed files with 17 additions and 7 deletions

View File

@ -531,4 +531,8 @@ msgstr ""
msgctxt "#30135" msgctxt "#30135"
msgid "Add Include Folder" msgid "Add Include Folder"
msgstr ""
msgctxt "#30136"
msgid "Path must be within root folder"
msgstr "" msgstr ""

View File

@ -78,6 +78,9 @@ class AdvancedBackupEditor:
def _cleanPath(self,root,path): def _cleanPath(self,root,path):
return path[len(root)-1:] return path[len(root)-1:]
def _validatePath(self,root,path):
return path.startswith(root)
def createSet(self): def createSet(self):
backupSet = None backupSet = None
@ -127,13 +130,16 @@ class AdvancedBackupEditor:
#add a folder, will equal root if cancel is hit #add a folder, will equal root if cancel is hit
addFolder = self.dialog.browse(type=0,heading=utils.getString(30120),shares='files',defaultt=backupSet['root']) addFolder = self.dialog.browse(type=0,heading=utils.getString(30120),shares='files',defaultt=backupSet['root'])
#cannot add root as an exclusion if(addFolder.startswith(rootPath)):
if(optionSelected == 0 and addFolder != backupSet['root']): #cannot add root as an exclusion
backupSet['dirs'].append({"path":addFolder,"type":"exclude"}) if(optionSelected == 0 and addFolder != backupSet['root']):
elif(optionSelected == 1): backupSet['dirs'].append({"path":addFolder,"type":"exclude"})
#can add root as inclusion elif(optionSelected == 1):
backupSet['dirs'].append({"path":addFolder,"type":"include","recurse":True}) #can add root as inclusion
backupSet['dirs'].append({"path":addFolder,"type":"include","recurse":True})
else:
#folder must be under root folder
self.dialog.ok(utils.getString(30117), utils.getString(30136),rootPath)
elif(optionSelected == 2): elif(optionSelected == 2):
self.dialog.ok(utils.getString(30121),utils.getString(30130),backupSet['root']) self.dialog.ok(utils.getString(30121),utils.getString(30130),backupSet['root'])
elif(optionSelected > 2): elif(optionSelected > 2):