On Tue, Jul 16, 2013 at 8:22 PM, Allan McRae <allan@archlinux.org> wrote:
Signed-off-by: Allan McRae <allan@archlinux.org> --- scripts/pacman-db-upgrade.sh.in | 46 ++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 10 deletions(-)
diff --git a/scripts/pacman-db-upgrade.sh.in b/scripts/pacman-db-upgrade.sh.in index a1630c5..d2cd78d 100644 --- a/scripts/pacman-db-upgrade.sh.in +++ b/scripts/pacman-db-upgrade.sh.in @@ -109,18 +109,44 @@ fi # do not let pacman run while we do this touch "$lockfile"
-# pacman-3.4 to 3.5 upgrade - merge depends into desc -if [[ $(find "$dbroot"/local -name depends) ]]; then - msg "$(gettext "Pre-3.5 database format detected - upgrading...")" - for i in "$dbroot"/local/*; do - if [[ -f "$i"/depends ]]; then - cat "$i"/depends >> "$i"/desc - rm "$i"/depends - fi - done - msg "$(gettext "Done.")" +if [[ -f "${dbroot}"/local/.alpm_db_version ]]; then + db_version=($(cat "${dbroot}"/local/.alpm_db_version))
Why is db_version an array?
fi
+if [[ -z "$db_version" ]]; then + # pacman-3.4 to 3.5 upgrade - merge depends into desc + if [[ $(find "$dbroot"/local -name depends) ]]; then + msg "$(gettext "Pre-3.5 database format detected - upgrading...")" + for i in "$dbroot"/local/*; do + if [[ -f "$i"/depends ]]; then + cat "$i"/depends >> "$i"/desc + rm "$i"/depends + fi + done + msg "$(gettext "Done.")" + fi + + # pacman 4.1 to 4.2 upgrade - remove directory symlink support + dirlist=() + + unset GREP_OPTIONS + while IFS= read -r dir; do + dirlist+=("/${dir%/}") + done < <(grep -h '/$' "$dbroot"/local/*/files | sort -u) + + mapfile -t dirlist < <(find "${dirlist[@]}" -maxdepth 0 -type l) + + if [[ ${#dirlist[@]} != 0 ]]; then + msg "$(gettext "Pre-4.2 database format detected - upgrading...")" + for dir in ${dirlist[@]}; do
missing quote, "${dirlist[@]}"
+ realdir=( $(cd $dir; pwd -P) )
missing quote, "$dir"; why is realdir an array?
+ sed -i "s#^${dir#/}/#${realdir#/}/#" "$dbroot"/local/*/files
If it's almost safe to assume paths don't include '\n', it's far less so to assume they don't include '#'. Also $dir is treated as a pattern, not a fixed string here. This should be better: awk -v "dir=${dir#/}/" -v "realdir=${realdir#/}/" ' BEGIN { i = length(dir) + 1 } { if (index($0, dir) == 1) { printf("%s%s\n", realdir, substr($0, i)) } else { print } }' awk doesn't have the convenience of in place file editting though, so we may have to wrap this inside a loop, and store the updated data in a temp file (or just a var?)...
+ done + fi +fi + +echo "9" > "$dbroot"/local/.alpm_db_version + # remove the lock file rm -f "$lockfile"
-- 1.8.3.3