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

Workaround for issue #2674 #3151

Merged
merged 1 commit into from
Oct 14, 2018
Merged
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
Workaround for issue #2674
  • Loading branch information
permster committed Oct 6, 2018
commit 0264b1fb0dd8dfd2cd64f8340b287cb291b73914
36 changes: 26 additions & 10 deletions headphones/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -825,9 +825,11 @@ def smartMove(src, dest, delete=True):

source_dir = os.path.dirname(src)
filename = os.path.basename(src)
source_path = os.path.join(source_dir, filename)
dest_path = os.path.join(dest, filename)

if os.path.isfile(os.path.join(dest, filename)):
logger.info('Destination file exists: %s', os.path.join(dest, filename))
if os.path.isfile(dest_path):
logger.info('Destination file exists: %s', dest_path)
title = os.path.splitext(filename)[0]
ext = os.path.splitext(filename)[1]
i = 1
Expand All @@ -845,15 +847,29 @@ def smartMove(src, dest, delete=True):
src.decode(headphones.SYS_ENCODING, 'replace'), e)
break

try:
if delete:
shutil.move(os.path.join(source_dir, filename), os.path.join(dest, filename))
else:
shutil.copy(os.path.join(source_dir, filename), os.path.join(dest, filename))
if delete:
try:
logger.info('Moving "%s" to "%s"', source_path, dest_path)
shutil.move(source_path, dest_path)
except Exception as e:
exists = os.path.exists(dest_path)
if exists and os.path.getsize(source_path) == os.path.getsize(dest_path):
logger.warn('Successfully moved file "%s", but something went wrong: %s',
filename.decode(headphones.SYS_ENCODING, 'replace'), e)
os.unlink(source_path)
else:
# remove faultly copied file
if exists:
os.unlink(dest_path)
raise
else:
try:
logger.info('Copying "%s" to "%s"', source_path, dest_path)
shutil.copy(source_path, dest_path)
return True
except Exception as e:
logger.warn('Error moving file %s: %s', filename.decode(headphones.SYS_ENCODING, 'replace'),
e)
except Exception as e:
logger.warn('Error copying file %s: %s', filename.decode(headphones.SYS_ENCODING, 'replace'),
e)


def walk_directory(basedir, followlinks=True):
Expand Down