Skip to content

Commit

Permalink
feat: add options for soft-deletion of channels and packages (#681)
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfv authored Jan 30, 2024
1 parent e7b3940 commit 2d7baea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
7 changes: 7 additions & 0 deletions quetz/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,13 @@ class Config:
],
required=False,
),
ConfigSection(
"storage",
[
ConfigEntry("soft_delete_channel", bool, required=False, default=False),
ConfigEntry("soft_delete_package", bool, required=False, default=False),
],
),
]
_config_dirs = [_site_dir, _user_dir]
_config_files = [os.path.join(d, _filename) for d in _config_dirs]
Expand Down
10 changes: 7 additions & 3 deletions quetz/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,13 @@ def delete_channel(
channel: db_models.Channel = Depends(get_channel_allow_proxy),
dao: Dao = Depends(get_dao),
auth: authorization.Rules = Depends(get_rules),
config=Depends(get_config),
):
auth.assert_delete_channel(channel)
dao.delete_channel(channel.name)
try:
pkgstore.remove_channel(channel.name)
if not config.storage_soft_delete_channel:
pkgstore.remove_channel(channel.name)
except FileNotFoundError:
logger.warning(
f"trying to remove non-existent package store for channel {channel.name}"
Expand Down Expand Up @@ -895,7 +897,8 @@ def delete_package(
db.commit()

for filename in filenames:
pkgstore.delete_file(channel_name, filename)
if not config.storage_soft_delete_package:
pkgstore.delete_file(channel_name, filename)

dao.update_channel_size(channel_name)

Expand Down Expand Up @@ -1162,7 +1165,8 @@ def delete_package_version(
db.commit()

path = os.path.join(platform, filename)
pkgstore.delete_file(channel_name, path)
if not config.storage_soft_delete_package:
pkgstore.delete_file(channel_name, path)

dao.cleanup_channel_db(channel_name, package_name)
dao.update_channel_size(channel_name)
Expand Down

0 comments on commit 2d7baea

Please sign in to comment.