9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] bug? test f -older t
@ 2013-10-01 11:34 arisawa
  2013-10-01 11:44 ` arisawa
  2013-10-01 11:53 ` erik quanstrom
  0 siblings, 2 replies; 4+ messages in thread
From: arisawa @ 2013-10-01 11:34 UTC (permalink / raw)
  To: 9fans

Hello,

Am I missing something?
It seems logic is inverted to me.

Kenji Arisawa

maia% ls -l
...
--rw-rw-r-- M 323 arisawa arisawa         0 Sep 29 06:29 x
--rw-rw-r-- M 323 arisawa arisawa        14 Sep 28 17:50 z
maia% mtime x
 1380403777 x
maia% if(test z -older 1380403777) echo older
maia% if(! test z -older 1380403777) echo older
older
maia%


man test(1)
          f -older t True if file f is older than (modified before)
                     time t. If t is a integer followed by the letters
                     y(years), M(months), d(days), h(hours),
                     m(minutes), or s(seconds), it represents current
                     time minus the specified time.  If there is no
                     letter, it represents seconds since epoch.  You
                     can also concatenate mixed units.  For example,
                     3d12h means three days and twelve hours ago.

the source code /sys/src/cmd/test.c
int
isolder(char *pin, char *f)
{
	int r;
	ulong n, m;
	char *p = pin;
	Dir *dir;

	dir = dirstat(f);
	if (dir == nil)
		return 0;

	/* parse time */
	n = 0;
	while(*p){
		m = strtoul(p, &p, 0);
		switch(*p){
		case 0:
			n = m;
			break;
		case 'y':
			m *= 12;
			/* fall through */
		case 'M':
			m *= 30;
			/* fall through */
		case 'd':
			m *= 24;
			/* fall through */
		case 'h':
			m *= 60;
			/* fall through */
		case 'm':
			m *= 60;
			/* fall through */
		case 's':
			n += m;
			p++;
			break;
		default:
			synbad("bad time syntax, ", pin);
		}
	}

	r = dir->mtime + n < time(0);
	free(dir);
	return r;
}






^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] bug? test f -older t
  2013-10-01 11:34 [9fans] bug? test f -older t arisawa
@ 2013-10-01 11:44 ` arisawa
  2013-10-01 11:53 ` erik quanstrom
  1 sibling, 0 replies; 4+ messages in thread
From: arisawa @ 2013-10-01 11:44 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

I have forgotten that I took up this bug in Jun this year.
Already fixed in distribution?

On 2013/10/01, at 20:34, arisawa <arisawa@ar.aichi-u.ac.jp> wrote:

