Skip to content

Commit

Permalink
Revise the deletion code
Browse files Browse the repository at this point in the history
There are rare cases where non-canonical and canonical packages
co-exist. In this case, if deleting the non-canonical package name we
should not attempt to remove the canonical package name, unless it's a
sym-link.
  • Loading branch information
waveform80 committed Aug 9, 2020
1 parent f86d92d commit 3906dac
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions piwheels/master/the_scribe.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,18 +394,25 @@ def delete_package(self, package):
files |= {
pkg_dir / 'index.html',
proj_dir / 'index.html',
canon_pkg_dir / 'index.html',
canon_proj_dir / 'index.html',
# Attempt to remove canonical sym-links (with unlink); if this
# fails that's okay (and ignorable) because it means we've run into
# one of the (rare) cases of a non-canonical and canonical package
# co-existing simultaneously (only for historic packages)
canon_pkg_dir,
canon_proj_dir,
}

for file_path in files:
try:
file_path.unlink()
self.logger.debug('file deleted: %s', file_path)
except IsADirectoryError:
# See note above
pass
except FileNotFoundError:
self.logger.error('file not found: %s', file_path)

for dir_path in {pkg_dir, proj_dir, canon_pkg_dir, canon_proj_dir}:
for dir_path in {pkg_dir, proj_dir}:
try:
dir_path.rmdir()
except OSError as e:
Expand Down

0 comments on commit 3906dac

Please sign in to comment.