* [PATCH] Remove perl dependency in zftp
@ 2009-09-11 10:37 Baptiste Daroussin
2009-09-11 10:58 ` Peter Stephenson
0 siblings, 1 reply; 3+ messages in thread
From: Baptiste Daroussin @ 2009-09-11 10:37 UTC (permalink / raw)
To: zsh-workers
[-- Attachment #1: Type: text/plain, Size: 111 bytes --]
Hi,
Here is a patch to remove the perl dependency in the zfrtime of zftp
Seems to work for me
regards,
Bapt
[-- Attachment #2: zfrtime-remove-perl.patch --]
[-- Type: application/octet-stream, Size: 1871 bytes --]
diff --git a/Functions/Zftp/zfrtime b/Functions/Zftp/zfrtime
index f63ffe0..be95c43 100644
--- a/Functions/Zftp/zfrtime
+++ b/Functions/Zftp/zfrtime
@@ -10,8 +10,10 @@
# with the standard library.
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 +23,19 @@ 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
-
-# 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
+year=$time[1,4]
+mon=$time[5,6]
+mday=$time[7,8]
+hr=$time[9,10]
+min=$time[11,12]
+sec=$time[13,14]
-# }
+#count the number of days since epoch without the current day
+for y ({1970..$(( $year - 1))}){ strftime -s tmpdate -r "%Y/%m/%d" ${y}/12/31; days_since_epoch+=$(strftime "%j" $tmpdate) }
+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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Remove perl dependency in zftp
2009-09-11 10:37 [PATCH] Remove perl dependency in zftp Baptiste Daroussin
@ 2009-09-11 10:58 ` Peter Stephenson
2009-09-11 11:09 ` Baptiste Daroussin
0 siblings, 1 reply; 3+ messages in thread
From: Peter Stephenson @ 2009-09-11 10:58 UTC (permalink / raw)
To: zsh-workers
On Fri, 11 Sep 2009 10:37:32 +0000
Baptiste Daroussin <baptiste.daroussin@gmail.com> wrote:
> Hi,
>
> Here is a patch to remove the perl dependency in the zfrtime of zftp
>
> Seems to work for me
Thanks, I'll take your word for it: this tidies it up a little.
Index: Functions/Zftp/zfrtime
===================================================================
RCS file: /cvsroot/zsh/zsh/Functions/Zftp/zfrtime,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 zfrtime
--- Functions/Zftp/zfrtime 25 Apr 1999 15:43:58 -0000 1.1.1.1
+++ Functions/Zftp/zfrtime 11 Sep 2009 10:57:16 -0000
@@ -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 @@
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
-
-# 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
-
-# }
+year=$time[1,4]
+mon=$time[5,6]
+mday=$time[7,8]
+hr=$time[9,10]
+min=$time[11,12]
+sec=$time[13,14]
+
+#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
--
Peter Stephenson <pws@csr.com> Software Engineer
Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK
Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Remove perl dependency in zftp
2009-09-11 10:58 ` Peter Stephenson
@ 2009-09-11 11:09 ` Baptiste Daroussin
0 siblings, 0 replies; 3+ messages in thread
From: Baptiste Daroussin @ 2009-09-11 11:09 UTC (permalink / raw)
To: zsh-workers
the documentation of zshsftpsys should be change either as it says
that it needs perl that is now not the case anymore.
I didn't send a patch for the documentation, because lots of people
has a better english than I do for documentation
2009/9/11 Peter Stephenson <pws@csr.com>:
> On Fri, 11 Sep 2009 10:37:32 +0000
> Baptiste Daroussin <baptiste.daroussin@gmail.com> wrote:
>> Hi,
>>
>> Here is a patch to remove the perl dependency in the zfrtime of zftp
>>
>> Seems to work for me
>
> Thanks, I'll take your word for it: this tidies it up a little.
>
> Index: Functions/Zftp/zfrtime
> ===================================================================
> RCS file: /cvsroot/zsh/zsh/Functions/Zftp/zfrtime,v
> retrieving revision 1.1.1.1
> diff -u -r1.1.1.1 zfrtime
> --- Functions/Zftp/zfrtime 25 Apr 1999 15:43:58 -0000 1.1.1.1
> +++ Functions/Zftp/zfrtime 11 Sep 2009 10:57:16 -0000
> @@ -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 @@
> 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
> -
> -# 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
> -
> -# }
> +year=$time[1,4]
> +mon=$time[5,6]
> +mday=$time[7,8]
> +hr=$time[9,10]
> +min=$time[11,12]
> +sec=$time[13,14]
> +
> +#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
>
>
> --
> Peter Stephenson <pws@csr.com> Software Engineer
> Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited
> Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK
>
>
> Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-09-11 11:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-09-11 10:37 [PATCH] Remove perl dependency in zftp Baptiste Daroussin
2009-09-11 10:58 ` Peter Stephenson
2009-09-11 11:09 ` Baptiste Daroussin
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).