1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-10-23 04:30:24 +02:00

34067: safe tempfile creation, part 1

This commit is contained in:
Barton E. Schaefer 2014-12-27 23:59:29 -08:00
parent 1cd8023570
commit 200accac63
15 changed files with 75 additions and 65 deletions

View file

@ -12,7 +12,6 @@ fi
local ZFTP_VERBOSE=45
# should we redirect 2>/dev/null or let the user see it?
local tmpf=${TMPPREFIX}zfcm$$
local -a match mbegin mend
if [[ $ZFTP_SYSTEM = UNIX* ]]; then
@ -27,9 +26,10 @@ if [[ $ZFTP_SYSTEM = UNIX* ]]; then
# If we're using -F, we get away with using a directory
# to list, but not a glob. Don't ask me why.
reply=(${${(M)${(f)"$(zftp ls -lF $dir)"}:#d*}/(#b)*[[:space:]](*)\//$match[1]})
# zftp ls -LF $dir >$tmpf
# reply=($(awk '/\/$/ { print substr($1, 1, length($1)-1) }' $tmpf))
# rm -f $tmpf
# () {
# zftp ls -LF $dir >|$1
# reply=($(awk '/\/$/ { print substr($1, 1, length($1)-1) }' $1))
# } =(:)
[[ -n $dir && $dir != */ ]] && dir="$dir/"
if [[ -n $WIDGET ]]; then
_wanted directories expl 'remote directory' \

View file

@ -14,7 +14,7 @@ emulate -L zsh
[[ $curcontext = :zf* ]] || local curcontext=:zfcget
local loc rem stat=0 opt opt_G opt_t remlist locst remst
local tmpfile=${TMPPREFIX}zfcget$$ rstat tsize
local rstat tsize
while getopts :Gt opt; do
[[ $opt = '?' ]] && print "zfcget: bad option: -$OPTARG" && return 1
@ -39,10 +39,11 @@ for remlist in $*; do
else
# Compare the sizes.
locst=($(zftp local $loc))
zftp remote $rem >$tmpfile
rstat=$?
remst=($(<$tmpfile))
rm -f $tmpfile
() {
zftp remote $rem >|$1
rstat=$?
remst=($(<$1))
} =(: temporary file)
if [[ $rstat = 2 ]]; then
print "Server does not support SIZE command.\n" \
"Assuming you know what you're doing..." 2>&1

View file

@ -14,7 +14,6 @@ emulate -L zsh
[[ $curcontext = :zf* ]] || local curcontext=:zfcput
local loc rem stat=0 locst remst offs tailtype
local tmpfile=${TMPPREFIX}zfcget$$ rstat
# find how tail works. this is intensely annoying, since it's completely
# standard in C. od's no use, since we can only skip whole blocks.
@ -40,10 +39,11 @@ for loc in $*; do
else
# Compare the sizes.
locst=($(zftp local $loc))
zftp remote $rem >$tmpfile
rstat=$?
remst=($(<$tmpfile))
rm -f $tmpfile
() {
zftp remote $rem >|$1
rstat=$?
remst=($(<$1))
} =(: temporary file)
if [[ $rstat = 2 ]]; then
print "Server does not support remote status commands.\n" \
"You will have to find out the size by hand and use zftp append." 2>&1

View file

@ -19,8 +19,5 @@ fi
if [[ $1 = -d ]]; then
unset $fcache_name
elif (( ${(P)#fcache_name} == 0 )); then
local tmpf=${TMPPREFIX}zffcache$$
zftp ls >$tmpf
eval "$fcache_name=(\${(f)\"\$(<\$tmpf)\"})"
rm -f $tmpf
eval "$fcache_name=(\${(f)\"\$(zftp ls)\"})"
fi

View file

@ -7,22 +7,22 @@ if [[ $1 == $HOME || $1 == $HOME/* ]]; then
1="~${1#$HOME}"
fi
local tmpf=${TMPPREFIX}zfgm$$
if [[ $ZFTP_SYSTEM == UNIX* && $1 == */* ]]; then
setopt localoptions clobber
local tmpf=${TMPPREFIX}zfgm$$
mv -f =(:) $tmpf
if [[ -n $WIDGET ]]; then
local dir=${1:h}
[[ $dir = */ ]] || dir="$dir/"
zftp ls -LF $dir >$tmpf
local reply
reply=(${${${(f)"$(<$tmpf)"}##$dir}%\*})
rm -f $tmpf
_wanted files expl 'remote file' compadd -P $dir - $reply
else
# On the first argument to ls, we usually get away with a glob.
zftp ls "$1*$2" >$tmpf
reply=($(<$tmpf))
rm -f $tmpf
fi
else
local fcache_name

View file

@ -33,12 +33,12 @@ if [[ $pat != *[][*?]* &&
( -n $zfrglob || $pat != *[(|)#^]* ) ]]; then
return 0
fi
local tmpf=${TMPPREFIX}zfrglob$$
if [[ $zfrglob != '' ]]; then
zftp ls "$pat" >$tmpf 2>/dev/null
eval "$1=(\$(<\$tmpf))"
rm -f $tmpf
() {
zftp ls "$pat" >|$1 2>/dev/null
eval "$1=(\$(<\$1))"
} =(: temporary file)
else
if [[ $ZFTP_SYSTEM = UNIX* && $pat = */* ]]; then
# not the current directory and we know how to handle paths
@ -49,10 +49,11 @@ else
dir=/
fi
nondir=${pat##*/}
zftp ls "$dir" 2>/dev/null >$tmpf
files=($(<$tmpf))
() {
zftp ls "$dir" 2>/dev/null >|$1
files=($(<$1))
} =(: temporary file)
files=(${files:t})
rm -f $tmpf
else
# we just have to do an ls and hope that's right
local fcache_name

View file

@ -43,10 +43,11 @@ zfautocheck || return 1
local style
zstyle -s ':zftp:zftransfer' progress style
if [[ -n $style && $style != none ]]; then
local ZFTP_TSIZE array tmpfile=${TMPPREFIX}zft$$
zftp remote $file1 >$tmpfile 2>/dev/null
array=($(<$tmpfile))
rm -f $tmpfile
local ZFTP_TSIZE array
() {
zftp remote $file1 >|$1 2>/dev/null
array=($(<$1))
} =(: temporary file)
[[ $#array -eq 2 ]] && ZFTP_TSIZE=$array[1]
fi

View file

@ -1,13 +1,11 @@
# function zftype {
local type zftmp=${TMPPREFIX}zftype$$
local type
[[ $curcontext = :zf* ]] || local curcontext=:zftype
zfautocheck -d
if (( $# == 0 )); then
zftp type >$zftmp
type=$(<$zftmp)
rm -f $zftmp
type=$(zftp type)
if [[ $type = I ]]; then
print "Current type is image (binary)"
return 0

View file

@ -26,7 +26,7 @@
emulate -L zsh
[[ $curcontext = :zf* ]] || local curcontext=:zfuget
local loc rem locstats remstats doit tmpfile=${TMPPREFIX}zfuget$$
local loc rem locstats remstats doit
local rstat remlist opt opt_v opt_s opt_G opt_t
integer stat do_close
@ -66,12 +66,13 @@ for remlist in $*; do
doit=y
remstats=()
if [[ -f $loc ]]; then
zftp local $loc >$tmpfile
locstats=($(<$tmpfile))
zftp remote $rem >$tmpfile
rstat=$?
remstats=($(<$tmpfile))
rm -f $tmpfile
() {
zftp local $loc >|$1
locstats=($(<$1))
zftp remote $rem >|$1
rstat=$?
remstats=($(<$1))
} =(: temporary file)
if [[ $rstat = 2 ]]; then
print "Server does not implement full command set required." 1>&2
return 1

View file

@ -12,7 +12,7 @@
emulate -L zsh
[[ $curcontext = :zf* ]] || local curcontext=:zfuput
local loc rem locstats remstats doit tmpfile=${TMPPREFIX}zfuput$$
local loc rem locstats remstats doit
local rstat opt opt_v opt_s
integer stat do_close
@ -52,12 +52,13 @@ for rem in $*; do
stat=1
continue
fi
zftp local $loc >$tmpfile
locstats=($(<$tmpfile))
zftp remote $rem >$tmpfile
rstat=$?
remstats=($(<$tmpfile))
rm -f $tmpfile
() {
zftp local $loc >|$1
locstats=($(<$1))
zftp remote $rem >|$1
rstat=$?
remstats=($(<$1))
} =(: temporary file)
if [[ $rstat = 2 ]]; then
print "Server does not implement full command set required." 1>&2
return 1