Skip to content

Commit

Permalink
bugfix: move does copy by default #56
Browse files Browse the repository at this point in the history
- set hardlink=False as default parameter of the move function
- have a try / except close that makes a copy instead in case of failure
- explicitly pass hardlink=True in the backup function in main
- ... that involves passing hardling around in Biblio.move(..., hardlink=..) and Biblio.rename_entry_files
  • Loading branch information
perrette committed May 10, 2023
1 parent c5599e4 commit 3945a05
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions papers/bib.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ def __init__(self, db=None, filesdir=None, key_field='ID', nameformat=NAMEFORMAT
self.relative_to = os.path.sep if relative_to is None else relative_to
self.sort()

def move(self, file, newfile, copy=False):
return _move(file, newfile, copy=copy, dryrun=papers.config.DRYRUN)
def move(self, file, newfile, copy=False, hardlink=False):
return _move(file, newfile, copy=copy, dryrun=papers.config.DRYRUN, hardlink=hardlink)

@property
def entries(self):
Expand Down Expand Up @@ -499,7 +499,7 @@ def check_duplicates(self, key=None, eq=None, mode='i'):
self.sort() # keep sorted


def rename_entry_files(self, e, copy=False, formatter=None, relative_to=None):
def rename_entry_files(self, e, copy=False, formatter=None, relative_to=None, hardlink=False):
""" Rename files
See `papers.filename.Format` class and REAMDE.md for infos.
Expand All @@ -526,7 +526,7 @@ def rename_entry_files(self, e, copy=False, formatter=None, relative_to=None):
if not os.path.exists(file):
raise ValueError(file+': original file link is broken')
elif file != newfile:
self.move(file, newfile, copy)
self.move(file, newfile, copy, hardlink=hardlink)
# assert os.path.exists(newfile)
# if not copy:
# assert not os.path.exists(file)
Expand All @@ -544,7 +544,7 @@ def rename_entry_files(self, e, copy=False, formatter=None, relative_to=None):
if not os.path.exists(file):
raise ValueError(file+': original file link is broken')
elif file != newfile:
self.move(file, newfile, copy)
self.move(file, newfile, copy, hardlink=hardlink)
# assert os.path.exists(newfile)
count += 1
newfiles.append(newfile)
Expand Down Expand Up @@ -577,10 +577,10 @@ def rename_entry_files(self, e, copy=False, formatter=None, relative_to=None):
logger.info('renamed file(s): {}'.format(count))


def rename_entries_files(self, copy=False, relative_to=None):
def rename_entries_files(self, copy=False, relative_to=None, hardlink=False):
for e in self.db.entries:
try:
self.rename_entry_files(e, copy, relative_to=relative_to)
self.rename_entry_files(e, copy, relative_to=relative_to, hardlink=hardlink)
except Exception as error:
logger.error(str(error))
continue
Expand Down

0 comments on commit 3945a05

Please sign in to comment.