mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix: make overwriting of archive files atomic
This commit is contained in:
parent
524334409a
commit
3dcbee5a4f
1 changed files with 6 additions and 9 deletions
|
@ -24,7 +24,6 @@ import io
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
@ -219,10 +218,9 @@ def _main():
|
||||||
output = list()
|
output = list()
|
||||||
snapshot_uri = aurweb.config.get("options", "snapshot_uri")
|
snapshot_uri = aurweb.config.get("options", "snapshot_uri")
|
||||||
|
|
||||||
tmpdir = tempfile.mkdtemp()
|
tmp_packages = f"{PACKAGES}.tmp"
|
||||||
tmp_packages = os.path.join(tmpdir, os.path.basename(PACKAGES))
|
tmp_meta = f"{META}.tmp"
|
||||||
tmp_meta = os.path.join(tmpdir, os.path.basename(META))
|
tmp_metaext = f"{META_EXT}.tmp"
|
||||||
tmp_metaext = os.path.join(tmpdir, os.path.basename(META_EXT))
|
|
||||||
gzips = {
|
gzips = {
|
||||||
"packages": gzip.open(tmp_packages, "wt"),
|
"packages": gzip.open(tmp_packages, "wt"),
|
||||||
"meta": gzip.open(tmp_meta, "wb"),
|
"meta": gzip.open(tmp_meta, "wb"),
|
||||||
|
@ -276,13 +274,13 @@ def _main():
|
||||||
|
|
||||||
# Produce pkgbase.gz
|
# Produce pkgbase.gz
|
||||||
query = db.query(PackageBase.Name).filter(PackageBase.PackagerUID.isnot(None)).all()
|
query = db.query(PackageBase.Name).filter(PackageBase.PackagerUID.isnot(None)).all()
|
||||||
tmp_pkgbase = os.path.join(tmpdir, os.path.basename(PKGBASE))
|
tmp_pkgbase = f"{PKGBASE}.tmp"
|
||||||
with gzip.open(tmp_pkgbase, "wt") as f:
|
with gzip.open(tmp_pkgbase, "wt") as f:
|
||||||
f.writelines([f"{base.Name}\n" for i, base in enumerate(query)])
|
f.writelines([f"{base.Name}\n" for i, base in enumerate(query)])
|
||||||
|
|
||||||
# Produce users.gz
|
# Produce users.gz
|
||||||
query = db.query(User.Username).all()
|
query = db.query(User.Username).all()
|
||||||
tmp_users = os.path.join(tmpdir, os.path.basename(USERS))
|
tmp_users = f"{USERS}.tmp"
|
||||||
with gzip.open(tmp_users, "wt") as f:
|
with gzip.open(tmp_users, "wt") as f:
|
||||||
f.writelines([f"{user.Username}\n" for i, user in enumerate(query)])
|
f.writelines([f"{user.Username}\n" for i, user in enumerate(query)])
|
||||||
|
|
||||||
|
@ -297,7 +295,7 @@ def _main():
|
||||||
|
|
||||||
for src, dst in files:
|
for src, dst in files:
|
||||||
checksum = sha256sum(src)
|
checksum = sha256sum(src)
|
||||||
base = os.path.basename(src)
|
base = os.path.basename(dst)
|
||||||
checksum_formatted = f"SHA256 ({base}) = {checksum}"
|
checksum_formatted = f"SHA256 ({base}) = {checksum}"
|
||||||
|
|
||||||
checksum_file = f"{dst}.sha256"
|
checksum_file = f"{dst}.sha256"
|
||||||
|
@ -307,7 +305,6 @@ def _main():
|
||||||
# Move the new archive into its rightful place.
|
# Move the new archive into its rightful place.
|
||||||
shutil.move(src, dst)
|
shutil.move(src, dst)
|
||||||
|
|
||||||
os.removedirs(tmpdir)
|
|
||||||
seconds = filters.number_format(bench.end(), 4)
|
seconds = filters.number_format(bench.end(), 4)
|
||||||
logger.info(f"Completed in {seconds} seconds.")
|
logger.info(f"Completed in {seconds} seconds.")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue