Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't fail if a to-be archived publish has missing snapshots #117

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions pyaptly/publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ def publish_cmd_update(cfg, publish_name, publish_config, ignore_existing=False)
return cmd

publish_fullname = "%s %s" % (publish_name, publish_config["distribution"])
current_snapshots = state_reader.state_reader().publish_map()[publish_fullname]
# TODO: add flag --create to create publishes when they haven't been created yet
# TODO: Fail gracefully and show an error when there is no existing publish
try:
current_snapshots = state_reader.state_reader().publish_map()[publish_fullname]
except KeyError as e:
util.exit_with_error("The publish hasn't been created yet: " + e)
if "snapshots" in publish_config:
snapshots_config = publish_config["snapshots"]
new_snapshots = [
Expand Down Expand Up @@ -129,13 +134,15 @@ 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]

snapshot.clone_snapshot(current_snapshot, archive).execute()
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))
winged marked this conversation as resolved.
Show resolved Hide resolved
else:
snapshot.clone_snapshot(current_snapshot, archive).execute()

publish_cmd.append("switch")
options.append("-component=%s" % ",".join(components))
Expand Down
Loading