Simplify linking

Thanks @mano3m
This commit is contained in:
Ruud
2013-08-24 14:03:17 +02:00
parent 08554889fd
commit 8e9e7b49ea
2 changed files with 19 additions and 17 deletions
+3 -3
View File
@@ -120,10 +120,10 @@ config = [{
{
'name': 'file_action',
'label': 'Torrent File Action',
'default': 'move',
'default': 'link',
'type': 'dropdown',
'values': [('Move', 'move'), ('Copy', 'copy'), ('Hard link', 'hardlink'), ('Move & Sym link', 'move_symlink')],
'description': 'Define which kind of file operation you want to use for torrents. Before you start using <a href="http://en.wikipedia.org/wiki/Hard_link">hard links</a> or <a href="http://en.wikipedia.org/wiki/Sym_link">sym links</a>, PLEASE read about their possible drawbacks.',
'values': [('Link', 'link'), ('Copy', 'copy'), ('Move', 'move')],
'description': '<strong>Link</strong> or <strong>Copy</strong> after downloading completed (and allow for seeding), or <strong>Move</strong> after seeding completed. Link first tries <a href="http://en.wikipedia.org/wiki/Hard_link">hard link</a>, then <a href="http://en.wikipedia.org/wiki/Sym_link">sym link</a> and falls back to Copy.',
'advanced': True,
},
{
+16 -14
View File
@@ -548,21 +548,23 @@ Remove it if you want it to be renamed (again, or at least let it try again)
try:
if forcemove:
shutil.move(old, dest)
elif self.conf('file_action') == 'hardlink':
try:
link(old, dest)
except:
log.error('Couldn\'t hardlink file "%s" to "%s". Copying instead. Error: %s. ', (old, dest, traceback.format_exc()))
shutil.copy(old, dest)
elif self.conf('file_action') == 'copy':
shutil.copy(old, dest)
elif self.conf('file_action') == 'move_symlink':
shutil.move(old, dest)
elif self.conf('file_action') == 'link':
# First try to hardlink
try:
symlink(dest, old)
log.debug('Hardlinking file "%s" to "%s"...', (old, dest))
link(old, dest)
except:
log.error('Couldn\'t symlink file "%s" to "%s". Copying the file back. Error: %s. ', (old, dest, traceback.format_exc()))
shutil.copy(dest, old)
# Try to simlink next
log.debug('Couldn\'t hardlink file "%s" to "%s". Simlinking instead. Error: %s. ', (old, dest, traceback.format_exc()))
shutil.copy(old, dest)
try:
symlink(dest, old + '.link')
os.unlink(old)
os.rename(old + '.link', old)
except:
log.error('Couldn\'t symlink file "%s" to "%s". Copied instead. Error: %s. ', (old, dest, traceback.format_exc()))
else:
shutil.move(old, dest)
@@ -767,10 +769,10 @@ Remove it if you want it to be renamed (again, or at least let it try again)
for item in scan_items:
# Ask the renamer to scan the item
if item['scan']:
if item['pause'] and self.conf('file_action') == 'move_symlink':
if item['pause'] and self.conf('file_action') == 'link':
fireEvent('download.pause', item = item, pause = True, single = True)
fireEvent('renamer.scan', download_info = item)
if item['pause'] and self.conf('file_action') == 'move_symlink':
if item['pause'] and self.conf('file_action') == 'link':
fireEvent('download.pause', item = item, pause = False, single = True)
if item['process_complete']:
#First make sure the files were succesfully processed
@@ -829,6 +831,6 @@ Remove it if you want it to be renamed (again, or at least let it try again)
def statusInfoComplete(self, item):
return item['id'] and item['downloader'] and item['folder']
def movieInFromFolder(self, movie_folder):
return movie_folder and self.conf('from') in movie_folder or not movie_folder