aboutsummaryrefslogtreecommitdiff
path: root/brep/handler/submit/submit-git.in
diff options
context:
space:
mode:
Diffstat (limited to 'brep/handler/submit/submit-git.in')
-rw-r--r--brep/handler/submit/submit-git.in50
1 files changed, 21 insertions, 29 deletions
diff --git a/brep/handler/submit/submit-git.in b/brep/handler/submit/submit-git.in
index 8263efe..c882b84 100644
--- a/brep/handler/submit/submit-git.in
+++ b/brep/handler/submit/submit-git.in
@@ -1,7 +1,6 @@
#!/usr/bin/env bash
# file : brep/handler/submit/submit-git.in
-# copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
# license : MIT; see accompanying LICENSE file
# Package submission handler with git repository storage.
@@ -187,8 +186,10 @@ git_timeout=10
ref_lock_timeout=30
trap "{ exit 1; }" ERR
-set -o errtrace # Trap ERR in functions.
-set -o pipefail # Return the rightmost non-zero exit status in a pipeline.
+set -o errtrace # Trap in functions and subshells.
+set -o pipefail # Fail if any pipeline command fails.
+shopt -s lastpipe # Execute last pipeline command in the current shell.
+shopt -s nullglob # Expand no-match globs to nothing rather than themselves.
@import brep/handler/handler@
@import brep/handler/submit/submit@
@@ -404,7 +405,7 @@ function git_add () # <repo-dir> <path>...
local d="$1"
shift
- run git -C "$d" add $gvo "$@" >&2
+ run git -C "$d" add --force $gvo "$@" >&2
}
# For now we make 10 re-tries to add the package and push to target. Push can
@@ -440,8 +441,12 @@ for i in {1..11}; do
trace "+ exec {fd}<$l"
exec {fd}<"$l"
+ # Note that on the locking failure we don't suggest the user to try again,
+ # since the client program may suggest to re-try later for all server
+ # errors (as bdep-publish(1) does).
+ #
if ! run flock -w "$ref_lock_timeout" "$fd"; then
- exit_with_manifest 503 "submission service temporarily unavailable"
+ exit_with_manifest 503 "submission service is busy"
fi
# Pull the reference repository.
@@ -558,7 +563,7 @@ for i in {1..11}; do
#
prj_man="$d/project-owner.manifest"
- if [ ! -f "$prj_man" ]; then
+ if [ ! -f "$prj_man" -a "$ref_auth" != "project" ]; then
run mkdir -p "$d" # Also creates the owners directory if not exist.
ctl="$(repository_base "$control")"
@@ -575,7 +580,7 @@ for i in {1..11}; do
# Now the package name.
#
d="$d/$name"
- run mkdir "$d"
+ run mkdir -p "$d" # Also creates the project directory if not exist.
pkg_man="$d/package-owner.manifest"
@@ -636,34 +641,21 @@ for i in {1..11}; do
exit_with_manifest 400 "unrecognized section '$section'"
fi
- # Strips the version revision part, if present.
- #
- v="$(sed -n -re 's%^(\+?[^+]+)(\+[0-9]+)?$%\1%p' <<<"$version")"
-
- # Make sure the section directory exists before we run find in it.
- #
- d="$tgt_dir/$s/$project"
- run mkdir -p "$d" # Create all the parent directories as well.
+ run pkg_find_archives "$name" "$version*" "$tgt_dir/$s" | readarray -t arcs
- # Go through the potentially matching archives (for example, for
- # foo-1.2.3+2: foo-1.2.3.tar.gz, foo-1.2.3+1.tar.gz, foo-1.2.30.tar.gz, etc)
- # and remove those that match exactly.
- #
- # Change CWD to the section directory to make sure that the found archive
- # paths don't contain spaces.
- #
- fs=($(run cd "$tgt_dir/$s" && run find -name "$name-$v*"))
-
- for f in "${fs[@]}"; do
- if [[ "$f" =~ ^\./[^/]+/"$name-$v"(\+[0-9]+)?\.[^/]+$ ]]; then
- run git -C "$tgt_dir" rm $gqo "$s/$f" >&2
- fi
+ for f in "${arcs[@]}"; do
+ run git -C "$tgt_dir" rm $gqo "${f#$tgt_dir/}" >&2
done
# Finally, add the package archive to the target repository.
#
- # We copy the archive rather than move it since we may need it for a re-try.
+ # Copy the archive rather than move it since we may need it for a re-try.
+ # Make sure the project directory exists before we copy the archive into it.
+ # Note that it was removed by git-rm if it became empty.
#
+ d="$tgt_dir/$s/$project"
+ run mkdir -p "$d" # Create all the parent directories as well.
+
a="$d/$archive"
run cp "$data_dir/$archive" "$a"