'
while [ $i -le $n ]; do
- file=$name.$i ctf=$dir/$name.content-type
- vname=$file.`cat $dir/$file.rowid`
- if [ -s $ctf ]; then
- case `cat $ctf` in
- *:[Ii]mage:*)
-
- ;;
-
- esac
- fi
- val="`cat $dir/$file|htmlescape`"
+ file=$name.$i
+ vname=$file.`cat "$dir/$file.rowid"`
+ val="`cat $dir/$file`"
cat<($i) |
"
shift
for i; do
- echo ""
+ echo ""
done
echo ""
}
diff --git a/s4-funcs.sh b/s4-funcs.sh
index 7f86f81..fd0bb51 100755
--- a/s4-funcs.sh
+++ b/s4-funcs.sh
@@ -642,7 +642,7 @@
vcount=`query "select count(val) from $cond;"`
echo $vcount > $td/$c.count
i=0
-err gvbid: i=$i vcount=$vcount
+## err gvbid: i=$i vcount=$vcount
while [ $i -lt $vcount ]; do
slice="order by rowid limit 1 offset $i"
i=$((i+1))
@@ -651,31 +651,37 @@
case $type in
file:*)
#file=$td/$val
- file=$td/`query "select val from $cond $slice;"`
+ r_f=`query "select rowid||'//'||val from $cond $slice;"`
+ f_rid=${r_f%%//*}
+ file=$td/${r_f##*//}
# FOR SPEED: Skip file generation if imgcache exists
- [ -s $file -a -s $td/$fn.rowid -a -s $file.rowid ] && continue
+ [ -s "$file" -a -s "$td/$fn.rowid" -a -s "$file.rowid" ] \
+ && [ x"$f_rid" = x"`cat $td/$fn.rowid`" ] \
+ && continue
# err gvbid-get="select quote(bin) from $cond $slice;"
- sq $db< $file
-.output $td/$fn.rowid
+## err output: "fn=[$fn] file=[$file]"
+ sq $db< "$file"
+.output '$td/$fn.rowid'
select rowid from $cond $slice;
-.output $td/$fn
+.output '$td/$fn'
select val from $cond $slice;
-.output $file.content-type
+.output '$td/${fn}.content-type'
select substr(type, 6) from $cond $slice;
.output stdout
select quote(bin) from $cond $slice;
EOF
## err gvbid-get2: "`ls -lF $file`"
## err i=$i - file=$file rowid=`cat $td/$fn.rowid`
- cp $td/$fn.rowid $file.rowid 2>&3 # for convenience
- cp $file $file.orig 2>&3
- ls -lh $file | awk '{print $5"B"}'|sed 's/BB/B/' > $file.size
- case $type in
- *:[Ii]mage*) mogrify -geometry $thumbxy $file ;;
+ cp "$td/$fn.rowid" "$file.rowid" 2>&3 # for convenience
+ cp "$file" "$file.orig" 2>&3
+ ls -lh "$file" |
+ awk '{print $5"B"}'|sed 's/BB/B/' > "$file.size"
+ case "$type" in
+ *:[Ii]mage*) mogrify -geometry $thumbxy "$file" ;;
### ここのアイコンを増やしたい
*|*:[Aa]pplication*)
convert -geometry $thumbxy $imgdir/file-icon.png \
- png:- > $file
+ png:- > "$file"
;;
esac
;;
@@ -697,14 +703,13 @@
echo "$val" \
| while read fn; do
file=$td/$fn
- if [ ! -s $file ]; then
+ if [ ! -s "$file" ]; then
## sq $db "select quote(bin) from $cond and val=\"$fn\"" \
query "select quote(bin) from $cond and val=\"$fn\";" \
- | unhexize > $file
- echo ${type#file:} > $file.content-type
-# err TTTTTTTTTTTTTTTT: $type
+ | unhexize > "$file"
+ ##@@## -- echo ${type#file:} > "$file.content-type"
case $type in
- *:[Ii]mage*) mogrify -geometry $thumbxy $file ;;
+ *:[Ii]mage*) mogrify -geometry $thumbxy "$file" ;;
*:[Aa]pplication*)
convert -geometry $thumbxy $imgdir/file-icon.png \
png:- > $file ;;
@@ -788,7 +793,7 @@
hexize="hexize_hd"
fi
fi
- cat $1 | $hexize | tr -d '\n'
+ cat "$@" | $hexize | tr -d '\n'
}
unhexize() {
if [ -z "$unhex" ]; then
@@ -804,11 +809,11 @@
unhex="perl -n $tmpd/unhex.pl"
fi
fi
- cat $1 | $unhex
+ cat "$@" | $unhex
# cat $1 | tee /tmp/uh.in| $unhex | tee /tmp/uh.out
}
percenthex() {
- hexize $1 | sed 's/\(..\)/%\1/g'
+ hexize "$@" | sed 's/\(..\)/%\1/g'
}
htmlescape() {
sed -e 's/\&/\&/g' -e 's/"/\"/g' -e "s/'/\'/g" \
@@ -939,8 +944,8 @@
type=encoded ### val=`echo $val|encode`
;;
*/image*|*/document*)
- type=`file --mime-type $val`
- bin="X'`hexize $val`'"
+ type=`file --mime-type - < "$val" | cut -d' ' -f2`
+ bin="X'`hexize "$val"`'"
;;
esac
pkey=`echo "$tconfs"|grep "${t0}/.*=p"|sed 1q`
@@ -1151,15 +1156,20 @@
case "$k" in
*:filename)
type='file'; k=${k%:filename}
-(echo k=$k; ls -lF $tmpd/$v; file --mime-type $tmpd/$v) 1>&3
- case `file --mime-type $tmpd/$v|cut -d' ' -f2` in
+ # DO NOT ALLOW Space and '|' in file names
+ newv=`echo "$v"|sed 's/[ \|]/X/g'`
+ if [ x"$v" != x"$newv" ]; then
+
+ fi
+# (echo k=$k v="[$v]"; ls -lF "$tmpd/$v"; file --mime-type "$tmpd/$v") 1>&3
+ case `file --mime-type - < "$tmpd/$v"|cut -d' ' -f2` in
[Ii]mage/x-xcf)
- bzip2 $tmpd/$v
+ bzip2 "$tmpd/$v"
v=${v}.bz2
;;
[Ii]mage/x-*|*/vnd.*) ;;
[Ii]mage/*)
- mogrify -resize $maximagexy'>' $tmpd/$v
+ mogrify -resize $maximagexy'>' "$tmpd/$v"
;;
esac
;;
@@ -1534,10 +1544,10 @@
| tee $fifo \
| convert -define ${fmt}:size=${iconxy_M}x${iconxy_M} \
-resize ${iconxy_M}x${iconxy_M}'>' - pnm:- \
- | convert - $cacheimg_M &
+ | convert - "$cacheimg_M" &
cat $fifo | convert -define ${fmt}:size=${iconxy_S}x${iconxy_S} \
-resize ${iconxy_S}x${iconxy_S}'>' - pnm:- \
- | convert - $cacheimg_S &
+ | convert - "$cacheimg_S" &
printf '%s' "'
@@ -1765,8 +1775,8 @@
}
iconhref() (
# $1=icon-file, $2=Href $3=title $4...=anchor
- data=`percenthex $1`
- ct=`file --mime-type $1|cut -d' ' -f2`
+ data=`percenthex "$1"`
+ ct=`file --mime-type - < "$1"|cut -d' ' -f2`
err iconhref: \$1=$1 \$2=$2 \$3="$@"
href=$2; title=$3; shift 3
echo "$@"
@@ -2967,13 +2977,13 @@
err type=file=$file
[ -z "$file" ] && continue
bn=`sqlquotestr "${file##*/}"`
- bin="X'"$(hexize $file)"'"
- ct=`file --mime-type $file|cut -d' ' -f2`
+ bin="X'"$(hexize "$file")"'"
+ ct=`file --mime-type - < "$file" |cut -d' ' -f2`
type=\"file:$ct\"
newsql="update $tb2 set val=$bn, type=$type, bin=$bin"
cachedir=`getcachedir "$tbl/$rowid"`
err getcache tbl/rowid=$tbl/$rowid, rm -r $cachedir
- rm -r $cachedir
+ rm -rf $cachedir
;;
*)
newsql="update $tb2 set val=(select val from par where var \
@@ -3020,8 +3030,8 @@
file) file=$tmpd/`getparfilename $col "$limit"`
err parfile-$col=$file
[ -z "$file" ] && continue
- bin="X'"$(hexize $file)"'"
- ct=`file --mime-type $file|cut -d' ' -f2`
+ bin="X'"$(hexize "$file")"'"
+ ct=`file --mime-type - < "$file"|cut -d' ' -f2`
type=\"file:$ct\" ;;
"*"*) continue ;; # foreign table
*) type=\"string\" ;;
@@ -3119,7 +3129,7 @@
rawval=`getvalbyid $2 $name $rowid $td`
val=`echo "$rawval"|htmlescape`
err genform3a: getvalbyid $2 $name $rowid $td
-err genform3b: val="[$val]"
+err genform3b: val="[$val]" type="$type"
fi
if [ -n "$GF_VIEWONLY" ]; then
is_hidden "$2" "$name" && continue
@@ -3161,27 +3171,28 @@
;;
[Ii][Mm][Aa][Gg][Ee]|[Dd][Oo][Cc][Uu][Mm][Ee][Nn][Tt]|[Bb]inary)
if [ -s $td/$name.count ]; then
+err Calling cgi_multi_file: "nae=[$name] td=[$td] args=[$args]"
form=`cgi_multi_file $name $td "$args"`
if [ -n "$val" ]; then
hrfb="$myname?showattc+$2_m"
val=$(echo "$rawval" \
| while read fn; do
- data=`percenthex $td/$fn`
+ data=`percenthex "$td/$fn"`
#ct=`cat $td/$fn.content-type`
- ct=`file --mime-type $td/$fn|cut -d' ' -f2`
- ri=`cat $td/$fn.rowid`
-## err fn=$fn, name=$name, ri=$ri; ls -lF $td 1>&3
+ ct=`file --mime-type - < "$td/$fn"|cut -d' ' -f2`
+ ri=`cat "$td/$fn.rowid"`
+ err fn=$fn, name=$name, ri=$ri; ls -lF "$td/" 1>&3
#imgsrc=""
#echo "$imgsrc "
- iconhref $td/$fn "$hrfb+$ri" ""
+ iconhref "$td/$fn" "$hrfb+$ri" ""
done)
fi
else
form=""
if [ -n "$val" ]; then
- imgs=$(echo "$val"\
+ imgs=$(echo "$rawval"\
|while read fn;do
- data=`percenthex $td/$fn`
+ data=`percenthex "$td/$fn"`
echo "$fn "
done)
form=$form" $imgs"
@@ -3286,8 +3297,8 @@
sql="select quote(bin) from $1 where rowid='$2';"
err showattc: sql: $sql
sq $db "$sql" | unhexize > $bin
- tv=`query "select type,val from $1 where rowid='$2';"`
- type=${tv%\|*} fn=${tv#*\|}
+ tv=`query "select type||'//'||val from $1 where rowid='$2';"`
+ type=${tv%//*} fn=${tv#*//}
err tv=$tv type=$type fn=$fn, tp2=${tv%\|*}
ct=${type#file:}
case $ct in # all text/* changed to text/plain
|