]> pd.if.org Git - zpackage/blobdiff - zpm-install
add conflict checking for installs
[zpackage] / zpm-install
index 173ff1b85a3371b3f3650ce9461f469a21d09e9c..af14c4d364de847df6591293b583a539cab34d12 100755 (executable)
@@ -154,9 +154,10 @@ pkgname() {
 # paths to replace
 
 newfiles() {
-       #zpm merge $pkgfile $newver
-
-       # add...
+       nv=$1
+       ov=$2
+#      printf "zzz checking %s vs %s\n" "$1" "$2"
+#      printf "zzz checking %s vs %s\n" "$nv" "$ov"
        zpm shell $ZPMDB<<-EOS
        select NV.path
        from packagefiles NV
@@ -172,8 +173,6 @@ newfiles() {
 }
 
 removedfiles() {
-       #zpm merge $pkgfile $newver
-
        zpm shell $ZPMDB<<-EOS
        select OV.path
        from packagefiles OV
@@ -213,20 +212,22 @@ do_upgrade() {
        zpm merge $pkgfile $newver
        zpm pkg $newver status installing
 
-       echo newfiles
-       newct=$(newfiles | wc -l)
+       newct=$(newfiles "$newver" "$oldver" | wc -l)
+       echo newfiles $newct
+
        if [ $newct -gt 0 ]; then
-               newfiles $newver $oldver | xargs zpm ipkgfile ${user+-u $user} ${group+-g $group} -R "$pkgroot" -f $pkgfile -- $nver
+       newfiles $newver $oldver
+       { newfiles "$newver" "$oldver"; } | xargs zpm ipkgfile ${user+-u $user} ${group+-g $group} -R "$pkgroot" -f $pkgfile -- $nver
        fi
 
-       echo changed
-       ct=$(changedfiles | wc -l)
+       ct=$(changedfiles $newver $oldver | wc -l)
+       echo changed $ct
        if [ $ct -gt 0 ]; then
                changedfiles $newver $oldver | xargs zpm ipkgfile ${user+-u $user} ${group+-g $group} -R "$pkgroot" -f $pkgfile -- $pkg
        fi
 
-       echo removed
-       ct=$(removedfiles | wc -l)
+       ct=$(removedfiles $newver $oldver | wc -l)
+       echo removed $ct
        if [ $ct -gt 0 ]; then
                removedfiles $newver $oldver | xargs rm
        fi
@@ -241,6 +242,49 @@ do_upgrade() {
        EOS
 }
 
+conflicts() {
+       echo conflict check $pkg $pkgfile
+       #newver=$1
+       {
+       zpm shell $pkgfile<<-EOS
+               .separator " "
+               select hash,path from packagefiles
+               where package||'-'||version||'-'||release = '$pkg'
+               and filetype = 'r'
+               ;
+       EOS
+       } | while read hash path; do
+               rpath=$pkgroot$path
+               if [ -f $rpath ]; then
+                       ihash=$(zpm hash $rpath)
+                       if [ $ihash != $hash ]; then
+                               die $path already exists
+                       fi
+               elif [ -d $rpath ]; then
+                       die $path already exists
+               fi
+       done
+
+       {
+       zpm shell $pkgfile<<-EOS
+               .separator " "
+               select path from packagefiles
+               where package||'-'||version||'-'||release = '$pkg'
+               and filetype = 'd'
+               ;
+       EOS
+       } | while read hash path; do
+               rpath=$pkgroot$path
+               if [ -f $rpath ]; then
+                       die $path already exists
+               elif [ -d $rpath ]; then
+                       die $path already exists
+               elif [ -e $rpath ]; then
+                       die $path already exists
+               fi
+       done
+}
+
 for pkg in $pkglist; do
        pname=$(pkgname $pkg)
        curver=$(zpm findpkg $ZPMDB $pname)
@@ -276,6 +320,8 @@ for pkg in $pkglist; do
 
        # check for conflicts
 
+       conflicts $pkgroot $pkg
+
        # mark package in localdb as installing
        # zpm setmark installing $pkg
        # install all the files for a package
@@ -285,12 +331,14 @@ for pkg in $pkglist; do
        echo $filecount files
        #die 'aborting for test'
        #pathlist
+       zpm pkg $pkg status installing
        pathlist | xargs zpm ipkgfile ${user+-u $user} ${group+-g $group} -R "$pkgroot" -f $pkgfile -- $pkg
 
        # TODO find scripts marked as post-install
        # TODO if this is an upgrade, run post-upgrade
 
        # mark as ready for install
+       zpm pkg $pkg status installed
        #zpm setmark ready $pkg
 done