| |
@@ -218,6 +218,11 @@
|
| |
if not os.path.exists(compose.target_dir):
|
| |
continue
|
| |
|
| |
+ # Do not remove the latest successfull compose.
|
| |
+ if get_latest_symlink(compose):
|
| |
+ log.info("%r: Not removing compose, the latest-* symlink points to it.")
|
| |
+ continue
|
| |
+
|
| |
log.info("%r: Removing compose", compose)
|
| |
if compose.removed_by:
|
| |
state_reason = "Removed by {}.".format(compose.removed_by)
|
| |
@@ -837,6 +842,27 @@
|
| |
os.symlink(compose_dir, symlink)
|
| |
|
| |
|
| |
+ def get_latest_symlink(compose):
|
| |
+ """
|
| |
+ Returns the latest-* symlink associated with this compose or None
|
| |
+ if it does not exists.
|
| |
+ """
|
| |
+ # Ignore old composes which do not have the compose_type and pungi_compose_id set.
|
| |
+ if not compose.compose_type or not compose.pungi_compose_id:
|
| |
+ return None
|
| |
+
|
| |
+ symlink_dir = os.path.join(compose.target_dir, compose.compose_type)
|
| |
+ symlink = os.path.join(symlink_dir, compose.pungi_compose_id)
|
| |
+ latest_name = "latest-%s" % "-".join(compose.pungi_compose_id.split("-")[:2])
|
| |
+ latest_symlink = os.path.join(symlink_dir, latest_name)
|
| |
+
|
| |
+ # Return Non if `latest_symlink` points to the different dir than `symlink`.
|
| |
+ if os.path.realpath(symlink) != os.path.realpath(latest_symlink):
|
| |
+ return None
|
| |
+
|
| |
+ return latest_symlink
|
| |
+
|
| |
+
|
| |
def remove_compose_symlink(compose):
|
| |
"""
|
| |
Removes non-latest symlink generated by the `generate_compose_symlink`.
|
| |
@@ -848,14 +874,7 @@
|
| |
|
| |
symlink_dir = os.path.join(compose.target_dir, compose.compose_type)
|
| |
symlink = os.path.join(symlink_dir, compose.pungi_compose_id)
|
| |
-
|
| |
- # Check if latest_symlink points to the same directory as the non-latest
|
| |
- # symlink. In this case, we will remove the latest-symlink later too.
|
| |
- latest_name = "latest-%s" % "-".join(compose.pungi_compose_id.split("-")[:2])
|
| |
- latest_symlink = os.path.join(symlink_dir, latest_name)
|
| |
- remove_latest_symlink = os.path.realpath(symlink) == os.path.realpath(
|
| |
- latest_symlink
|
| |
- )
|
| |
+ latest_symlink = get_latest_symlink(compose)
|
| |
|
| |
# Remove non-latest symlink.
|
| |
log.info("%r: Removing %s symlink.", compose, symlink)
|
| |
@@ -866,7 +885,7 @@
|
| |
raise
|
| |
|
| |
# Remove latest symlink.
|
| |
- if remove_latest_symlink:
|
| |
+ if latest_symlink:
|
| |
log.info("%r: Removing %s symlink.", compose, latest_symlink)
|
| |
try:
|
| |
os.unlink(latest_symlink)
|
| |
There are two reasons for this:
reduce their generation time. If we remove it after 24 hours, next
compose will have to generate everything from scratch again.
available so other service can point to this location. This is
needed for Fedora ELN or internal Integration composes.