> Hello,
>
> Am I missing something?
> It seems logic is inverted to me.
>
> Kenji Arisawa
>
> maia% ls -l
> ...
> --rw-rw-r-- M 323 arisawa arisawa         0 Sep 29 06:29 x
> --rw-rw-r-- M 323 arisawa arisawa        14 Sep 28 17:50 z
> maia% mtime x
> 1380403777 x
> maia% if(test z -older 1380403777) echo older
> maia% if(! test z -older 1380403777) echo older
> older
> maia%
>
>
> man test(1)
>          f -older t True if file f is older than (modified before)
>                     time t. If t is a integer followed by the letters
>                     y(years), M(months), d(days), h(hours),
>                     m(minutes), or s(seconds), it represents current
>                     time minus the specified time.  If there is no
>                     letter, it represents seconds since epoch.  You
>                     can also concatenate mixed units.  For example,
>                     3d12h means three days and twelve hours ago.
>
> the source code /sys/src/cmd/test.c
> int
> isolder(char *pin, char *f)
> {
> 	int r;
> 	ulong n, m;
> 	char *p = pin;
> 	Dir *dir;
>
> 	dir = dirstat(f);
> 	if (dir == nil)
> 		return 0;
>
> 	/* parse time */
> 	n = 0;
> 	while(*p){
> 		m = strtoul(p, &p, 0);
> 		switch(*p){
> 		case 0:
> 			n = m;
> 			break;
> 		case 'y':
> 			m *= 12;
> 			/* fall through */
> 		case 'M':
> 			m *= 30;
> 			/* fall through */
> 		case 'd':
> 			m *= 24;
> 			/* fall through */
> 		case 'h':
> 			m *= 60;
> 			/* fall through */
> 		case 'm':
> 			m *= 60;
> 			/* fall through */
> 		case 's':
> 			n += m;
> 			p++;
> 			break;
> 		default:
> 			synbad("bad time syntax, ", pin);
> 		}
> 	}
>
> 	r = dir->mtime + n < time(0);
> 	free(dir);
> 	return r;
> }
>
>
>
>




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] bug? test f -older t
  2013-10-01 11:34 [9fans] bug? test f -older t arisawa
  2013-10-01 11:44 ` arisawa
@ 2013-10-01 11:53 ` erik quanstrom
  2013-10-01 13:10   ` arisawa
  1 sibling, 1 reply; 4+ messages in thread
From: erik quanstrom @ 2013-10-01 11:53 UTC (permalink / raw)
  To: 9fans

On Tue Oct  1 07:35:11 EDT 2013, arisawa@ar.aichi-u.ac.jp wrote:
> Hello,
> 
> Am I missing something?
> It seems logic is inverted to me.
> 
> Kenji Arisawa
> 
> maia% ls -l
> ...
> --rw-rw-r-- M 323 arisawa arisawa         0 Sep 29 06:29 x
> --rw-rw-r-- M 323 arisawa arisawa        14 Sep 28 17:50 z
> maia% mtime x
>  1380403777 x
> maia% if(test z -older 1380403777) echo older
> maia% if(! test z -older 1380403777) echo older

i assume that there is some copy paste error here?  (the 
mtime of z is not shown.)

if not, "older" is not equivalent to "not younger than";
x is older than y means mtime(x) < mtime(y), and not ≤.

minooka; touch x
minooka; mtime x
 1380627631 x
minooka; if(test x -older 1380627631) echo older
minooka; if(test x -older 1380627632) echo older
older

> I have forgotten that I took up this bug in Jun this year.
> Already fixed in distribution?

the distribution's executable is really broken.  even if the sign is wrong,
one of the following must be true:

minooka; 9fs sources
minooka; if(/n/sources/plan9/386/bin/test x -older 1380627630)echo older
minooka; if(/n/sources/plan9/386/bin/test x -older 1380627631)echo older
minooka; if(/n/sources/plan9/386/bin/test x -older 1380627632)echo older

> 	r = dir->mtime + n < time(0);
> 	free(dir);
> 	return r;

i have the following, perhaps from your suggestion:

	if(rel)
		n = time(0) - n;
	if(n < 0)
		r =  0;
	else
		r = dir->mtime < n;

- erik



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] bug? test f -older t
  2013-10-01 11:53 ` erik quanstrom
@ 2013-10-01 13:10   ` arisawa
  0 siblings, 0 replies; 4+ messages in thread
From: arisawa @ 2013-10-01 13:10 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs


I looked the latest 9front source and found test.c have been already fixed.

thank you.

On 2013/10/01, at 20:53, erik quanstrom <quanstro@quanstro.net> wrote:

> On Tue Oct  1 07:35:11 EDT 2013, arisawa@ar.aichi-u.ac.jp wrote:
>> Hello,
>> 
>> Am I missing something?
>> It seems logic is inverted to me.
>> 
>> Kenji Arisawa
>> 
>> maia% ls -l
>> ...
>> --rw-rw-r-- M 323 arisawa arisawa         0 Sep 29 06:29 x
>> --rw-rw-r-- M 323 arisawa arisawa        14 Sep 28 17:50 z
>> maia% mtime x
>> 1380403777 x
>> maia% if(test z -older 1380403777) echo older
>> maia% if(! test z -older 1380403777) echo older
> 
> i assume that there is some copy paste error here?  (the 
> mtime of z is not shown.)
> 
> if not, "older" is not equivalent to "not younger than";
> x is older than y means mtime(x) < mtime(y), and not ≤.
> 
> minooka; touch x
> minooka; mtime x
> 1380627631 x
> minooka; if(test x -older 1380627631) echo older
> minooka; if(test x -older 1380627632) echo older
> older
> 
>> I have forgotten that I took up this bug in Jun this year.
>> Already fixed in distribution?
> 
> the distribution's executable is really broken.  even if the sign is wrong,
> one of the following must be true:
> 
> minooka; 9fs sources
> minooka; if(/n/sources/plan9/386/bin/test x -older 1380627630)echo older
> minooka; if(/n/sources/plan9/386/bin/test x -older 1380627631)echo older
> minooka; if(/n/sources/plan9/386/bin/test x -older 1380627632)echo older
> 
>> 	r = dir->mtime + n < time(0);
>> 	free(dir);
>> 	return r;
> 
> i have the following, perhaps from your suggestion:
> 
> 	if(rel)
> 		n = time(0) - n;
> 	if(n < 0)
> 		r =  0;
> 	else
> 		r = dir->mtime < n;
> 
> - erik
> 




^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-10-01 13:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-01 11:34 [9fans] bug? test f -older t arisawa
2013-10-01 11:44 ` arisawa
2013-10-01 11:53 ` erik quanstrom
2013-10-01 13:10   ` arisawa

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).