Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reference linking #4463

Merged
merged 5 commits into from
Jul 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions medusa/helpers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,8 @@ def reflink_file(src_file, dest_file):
if reflink is None:
raise NotImplementedError()
reflink.reflink(src_file, dest_file)
except reflink.ReflinkImpossibleError as msg:
if msg.args[0] == 'EOPNOTSUPP':
except (reflink.ReflinkImpossibleError, IOError) as msg:
if msg.args and msg.args[0] == 'EOPNOTSUPP':
log.warning(
u'Failed to create reference link of {source} at {destination}.'
u' Error: Filesystem or OS has not implemented reflink. Copying instead', {
Expand All @@ -443,7 +443,7 @@ def reflink_file(src_file, dest_file):
}
)
copy_file(src_file, dest_file)
elif msg.args[0] == 'EXDEV':
elif msg.args and msg.args[0] == 'EXDEV':
log.warning(
u'Failed to create reference link of {source} at {destination}.'
u' Error: Can not reflink between two devices. Copying instead', {
Expand Down Expand Up @@ -471,16 +471,6 @@ def reflink_file(src_file, dest_file):
}
)
copy_file(src_file, dest_file)
except IOError as msg:
log.warning(
u'Failed to create reflink of {source} at {destination}.'
u' Error: {error!r}. Copying instead', {
'source': src_file,
'destination': dest_file,
'error': msg,
}
)
copy_file(src_file, dest_file)


def make_dirs(path):
Expand Down
20 changes: 15 additions & 5 deletions medusa/post_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,19 @@ def symlink(cur_file_path, new_file_path):
(cur_file_path, new_file_path, e), logger.ERROR)
raise EpisodePostProcessingFailedException('Unable to move and link the files to their new home')

action = {'copy': copy, 'move': move, 'hardlink': hardlink, 'symlink': symlink}.get(self.process_method)
# Subtitle action should be move in case of hardlink|symlink as downloaded subtitle is not part of torrent
subtitle_action = {'copy': copy, 'move': move, 'hardlink': move, 'symlink': move}.get(self.process_method)
def reflink(cur_file_path, new_file_path):
self.log(u'Reflink file from {0} to {1}'.format(cur_file_path, new_basename), logger.DEBUG)
try:
helpers.reflink_file(cur_file_path, new_file_path)
helpers.chmod_as_parent(new_file_path)
except (IOError, OSError) as e:
self.log(u'Unable to reflink file {0} to {1}: {2!r}'.format
(cur_file_path, new_file_path, e), logger.ERROR)
raise EpisodePostProcessingFailedException('Unable to copy the files to their new home')

action = {'copy': copy, 'move': move, 'hardlink': hardlink, 'symlink': symlink, 'reflink': reflink}.get(self.process_method)
# Subtitle action should be move in case of hardlink|symlink|reflink as downloaded subtitle is not part of torrent
subtitle_action = {'copy': copy, 'move': move, 'hardlink': move, 'symlink': move, 'reflink': move}.get(self.process_method)
self._combined_file_operation(file_path, new_path, new_basename, associated_files,
action=action, subtitle_action=subtitle_action, subtitles=subtitles)

Expand Down Expand Up @@ -1222,7 +1232,7 @@ def process(self):

try:
# do the action to the episode and associated files to the show dir
if self.process_method in ['copy', 'hardlink', 'move', 'symlink']:
if self.process_method in ['copy', 'hardlink', 'move', 'symlink', 'reflink']:
if not self.process_method == 'hardlink':
if helpers.is_file_locked(self.file_path, False):
raise EpisodePostProcessingFailedException('File is locked for reading')
Expand Down Expand Up @@ -1295,7 +1305,7 @@ def process(self):
self._run_extra_scripts(ep_obj)

if not self.nzb_name and all([app.USE_TORRENTS,
app.PROCESS_METHOD in ('hardlink', 'symlink'),
app.PROCESS_METHOD in ('hardlink', 'symlink', 'reflink'),
app.TORRENT_SEED_LOCATION]):
# Store self.info_hash and self.release_name so later we can remove from client if setting is enabled
if self.info_hash:
Expand Down
4 changes: 2 additions & 2 deletions medusa/process_tv.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def process(self, resource_name=None, force=False, is_priority=None, delete_on=F
for missedfile in self.missedfiles:
self.log('{0}'.format(missedfile), logger.WARNING)

if app.USE_TORRENTS and app.PROCESS_METHOD in ('hardlink', 'symlink') and app.TORRENT_SEED_LOCATION:
if app.USE_TORRENTS and app.PROCESS_METHOD in ('hardlink', 'symlink', 'reflink') and app.TORRENT_SEED_LOCATION:
for info_hash, release_names in list(iteritems(app.RECENTLY_POSTPROCESSED)):
if self.move_torrent(info_hash, release_names):
app.RECENTLY_POSTPROCESSED.pop(info_hash, None)
Expand Down Expand Up @@ -311,7 +311,7 @@ def process_files(self, path, force=False, is_priority=None, ignore_subs=False):
if self.video_in_rar:
video_files = set(self.video_files + self.video_in_rar)

if self.process_method in ('hardlink', 'symlink'):
if self.process_method in ('hardlink', 'symlink', 'reflink'):
process_method = self.process_method
# Move extracted video files instead of hard/softlinking them
self.process_method = 'move'
Expand Down
2 changes: 1 addition & 1 deletion medusa/server/api/v1/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ def __init__(self, args, kwargs):
self.force_replace, args = self.check_params(args, kwargs, 'force_replace', False, False, 'bool', [])
self.return_data, args = self.check_params(args, kwargs, 'return_data', False, False, 'bool', [])
self.process_method, args = self.check_params(args, kwargs, 'process_method', False, False, 'string',
['copy', 'symlink', 'hardlink', 'move'])
['copy', 'symlink', 'hardlink', 'move', 'reflink'])
self.is_priority, args = self.check_params(args, kwargs, 'is_priority', False, False, 'bool', [])
self.delete_files, args = self.check_params(args, kwargs, 'delete_files', False, False, 'bool', [])
self.failed, args = self.check_params(args, kwargs, 'failed', False, False, 'bool', [])
Expand Down