mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Lazy-add new package bases
Create new package bases just before saving package metadata. This protects from stray package bases left behind when new packages are rejected, e.g. when the user tries to push a package that is available from the official repositories already. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
parent
ac6b091724
commit
936ee66f1e
2 changed files with 24 additions and 4 deletions
|
@ -145,10 +145,7 @@ if action == 'git-upload-pack' or action == 'git-receive-pack':
|
||||||
if not re.match(repo_regex, pkgbase):
|
if not re.match(repo_regex, pkgbase):
|
||||||
die('{:s}: invalid repository name: {:s}'.format(action, pkgbase))
|
die('{:s}: invalid repository name: {:s}'.format(action, pkgbase))
|
||||||
|
|
||||||
if not pkgbase_exists(pkgbase):
|
if action == 'git-receive-pack' and pkgbase_exists(pkgbase):
|
||||||
create_pkgbase(pkgbase, user)
|
|
||||||
|
|
||||||
if action == 'git-receive-pack':
|
|
||||||
if not privileged and not pkgbase_has_write_access(pkgbase, user):
|
if not privileged and not pkgbase_has_write_access(pkgbase, user):
|
||||||
die('{:s}: permission denied: {:s}'.format(action, user))
|
die('{:s}: permission denied: {:s}'.format(action, user))
|
||||||
|
|
||||||
|
|
|
@ -58,6 +58,25 @@ def parse_dep(depstring):
|
||||||
return (depname, depcond)
|
return (depname, depcond)
|
||||||
|
|
||||||
|
|
||||||
|
def create_pkgbase(conn, pkgbase, user):
|
||||||
|
cur = conn.execute("SELECT ID FROM Users WHERE Username = ?", [user])
|
||||||
|
userid = cur.fetchone()[0]
|
||||||
|
|
||||||
|
now = int(time.time())
|
||||||
|
cur = conn.execute("INSERT INTO PackageBases (Name, SubmittedTS, " +
|
||||||
|
"ModifiedTS, SubmitterUID, MaintainerUID) VALUES " +
|
||||||
|
"(?, ?, ?, ?, ?)", [pkgbase, now, now, userid, userid])
|
||||||
|
pkgbase_id = cur.lastrowid
|
||||||
|
|
||||||
|
cur = conn.execute("INSERT INTO PackageNotifications " +
|
||||||
|
"(PackageBaseID, UserID) VALUES (?, ?)",
|
||||||
|
[pkgbase_id, userid])
|
||||||
|
|
||||||
|
conn.commit()
|
||||||
|
|
||||||
|
return pkgbase_id
|
||||||
|
|
||||||
|
|
||||||
def save_metadata(metadata, conn, user):
|
def save_metadata(metadata, conn, user):
|
||||||
# Obtain package base ID and previous maintainer.
|
# Obtain package base ID and previous maintainer.
|
||||||
pkgbase = metadata['pkgbase']
|
pkgbase = metadata['pkgbase']
|
||||||
|
@ -362,6 +381,10 @@ for pkgname in srcinfo.utils.get_package_names(metadata):
|
||||||
if cur.fetchone()[0] > 0:
|
if cur.fetchone()[0] > 0:
|
||||||
die('cannot overwrite package: {:s}'.format(pkgname))
|
die('cannot overwrite package: {:s}'.format(pkgname))
|
||||||
|
|
||||||
|
# Create a new package base if it does not exist yet.
|
||||||
|
if pkgbase_id == 0:
|
||||||
|
pkgbase_id = create_pkgbase(conn, pkgbase, user)
|
||||||
|
|
||||||
# Store package base details in the database.
|
# Store package base details in the database.
|
||||||
save_metadata(metadata, conn, user)
|
save_metadata(metadata, conn, user)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue