This is an automated email from the ASF dual-hosted git repository.
sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-release.git
The following commit(s) were added to refs/heads/main by this push:
new 052bf39 Do not create a new revision if moving a file fails
052bf39 is described below
commit 052bf39abc04591eac141fa599ac61229ed68d40
Author: Sean B. Palmer <[email protected]>
AuthorDate: Wed May 21 19:59:00 2025 +0100
Do not create a new revision if moving a file fails
---
atr/revision.py | 7 ++++++-
atr/routes/finish.py | 3 +++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/atr/revision.py b/atr/revision.py
index 37e60ad..a0df39b 100644
--- a/atr/revision.py
+++ b/atr/revision.py
@@ -38,6 +38,7 @@ class Creating:
old: models.Revision | None
interim_path: pathlib.Path
new: models.Revision | None
+ failed: bool = False
# NOTE: The create_directory parameter is not used anymore
@@ -68,12 +69,16 @@ async def create_and_manage(
old_release_dir = util.release_directory(release)
await util.create_hard_link_clone(old_release_dir, temp_dir_path,
do_not_create_dest_dir=True)
# The directory is either empty or its files are hard linked to the
previous revision
- creating = Creating(old=old_revision, interim_path=temp_dir_path,
new=None)
+ creating = Creating(old=old_revision, interim_path=temp_dir_path,
new=None, failed=False)
yield creating
except Exception:
await aioshutil.rmtree(temp_dir) # type: ignore[call-arg]
raise
+ if creating.failed:
+ await aioshutil.rmtree(temp_dir) # type: ignore[call-arg]
+ return
+
# Create a revision row, but hold the write lock
async with db.session() as data, data.begin():
new_revision = models.Revision(
diff --git a/atr/routes/finish.py b/atr/routes/finish.py
index 6c632dc..04ded95 100644
--- a/atr/routes/finish.py
+++ b/atr/routes/finish.py
@@ -158,6 +158,9 @@ async def _move_file_to_revision(
f.name for f in bundle if await
aiofiles.os.path.exists(creating.interim_path / target_dir_rel / f.name)
]
if collisions:
+ # Remove the temporary directory, and do not create or commit
a new revision
+ # (But also do not raise an exception)
+ creating.failed = True
msg = f"Files already exist in '{target_dir_rel}': {',
'.join(collisions)}"
if wants_json:
return quart.jsonify(error=msg), 400
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]