[aur-dev] [PATCH 1/2] 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, i.e. when the user tries to push a package that is available from the official repositories already. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- git-interface/git-serve.py | 5 +---- git-interface/git-update.py | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/git-interface/git-serve.py b/git-interface/git-serve.py index d3a32c3..19c3ab2 100755 --- a/git-interface/git-serve.py +++ b/git-interface/git-serve.py @@ -145,10 +145,7 @@ if action == 'git-upload-pack' or action == 'git-receive-pack': if not re.match(repo_regex, pkgbase): die('{:s}: invalid repository name: {:s}'.format(action, pkgbase)) - if not pkgbase_exists(pkgbase): - create_pkgbase(pkgbase, user) - - if action == 'git-receive-pack': + if action == 'git-receive-pack' and pkgbase_exists(pkgbase): if not privileged and not pkgbase_has_write_access(pkgbase, user): die('{:s}: permission denied: {:s}'.format(action, user)) diff --git a/git-interface/git-update.py b/git-interface/git-update.py index e6f6410..40d834d 100755 --- a/git-interface/git-update.py +++ b/git-interface/git-update.py @@ -58,6 +58,25 @@ def parse_dep(depstring): 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): # Obtain package base ID and previous maintainer. pkgbase = metadata['pkgbase'] @@ -362,6 +381,10 @@ for pkgname in srcinfo.utils.get_package_names(metadata): if cur.fetchone()[0] > 0: 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. save_metadata(metadata, conn, user) -- 2.9.2
Package bases are created by git-update automatically when the repository receives a ref update for the first time. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org> --- git-interface/test/t0003-update.sh | 6 ------ 1 file changed, 6 deletions(-) diff --git a/git-interface/test/t0003-update.sh b/git-interface/test/t0003-update.sh index 81c5687..aeb223e 100755 --- a/git-interface/test/t0003-update.sh +++ b/git-interface/test/t0003-update.sh @@ -4,11 +4,6 @@ test_description='git-update tests' . ./setup.sh -test_expect_success 'Setup repositories and create package bases.' ' - SSH_ORIGINAL_COMMAND="setup-repo foobar" AUR_USER=user "$GIT_SERVE" - SSH_ORIGINAL_COMMAND="setup-repo foobar2" AUR_USER=user "$GIT_SERVE" -' - test_expect_success 'Test update hook on a fresh repository.' ' old=0000000000000000000000000000000000000000 && new=$(git -C aur.git rev-parse HEAD^) && @@ -20,7 +15,6 @@ test_expect_success 'Test update hook on a fresh repository.' ' 1|1 1|1|python-pygit2|| 1|1 - 2|1 EOF >actual && for t in Packages Licenses PackageLicenses Groups PackageGroups \ -- 2.9.2
participants (1)
-
Lukas Fleischer