Check that the backup folder is not inside the project path to be backed up
This commit is contained in:
+15
-6
@@ -526,25 +526,25 @@ class NWProject():
|
|||||||
self.theParent.makeAlert((
|
self.theParent.makeAlert((
|
||||||
"Cannot backup project because no backup path is set. "
|
"Cannot backup project because no backup path is set. "
|
||||||
"Please set a valid backup location in Tools > Preferences."
|
"Please set a valid backup location in Tools > Preferences."
|
||||||
), nwAlert.WARN)
|
), nwAlert.ERROR)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if self.projName is None or self.projName == "":
|
if self.projName is None or self.projName == "":
|
||||||
self.theParent.makeAlert((
|
self.theParent.makeAlert((
|
||||||
"Cannot backup project because no project name is set. "
|
"Cannot backup project because no project name is set. "
|
||||||
"Please set a Working Title in Project > Project Settings."
|
"Please set a Working Title in Project > Project Settings."
|
||||||
), nwAlert.WARN)
|
), nwAlert.ERROR)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if not path.isdir(self.mainConf.backupPath):
|
if not path.isdir(self.mainConf.backupPath):
|
||||||
self.theParent.makeAlert((
|
self.theParent.makeAlert((
|
||||||
"Cannot backup project because the backup path does not exist. "
|
"Cannot backup project because the backup path does not exist. "
|
||||||
"Please set a valid backup location in Tools > Preferences."
|
"Please set a valid backup location in Tools > Preferences."
|
||||||
), nwAlert.WARN)
|
), nwAlert.ERROR)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
cleanName = self.getFileSafeProjectName()
|
cleanName = self.getFileSafeProjectName()
|
||||||
baseDir = path.join(self.mainConf.backupPath, cleanName)
|
baseDir = path.abspath(path.join(self.mainConf.backupPath, cleanName))
|
||||||
if not path.isdir(baseDir):
|
if not path.isdir(baseDir):
|
||||||
try:
|
try:
|
||||||
mkdir(baseDir)
|
mkdir(baseDir)
|
||||||
@@ -556,16 +556,25 @@ class NWProject():
|
|||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
backPath = path.abspath(self.projPath)
|
||||||
|
if path.commonpath([backPath, baseDir]) == backPath:
|
||||||
|
self.theParent.makeAlert((
|
||||||
|
"Cannot backup project because the backup path is within the "
|
||||||
|
"project folder to be backed up. Please choose a different "
|
||||||
|
"backup path in Tools > Preferences."
|
||||||
|
), nwAlert.ERROR)
|
||||||
|
return False
|
||||||
|
|
||||||
archName = "Backup from %s" % formatTimeStamp(time(), fileSafe=True)
|
archName = "Backup from %s" % formatTimeStamp(time(), fileSafe=True)
|
||||||
baseName = path.join(baseDir, archName)
|
baseName = path.join(baseDir, archName)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._clearLockFile()
|
self._clearLockFile()
|
||||||
make_archive(baseName, "zip", self.projPath, ".")
|
make_archive(baseName, "zip", backPath, ".")
|
||||||
self._writeLockFile()
|
self._writeLockFile()
|
||||||
if doNotify:
|
if doNotify:
|
||||||
self.theParent.makeAlert(
|
self.theParent.makeAlert(
|
||||||
"Backup archive file written to: '%s.zip'" % path.join(cleanName, archName),
|
"Backup archive file written to: %s.zip" % path.join(cleanName, archName),
|
||||||
nwAlert.INFO
|
nwAlert.INFO
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user