mirror of
https://github.com/clinton-hall/nzbToMedia.git
synced 2025-08-21 05:43:16 -07:00
add error handling to cleandir to handle "read only" files. Fixes #445
This commit is contained in:
parent
44c6b3b1ef
commit
35450fefe2
1 changed files with 23 additions and 2 deletions
|
@ -543,10 +543,28 @@ def getDirs(section, subsection):
|
|||
|
||||
return list(set(to_return))
|
||||
|
||||
def onerror(func, path, exc_info):
|
||||
"""
|
||||
Error handler for ``shutil.rmtree``.
|
||||
|
||||
If the error is due to an access error (read only file)
|
||||
it attempts to add write permission and then retries.
|
||||
|
||||
If the error is for another reason it re-raises the error.
|
||||
|
||||
Usage : ``shutil.rmtree(path, onerror=onerror)``
|
||||
"""
|
||||
if not os.access(path, os.W_OK):
|
||||
# Is the error an access error ?
|
||||
os.chmod(path, stat.S_IWUSR)
|
||||
func(path)
|
||||
else:
|
||||
raise
|
||||
|
||||
def rmDir(dirName):
|
||||
logger.info("Deleting %s" % (dirName))
|
||||
try:
|
||||
shutil.rmtree(dirName, True)
|
||||
shutil.rmtree(dirName, onerror=onerror)
|
||||
except:
|
||||
logger.error("Unable to delete folder %s" % (dirName))
|
||||
|
||||
|
@ -569,7 +587,10 @@ def cleanDir(path, section, subsection):
|
|||
'CLEANDIRS')
|
||||
|
||||
logger.info("Directory %s has been processed, removing ..." % (path), 'CLEANDIRS')
|
||||
shutil.rmtree(path)
|
||||
try:
|
||||
shutil.rmtree(path, onerror=onerror)
|
||||
except:
|
||||
logger.error("Unable to delete directory %s" % (dirName))
|
||||
|
||||
def create_torrent_class(clientAgent):
|
||||
# Hardlink solution for Torrents
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue