mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-01-01 05:16:05 +01:00
Baptiste Daroussin: 27267 plus 27269 plus doc:
remove perl dependency
This commit is contained in:
parent
12dfec77e9
commit
49b4a71009
3 changed files with 33 additions and 32 deletions
|
@ -1,3 +1,9 @@
|
|||
2009-09-11 Peter Stephenson <pws@csr.com>
|
||||
|
||||
* Baptiste Daroussin: 27267 plus 27269 plus doc:
|
||||
Functions/Zftp/zfrtime, Doc/Zsh/zftpsys.yo: remove perl
|
||||
dependency.
|
||||
|
||||
2009-09-10 Peter Stephenson <pws@csr.com>
|
||||
|
||||
* Greg Klanderman: 27259 / 27260:
|
||||
|
@ -12146,5 +12152,5 @@
|
|||
|
||||
*****************************************************
|
||||
* This is used by the shell to define $ZSH_PATCHLEVEL
|
||||
* $Revision: 1.4773 $
|
||||
* $Revision: 1.4774 $
|
||||
*****************************************************
|
||||
|
|
|
@ -220,8 +220,7 @@ The commands for retrieving files all take at least two options. tt(-G)
|
|||
suppresses remote filename expansion which would otherwise be performed
|
||||
(see below for a more detailed description of that). tt(-t) attempts
|
||||
to set the modification time of the local file to that of the remote file:
|
||||
this requires version 5 of tt(perl), see the description of the function
|
||||
tt(zfrtime) below for more information.
|
||||
see the description of the function tt(zfrtime) below for more information.
|
||||
|
||||
startitem()
|
||||
findex(zfget)
|
||||
|
@ -462,11 +461,9 @@ findex(zfrtime)
|
|||
item(tt(zfrtime var(lfile) var(rfile) [ var(time) ]))(
|
||||
Set the local file var(lfile) to have the same modification time as the
|
||||
remote file var(rfile), or the explicit time var(time) in FTP format
|
||||
tt(CCYYMMDDhhmmSS) for the GMT timezone.
|
||||
|
||||
Currently this requires tt(perl) version 5 to perform the conversion from
|
||||
GMT to local time. This is unfortunately difficult to do using shell code
|
||||
alone.
|
||||
tt(CCYYMMDDhhmmSS) for the GMT timezone. This uses the shell's
|
||||
tt(zsh/datetime) module to perform the conversion from
|
||||
GMT to local time.
|
||||
)
|
||||
findex(zftp_chpwd, supplied version)
|
||||
item(tt(zftp_chpwd))(
|
||||
|
|
|
@ -6,12 +6,13 @@
|
|||
#
|
||||
# Unfortunately, since the time returned from FTP is GMT and
|
||||
# your file needs to be set in local time, we need to do some
|
||||
# hacking around with time. At the moment this requires perl 5
|
||||
# with the standard library.
|
||||
# hacking around with time.
|
||||
|
||||
emulate -L zsh
|
||||
zmodload zsh/datetime
|
||||
|
||||
local time gmtime loctime
|
||||
local time gmtime loctime year mon mday hr min sec y tmpdate
|
||||
local -i days_since_epoch
|
||||
|
||||
if [[ -n $3 ]]; then
|
||||
time=$3
|
||||
|
@ -21,25 +22,22 @@ else
|
|||
fi
|
||||
[[ -z $time ]] && return 1
|
||||
|
||||
# Now's the real *!@**!?!. We have the date in GMT and want to turn
|
||||
# it into local time for touch to handle. It's just too nasty
|
||||
# to handle in zsh; do it in perl.
|
||||
if perl -mTime::Local -e '($file, $t) = @ARGV;
|
||||
$yr = substr($t, 0, 4) - 1900;
|
||||
$mon = substr($t, 4, 2) - 1;
|
||||
$mday = substr($t, 6, 2) + 0;
|
||||
$hr = substr($t, 8, 2) + 0;
|
||||
$min = substr($t, 10, 2) + 0;
|
||||
$sec = substr($t, 12, 2) + 0;
|
||||
$time = Time::Local::timegm($sec, $min, $hr, $mday, $mon, $yr);
|
||||
utime $time, $time, $file and return 0;' $1 $time 2>/dev/null; then
|
||||
print "Setting time for $1 failed. Need perl 5." 2>1
|
||||
fi
|
||||
year=$time[1,4]
|
||||
mon=$time[5,6]
|
||||
mday=$time[7,8]
|
||||
hr=$time[9,10]
|
||||
min=$time[11,12]
|
||||
sec=$time[13,14]
|
||||
|
||||
# If it wasn't for the GMT/local time thing, it would be this simple.
|
||||
#
|
||||
# time="${time[1,12]}.${time[13,14]}"
|
||||
#
|
||||
# touch -t $time $1
|
||||
|
||||
# }
|
||||
#count the number of days since epoch without the current day
|
||||
for y in {1970..$(( $year - 1))}; do
|
||||
strftime -s tmpdate -r "%Y/%m/%d" ${y}/12/31
|
||||
days_since_epoch+=$(strftime "%j" $tmpdate)
|
||||
done
|
||||
strftime -s tmpdate -r "%Y/%m/%d" $year/$mon/$(( $mday - 1 ))
|
||||
days_since_epoch+=$(strftime "%j" $tmpdate)
|
||||
# convert the time in number of seconds (this should be equivalent to timegm)
|
||||
time=$(( $sec + 60 * ( $min + 60 * ($hr + 24 * $days_since_epoch)) ))
|
||||
#Convert it back to CCYYMMDDhhmmSS
|
||||
strftime -s time "%Y%m%d%H%M%S" ${EPOCHSECONDS}
|
||||
touch -t ${time[1,12]}.${time[13,14]} $1
|
||||
|
|
Loading…
Reference in a new issue