Skip to content

Commit

Permalink
[#795] wb-manager: Show error when adding duplicate warc files (#797)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuechensofa authored Jan 19, 2023
1 parent 1790fd0 commit e6ec8b4
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pywb/manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,24 @@ def add_warcs(self, warcs):
format(self.archive_dir))

full_paths = []
duplicate_warcs = []
for filename in warcs:
filename = os.path.abspath(filename)

# don't overwrite existing warcs with duplicate names
if os.path.exists(os.path.join(self.archive_dir, os.path.basename(filename))):
duplicate_warcs.append(filename)
continue

shutil.copy2(filename, self.archive_dir)
full_paths.append(os.path.join(self.archive_dir, filename))
logging.info('Copied ' + filename + ' to ' + self.archive_dir)

self._index_merge_warcs(full_paths, self.DEF_INDEX_FILE)

if duplicate_warcs:
logging.warning(f'Warcs {", ".join(duplicate_warcs)} weren\'t added because of duplicate names.')

def reindex(self):
cdx_file = os.path.join(self.indexes_dir, self.DEF_INDEX_FILE)
logging.info('Indexing ' + self.archive_dir + ' to ' + cdx_file)
Expand Down

0 comments on commit e6ec8b4

Please sign in to comment.