[pacman-dev] [PATCH] repo-add; add option to remove existing package files from disk
From: Phillip Smith <fukawi2@gmail.com> ==== Updated this patch to remove the sig file, use awk instead of grep/tail and updated documentation too. ==== When maintaining a custom repo, often it is undesirable to retain older versions of packages. This patch adds the --remove option to remove the current package file and it's signature from disk before adding the new one to the database. Documentation is also updated. This is an optional flag and default behaviour (leaving ondisk files alone) is not changed. Signed-off-by: Phillip Smith <fukawi2@gmail.com> --- doc/repo-add.8.txt | 6 ++++++ scripts/repo-add.sh.in | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/doc/repo-add.8.txt b/doc/repo-add.8.txt index 049195a..b06844b 100644 --- a/doc/repo-add.8.txt +++ b/doc/repo-add.8.txt @@ -75,6 +75,12 @@ repo-add Options Only add packages that are not already in the database. Warnings will be printed upon detection of existing packages, but they will not be re-added. +*-R, \--remove*:: + If an existing package with the same name exists in the database and on + disk, remove it from disk well as updating the database entry for the + package. This is designed to be Used when updating an existing package to + a new version. + See Also -------- linkman:makepkg[8], linkman:pacman[8], linkman:pkgdelta[8] diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in index 4470dd0..91574b3 100644 --- a/scripts/repo-add.sh.in +++ b/scripts/repo-add.sh.in @@ -31,6 +31,7 @@ declare -r confdir='@sysconfdir@' QUIET=0 DELTA=0 ONLYADDNEW=0 +RMEXISTING=0 WITHFILES=0 SIGN=0 VERIFY=0 @@ -58,6 +59,7 @@ Multiple packages to add can be specified on the command line.\n")" printf -- "$(gettext "Options:\n")" printf -- "$(gettext " -d, --delta generate and add delta for package update\n")" printf -- "$(gettext " -n, --new only add packages that are not already in the database\n")" + printf -- "$(gettext " -R, --remove remove any existing packages with the same name (eg, an older version)\n")" printf -- "$(gettext " -f, --files update database's file list\n")" elif [[ $cmd == "repo-remove" ]] ; then printf -- "$(gettext "Usage: repo-remove [options] <path-to-db> <packagename|delta> ...\n")" @@ -304,6 +306,15 @@ db_write_entry() { local oldfilename=$(grep -A1 FILENAME "$pkgentry/desc" | tail -n1) local oldfile="$(dirname "$1")/$oldfilename" fi + elif (( RMEXISTING )); then + # only remove existing package if we're not doing deltas + pkgentry=$(find_pkgentry "$pkgname") + if [[ -n $pkgentry ]]; then + local oldfilename="$(awk '/%FILENAME%/ {getline; print}' "$pkgentry/desc")" + local oldfile="$(dirname "$1")/$oldfilename" + msg2 "$(gettext "Removing existing package '%s'")" "$oldfilename" + rm -f ${oldfile} ${oldfile}.sig + fi fi fi @@ -611,6 +622,7 @@ while (( $# )); do -q|--quiet) QUIET=1;; -d|--delta) DELTA=1;; -n|--new) ONLYADDNEW=1;; + -R|--remove) RMEXISTING=1;; -f|--files) WITHFILES=1;; --nocolor) USE_COLOR='n';; -s|--sign) -- 1.8.2.3
On 30/05/13 13:39, Phillip Smith wrote:
From: Phillip Smith <fukawi2@gmail.com>
==== Updated this patch to remove the sig file, use awk instead of grep/tail and updated documentation too. ====
When maintaining a custom repo, often it is undesirable to retain older versions of packages. This patch adds the --remove option to remove the current package file and it's signature from disk before adding the new one to the database. Documentation is also updated. This is an optional flag and default behaviour (leaving ondisk files alone) is not changed.
Signed-off-by: Phillip Smith <fukawi2@gmail.com> ---
Hint: add comments like "Updated this patch"... under the "---" above. Then it is not part of the commit message.
doc/repo-add.8.txt | 6 ++++++ scripts/repo-add.sh.in | 12 ++++++++++++ 2 files changed, 18 insertions(+)
diff --git a/doc/repo-add.8.txt b/doc/repo-add.8.txt index 049195a..b06844b 100644 --- a/doc/repo-add.8.txt +++ b/doc/repo-add.8.txt @@ -75,6 +75,12 @@ repo-add Options Only add packages that are not already in the database. Warnings will be printed upon detection of existing packages, but they will not be re-added.
+*-R, \--remove*:: + If an existing package with the same name exists in the database and on + disk, remove it from disk well as updating the database entry for the + package. This is designed to be Used when updating an existing package to + a new version. + See Also -------- linkman:makepkg[8], linkman:pacman[8], linkman:pkgdelta[8] diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in index 4470dd0..91574b3 100644 --- a/scripts/repo-add.sh.in +++ b/scripts/repo-add.sh.in @@ -31,6 +31,7 @@ declare -r confdir='@sysconfdir@' QUIET=0 DELTA=0 ONLYADDNEW=0 +RMEXISTING=0 WITHFILES=0 SIGN=0 VERIFY=0 @@ -58,6 +59,7 @@ Multiple packages to add can be specified on the command line.\n")" printf -- "$(gettext "Options:\n")" printf -- "$(gettext " -d, --delta generate and add delta for package update\n")" printf -- "$(gettext " -n, --new only add packages that are not already in the database\n")" + printf -- "$(gettext " -R, --remove remove any existing packages with the same name (eg, an older version)\n")" printf -- "$(gettext " -f, --files update database's file list\n")" elif [[ $cmd == "repo-remove" ]] ; then printf -- "$(gettext "Usage: repo-remove [options] <path-to-db> <packagename|delta> ...\n")" @@ -304,6 +306,15 @@ db_write_entry() { local oldfilename=$(grep -A1 FILENAME "$pkgentry/desc" | tail -n1) local oldfile="$(dirname "$1")/$oldfilename" fi + elif (( RMEXISTING )); then + # only remove existing package if we're not doing deltas + pkgentry=$(find_pkgentry "$pkgname") + if [[ -n $pkgentry ]]; then + local oldfilename="$(awk '/%FILENAME%/ {getline; print}' "$pkgentry/desc")"
See Dave's comment about using sed here.
+ local oldfile="$(dirname "$1")/$oldfilename" + msg2 "$(gettext "Removing existing package '%s'")" "$oldfilename" + rm -f ${oldfile} ${oldfile}.sig + fi fi fi
@@ -611,6 +622,7 @@ while (( $# )); do -q|--quiet) QUIET=1;; -d|--delta) DELTA=1;; -n|--new) ONLYADDNEW=1;; + -R|--remove) RMEXISTING=1;; -f|--files) WITHFILES=1;; --nocolor) USE_COLOR='n';; -s|--sign)
On 31 May 2013 10:51, Allan McRae <allan@archlinux.org> wrote:
Hint: add comments like "Updated this patch"... under the "---" above. Then it is not part of the commit message.
Thanks Allan; was not aware of that. Will do next time.
+ elif (( RMEXISTING )); then + # only remove existing package if we're not doing deltas + pkgentry=$(find_pkgentry "$pkgname") + if [[ -n $pkgentry ]]; then + local oldfilename="$(awk '/%FILENAME%/ {getline; print}' "$pkgentry/desc")"
See Dave's comment about using sed here.
I saw that this morning; do you want me to amend the patch to use sed? If so, how do I do that with git without having to do everything over again instead of creating a new commit that will generate 2 patches (1 for the original change, and 1 to fix the first)?
On 31/05/13 11:07, Phillip Smith wrote:
On 31 May 2013 10:51, Allan McRae <allan@archlinux.org> wrote:
Hint: add comments like "Updated this patch"... under the "---" above. Then it is not part of the commit message.
Thanks Allan; was not aware of that. Will do next time.
+ elif (( RMEXISTING )); then + # only remove existing package if we're not doing deltas + pkgentry=$(find_pkgentry "$pkgname") + if [[ -n $pkgentry ]]; then + local oldfilename="$(awk '/%FILENAME%/ {getline; print}' "$pkgentry/desc")"
See Dave's comment about using sed here.
I saw that this morning; do you want me to amend the patch to use sed?
Yes please.
If so, how do I do that with git without having to do everything over again instead of creating a new commit that will generate 2 patches (1 for the original change, and 1 to fix the first)?
Assuming it is the top commit, make the adjustment in makepkg.sh.in. Then "git add makepkg.sh.in", "git commit --amend". Or in one command "git commit -a --amend". Allan
On 31 May 2013 11:15, Allan McRae <allan@archlinux.org> wrote:
Assuming it is the top commit, make the adjustment in makepkg.sh.in. Then "git add makepkg.sh.in", "git commit --amend". Or in one command "git commit -a --amend".
Wow. That is so much simpler and I feel like an idiot for not realizing --amend can alter the contents of a commit, not just the commit message. Thanks! :D
participants (2)
-
Allan McRae
-
Phillip Smith