summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorXavier Chantry <shiningxc@gmail.com>2009-02-25 19:06:16 +0100
committerXavier Chantry <shiningxc@gmail.com>2009-03-15 18:10:23 +0100
commitbbcf96230ad16ad91f5ab8cb93c05fd15136d3e4 (patch)
tree419314a2bc707eb981270e4b1533e76a3e42d34c /scripts
parent89685bdb2918c59a109cba2199ab25bc1bcfa784 (diff)
downloadpacman-bbcf96230ad16ad91f5ab8cb93c05fd15136d3e4.tar.xz
repo-add : rewrite delta support
Use the correct database format Use xdelta3 to get the source and destination files from the delta itself Allow delta files to be added with repo-add just like package files. delta files can also be removed with repo-remove. This is simply done by looking for a .delta extension in the arguments, and calling the appropriate db_write_delta or db_remove_delta functions. Example usage: repo-add repo/test.db.tar.gz repo/libx11-1.1.99.2-2-x86_64.pkg.tar.gz repo-add repo/test.db.tar.gz repo/libx11-1.1.5-2_to_1.1.99.2-2-x86_64.delta repo-remove repo/test.db.tar.gz libx11-1.1.5-2_to_1.1.99.2-2-x86_64.delta Signed-off-by: Xavier Chantry <shiningxc@gmail.com>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/repo-add.sh.in102
1 files changed, 97 insertions, 5 deletions
diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index 93416dc5..aa03ab78 100644
--- a/scripts/repo-add.sh.in
+++ b/scripts/repo-add.sh.in
@@ -57,8 +57,8 @@ error() {
# print usage instructions
usage() {
printf "repo-add, repo-remove (pacman) %s\n\n" "$myver"
- printf "$(gettext "Usage: repo-add [-q] <path-to-db> <package> ...\n")"
- printf "$(gettext "Usage: repo-remove [-q] <path-to-db> <packagename> ...\n\n")"
+ printf "$(gettext "Usage: repo-add [-q] <path-to-db> <package|delta> ...\n")"
+ printf "$(gettext "Usage: repo-remove [-q] <path-to-db> <packagename|delta> ...\n\n")"
printf "$(gettext "\
repo-add will update a package database by reading a package file.\n\
Multiple packages to add can be specified on the command line.\n\n")"
@@ -107,6 +107,73 @@ find_pkgentry()
return 1
}
+# Get the package name from the delta filename
+get_delta_pkgname() {
+ local tmp
+
+ tmp=${1##*/}
+ echo ${tmp%-*-*_to*}
+}
+
+# write a delta entry
+# arg1 - path to delta file
+db_write_delta()
+{
+ deltafile="$1"
+ pkgname="$(get_delta_pkgname $deltafile)"
+
+ pkgentry=$(find_pkgentry $pkgname)
+ if [ -z "$pkgentry" ]; then
+ return 1
+ fi
+ deltas="$pkgentry/deltas"
+ # create deltas file if it does not already exist
+ if [ ! -f "$deltas" ]; then
+ msg2 "$(gettext "Creating 'deltas' db entry...")"
+ echo -e "%DELTAS%" >>$deltas
+ fi
+ # get md5sum and compressed size of package
+ md5sum="$(openssl dgst -md5 "$deltafile" | awk '{print $NF}')"
+ csize=$(@SIZECMD@ "$deltafile")
+
+ oldfile=$(xdelta3 printhdr $deltafile | grep "XDELTA filename (source)" | sed 's/.*: *//')
+ newfile=$(xdelta3 printhdr $deltafile | grep "XDELTA filename (output)" | sed 's/.*: *//')
+
+ if grep -q "$oldfile.*$newfile" $deltas; then
+ warning "$(gettext "An entry for '%s' already existed")" "$deltafile"
+ sed -i.backup "/$oldfile.*$newfile/d" $deltas && rm -f $deltas.backup
+ msg2 "$(gettext "Removing existing entry '%s'...")" "$deltafile"
+ fi
+ echo ${deltafile##*/} $md5sum $csize $oldfile $newfile >> $deltas
+
+ return 0
+} # end db_write_delta
+
+# remove a delta entry
+# arg1 - path to delta file
+db_remove_delta()
+{
+ deltafile="$1"
+ filename=${deltafile##*/}
+ pkgname="$(get_delta_pkgname $deltafile)"
+
+ pkgentry=$(find_pkgentry $pkgname)
+ if [ -z "$pkgentry" ]; then
+ return 1
+ fi
+ deltas="$pkgentry/deltas"
+ if [ ! -f "$deltas" ]; then
+ return 1
+ fi
+ if grep -q "$filename" $deltas; then
+ sed -i.backup "/$filename/d" $deltas && rm -f $deltas.backup
+ msg2 "$(gettext "Removing existing entry '%s'...")" "$filename"
+ return 0
+ fi
+
+ return 1
+} # end db_remove_delta
+
# write an entry to the pacman database
# arg1 - path to package
db_write_entry()
@@ -222,7 +289,7 @@ db_remove_entry() {
if [ -f "$pkgentry/deltas" ]; then
mv "$pkgentry/deltas" "$gstmpdir/$pkgname.deltas"
fi
- msg2 "$(gettext "Removing existing package '%s'...")" \
+ msg2 "$(gettext "Removing existing entry '%s'...")" \
"$(basename $pkgentry)"
rm -rf $pkgentry
pkgentry=$(find_pkgentry $pkgname)
@@ -249,12 +316,26 @@ check_repo_db()
add()
{
- pkgfile=$1
if [ ! -f "$1" ]; then
- error "$(gettext "Package '%s' not found.")" "$pkgfile"
+ error "$(gettext "File '%s' not found.")" "$1"
return 1
fi
+ if [ "${1##*.}" == "delta" ]; then
+ deltafile=$1
+ msg "$(gettext "Adding delta '%s'")" "$deltafile"
+ if [ ! "$(type -p xdelta3)" ]; then
+ error "$(gettext "Cannot find the xdelta3 binary! Is xdelta3 installed?")"
+ exit 1
+ fi
+ if db_write_delta "$deltafile"; then
+ return 0
+ else
+ return 1
+ fi
+ fi
+
+ pkgfile=$1
if ! bsdtar -tf "$pkgfile" .PKGINFO 2>&1 >/dev/null; then
error "$(gettext "'%s' is not a package file, skipping")" "$pkgfile"
return 1
@@ -267,6 +348,17 @@ add()
remove()
{
+ if [ "${1##*.}" == "delta" ]; then
+ deltafile=$1
+ msg "$(gettext "Searching for delta '%s'...")" "$deltafile"
+ if db_remove_delta "$deltafile"; then
+ return 0
+ else
+ error "$(gettext "Delta matching '%s' not found.")" "$deltafile"
+ return 1
+ fi
+ fi
+
pkgname=$1
msg "$(gettext "Searching for package '%s'...")" "$pkgname"