]> pd.if.org Git - zpackage/commitdiff
improve file handling for addtopackage
authorNathan Wagner <nw@hydaspes.if.org>
Sun, 5 Mar 2017 15:03:14 +0000 (09:03 -0600)
committerNathan Wagner <nw@hydaspes.if.org>
Sun, 5 Mar 2017 15:05:16 +0000 (09:05 -0600)
zpm-addtopackage

index 19db69baf815782966b84c7239aa1b17f5317489..05c35963713f4b310f213f2861489cdb61fa039d 100755 (executable)
@@ -20,6 +20,8 @@ while getopts :f:v:r:d:a:u:l:p:b:P: opt; do
                p) packager="$OPTARG" ;;
                b) builddate="$OPTARG" ;;
                P) prefix="$OPTARG" ;;
+               t) tags="$OPTARG" ;;
+               c) tags="$tags +configuration" ;;
        esac
 done
 
@@ -39,12 +41,12 @@ else
 fi
 
 for path in $*; do
-       mtime=$(zpm stat -t '%y' $path)
-       uid=$(zpm stat -t '%u' $path)
-       gid=$(zpm stat -t '%g' $path)
-       username=$(zpm stat -t '%U' $path)
-       groupname=$(zpm stat -t '%G' $path)
-       mode=$(zpm stat -t '%a' $path)
+       mtime=$(zpm stat -f '%y' $path)
+       uid=$(zpm stat -f '%u' $path)
+       gid=$(zpm stat -f '%g' $path)
+       username=$(zpm stat -f '%U' $path)
+       groupname=$(zpm stat -f '%G' $path)
+       mode=$(zpm stat -f '%a' $path)
 
        # strip off leading slashes
        rpath=$(echo "$path" | sed -e 's|^/*||')
@@ -62,35 +64,34 @@ for path in $*; do
                rpath="$prefix/$rpath"
        fi
 
-       if [ -f "$path" ]; then
-
-               hash=$(zpm addfile $pkgfile $path)
-
-#if [ -z "$hash" ]; then continue; fi
+       filetype=$(zpm stat -f '%t' "$path")
+       hash='NULL'
+       target='NULL'
+       case "$filetype" in
+               regular)
+                       filetype=d
+                       hash=$(zpm addfile $pkgfile "$path")
+                       hash="'$hash'"
+                       filetype=r
+                       ;;
+               directory)
+                       filetype=d
+                       ;;
+               symlink)
+                       filetype=l
+                       target=$(readlink $path)
+                       target="'$target'"
+                       ;;
+       esac
 
-# TODO mtime, mode
-sqlite3 $pkgfile <<EOS
-PRAGMA foreign_keys = ON;
-insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,hash)
-values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$hash')
-;
-EOS
-elif [ -d "$path" ]; then
-sqlite3 $pkgfile <<EOS
+       sqlite3 $pkgfile <<EOS
 PRAGMA foreign_keys = ON;
-insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname)
-values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname')
-;
+begin;
+insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,filetype,hash,target)
+values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$filetype',$hash,$target);
+commit;
 EOS
-elif [ -l "$path" ]; then
-       target=$(readlink $path)
-sqlite3 $pkgfile <<EOS
-PRAGMA foreign_keys = ON;
-insert or replace into packagefiles (package,version,release,path,mode,mtime,username,groupname,target)
-values ('$package', '$pkgver', $pkgrel, '$rpath', '$mode',$mtime, '$username','$groupname','$target')
-;
-EOS
-fi
+
 #printf "%s %s%s\n" $path $rpath ${target:+" -> $target"}
 printf "%s\n" $path
 done