From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 13609 invoked from network); 11 Sep 2009 10:59:35 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from new-brage.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.254.104) by ns1.primenet.com.au with SMTP; 11 Sep 2009 10:59:35 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 16241 invoked from network); 11 Sep 2009 10:59:17 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 11 Sep 2009 10:59:17 -0000 Received: (qmail 22384 invoked by alias); 11 Sep 2009 10:59:09 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 27267 Received: (qmail 22372 invoked from network); 11 Sep 2009 10:59:08 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 11 Sep 2009 10:59:08 -0000 Received: from cluster-g.mailcontrol.com (cluster-g.mailcontrol.com [208.87.233.190]) by bifrost.dotsrc.org (Postfix) with ESMTPS id E50718026E39 for ; Fri, 11 Sep 2009 12:59:00 +0200 (CEST) Received: from cameurexb01.EUROPE.ROOT.PRI ([193.128.72.68]) by rly24g.srv.mailcontrol.com (MailControl) with ESMTP id n8BAwhik014050 for ; Fri, 11 Sep 2009 11:58:46 +0100 Received: from news01 ([10.99.50.25]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.3959); Fri, 11 Sep 2009 11:58:37 +0100 Date: Fri, 11 Sep 2009 11:58:37 +0100 From: Peter Stephenson To: zsh-workers@sunsite.dk Subject: Re: [PATCH] Remove perl dependency in zftp Message-ID: <20090911115837.64cb9243@news01> In-Reply-To: References: Organization: CSR X-Mailer: Claws Mail 3.5.0 (GTK+ 2.12.8; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 11 Sep 2009 10:58:37.0352 (UTC) FILETIME=[D0576280:01CA32CE] X-Scanned-By: MailControl A-09-22-01 (www.mailcontrol.com) on 10.71.0.134 X-Virus-Scanned: ClamAV 0.94.2/9795/Fri Sep 11 07:51:32 2009 on bifrost X-Virus-Status: Clean On Fri, 11 Sep 2009 10:37:32 +0000 Baptiste Daroussin 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 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