about summary refs log tree commit diff
path: root/Functions/Zftp/zfautocheck
blob: abb994061bbe8531caaaf61d2044b2eede89a4a0 (plain) (blame)
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
# function zfautocheck {
# This function is used to implement auto-open behaviour.
#
# With first argument including n, don't change to the old directory; else do.
#
# Set do_close to 1 if the connection was not previously open, 0 otherwise
# With first arguemnt including d, don't set do_close to 1.  Broadly
# speaking, we use this mechanism to shut the connection after use
# if the connection had been explicitly closed (i.e. didn't time out,
# which zftp test investigates) and we are not using a directory
# command, which implies we are looking for something so should stay open
# for it.

# Remember the old session:  zflastsession will be overwritten by
# a successful open.
local lastsession=$zflastsession

if [[ -z $ZFTP_HOST ]]; then
  zfopen || return 1
  [[ $1 = *d* ]] || do_close=1
elif zftp test 2>/dev/null; then
  return 0
else
  zfopen || return 1
fi

if [[ $1 = *n* ]]; then
  return 0
elif [[ -n $lastsession && $ZFTP_HOST = ${lastsession%%:*} ]]; then
  zfcd ${lastsession#*:}
fi

# }