Skip to content

Commit

Permalink
fix: Don't fail if a to-be archived publish has wrong snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
Melkor333 committed Jun 27, 2024
1 parent 24c28fd commit 2561d07
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions pyaptly/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def publish_cmd_update(cfg, publish_name, publish_config, ignore_existing=False)
return cmd

publish_fullname = "%s %s" % (publish_name, publish_config["distribution"])
# This line might fail if no publish has been created yet
# TODO: add clag --create to create publishes when they haven't been created yet
# TODO: Fail gracefully and show an error when there is no existing publish
current_snapshots = state_reader.state_reader().publish_map()[publish_fullname]
if "snapshots" in publish_config:
snapshots_config = publish_config["snapshots"]
Expand Down Expand Up @@ -129,11 +132,13 @@ def publish_cmd_update(cfg, publish_name, publish_config, ignore_existing=False)
continue
prefix_to_search = re.sub("%T$", "", snap["name"])

current_snapshot = [
snap_name
for snap_name in sorted(current_snapshots, key=lambda x: -len(x))
if snap_name.startswith(prefix_to_search)
][0]
current_snapshot = None
for snap_name in sorted(current_snapshots, key=lambda x: -len(x)):
if snap_name.startswith(prefix_to_search):
current_snapshot = snap_name
break
if current_snapshot is None:
lg.warn("Snapshot %s doesn't exist on to-be archived publish %s." % (snap["name"], publish_fullname))

snapshot.clone_snapshot(current_snapshot, archive).execute()

Expand Down

0 comments on commit 2561d07

Please sign in to comment.