check if destination is writeable

This commit is contained in:
Rob Weber 2014-10-31 09:50:37 -05:00
parent d335634618
commit 9e5873fcb7
2 changed files with 31 additions and 5 deletions

View File

@ -80,4 +80,7 @@
<string id="30086">This version of XBMC is different than the one used to create the archive</string> <string id="30086">This version of XBMC is different than the one used to create the archive</string>
<string id="30087">Compress Archives</string> <string id="30087">Compress Archives</string>
<string id="30088">Copying Zip Archive</string> <string id="30088">Copying Zip Archive</string>
<string id="30089">Write Error Detected</string>
<string id="30090">The destination may not be writeable</string>
<string id="30091">Zip archive could not be copied</string>
</strings> </strings>

View File

@ -153,7 +153,14 @@ class XbmcBackup:
self.remote_vfs.mkdir(self.remote_vfs.root_path) self.remote_vfs.mkdir(self.remote_vfs.root_path)
#create a validation file for backup rotation #create a validation file for backup rotation
self._createValidationFile() writeCheck = self._createValidationFile()
if(not writeCheck):
#we may not be able to write to this destination for some reason
shouldContinue = xbmcgui.Dialog().yesno(utils.getString(30089),utils.getString(30090), utils.getString(30044),autoclose=25000)
if(not shouldContinue):
return
utils.log(utils.getString(30051)) utils.log(utils.getString(30051))
allFiles = [] allFiles = []
@ -255,7 +262,11 @@ class XbmcBackup:
self.remote_vfs = self.saved_remote_vfs self.remote_vfs = self.saved_remote_vfs
self.progressBar.updateProgress(98, utils.getString(30088)) self.progressBar.updateProgress(98, utils.getString(30088))
self.backupFiles(fileManager.getFiles(),self.xbmc_vfs, self.remote_vfs) fileCopied = self.backupFiles(fileManager.getFiles(),self.xbmc_vfs, self.remote_vfs)
if(not fileCopied):
#zip archive copy filed, inform the user
shouldContinue = xbmcgui.Dialog().ok(utils.getString(30089),utils.getString(30090), utils.getString(30091))
#delete the temp zip file #delete the temp zip file
self.xbmc_vfs.rmfile(xbmc.translatePath("special://temp/" + zip_name)) self.xbmc_vfs.rmfile(xbmc.translatePath("special://temp/" + zip_name))
@ -419,6 +430,8 @@ class XbmcBackup:
window.setProperty(utils.__addon_id__ + ".running","") window.setProperty(utils.__addon_id__ + ".running","")
def backupFiles(self,fileList,source,dest): def backupFiles(self,fileList,source,dest):
result = True
utils.log("Writing files to: " + dest.root_path) utils.log("Writing files to: " + dest.root_path)
utils.log("Source: " + source.root_path) utils.log("Source: " + source.root_path)
for aFile in fileList: for aFile in fileList:
@ -429,12 +442,20 @@ class XbmcBackup:
dest.mkdir(dest.root_path + aFile[len(source.root_path) + 1:]) dest.mkdir(dest.root_path + aFile[len(source.root_path) + 1:])
else: else:
self._updateProgress() self._updateProgress()
wroteFile = True
if(isinstance(source,DropboxFileSystem)): if(isinstance(source,DropboxFileSystem)):
#if copying from dropbox we need the file handle, use get_file #if copying from dropbox we need the file handle, use get_file
source.get_file(aFile,dest.root_path + aFile[len(source.root_path):]) wroteFile = source.get_file(aFile,dest.root_path + aFile[len(source.root_path):])
else: else:
#copy using normal method #copy using normal method
dest.put(aFile,dest.root_path + aFile[len(source.root_path):]) wroteFile = dest.put(aFile,dest.root_path + aFile[len(source.root_path):])
#if result is still true but this file failed
if(not wroteFile and result):
result = False
return result
def _createCRC(self,string): def _createCRC(self,string):
#create hash from string #create hash from string
@ -486,7 +507,9 @@ class XbmcBackup:
vFile.write("") vFile.write("")
vFile.close() vFile.close()
self.remote_vfs.put(xbmc.translatePath(utils.data_dir() + "xbmcbackup.val"),self.remote_vfs.root_path + "xbmcbackup.val") success = self.remote_vfs.put(xbmc.translatePath(utils.data_dir() + "xbmcbackup.val"),self.remote_vfs.root_path + "xbmcbackup.val")
return success
def _checkValidationFile(self,path): def _checkValidationFile(self,path):
result = False result = False