File: zfput

package info (click to toggle)
zsh-beta 4.3.0-dev-1%2B20050424-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 18,240 kB
  • ctags: 6,564
  • sloc: ansic: 79,241; sh: 4,874; perl: 748; makefile: 676; awk: 341; sed: 16
file content (68 lines) | stat: -rw-r--r-- 1,444 bytes parent folder | download | duplicates (19)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# function zfput {
# Simple put:  dump every file under the same name, but stripping
# off any directory parts to get the remote filename (i.e. always
# goes into current remote directory).  Use zfpcp to specify new
# file name or new directory at remote end.
#
# -r means put recursively:  any directories encountered will have
#    all their contents to arbitrary depth transferred.  Note that
#    this creates the required directories.  Any files in subdirectories
#    whose names begin with a `.' will also be included.

emulate -L zsh

[[ $curcontext = :zf* ]] || local curcontext=:zfput
local opt opt_r
integer stat do_close abort

while getopts :r opt; do
  [[ $opt = '?' ]] && print "zfget: bad option: -$OPTARG" && return 1
  eval "opt_$opt=1"
done
(( OPTIND > 1 )) && shift $(( OPTIND - 1 ))

zfautocheck

zfput_sub() {
  local subdirs loc rem
  integer stat
  subdirs=()

  for loc in $*; do
    if [[ -n $opt_r ]]; then
      if [[ -d $loc ]]; then
	subdirs=($subdirs $loc)
	continue
      else
	rem=$loc
      fi
    else
      rem=${loc:t}
    fi

    zftp put $rem <$loc
    (( $? )) && stat=$?
    if ! zftp test; then
      abort=1
      (( stat )) || stat=1
      break;
    fi
  done

  while (( $#subdirs  && ! abort )); do
    zftp mkdir ${subdirs[1]}
    zfput_sub ${subdirs[1]}/*(ND)
    (( $? )) && stat=$?
    shift subdirs
  done

  return $stat
}

zfput_sub $*
stat=$?

(( $do_close )) && zfclose

return $stat
# }