GNU bug report logs -
#6986
[PATCH] test: add check to determine whether files are on the same device
Previous Next
To reply to this bug, email your comments to 6986 AT debbugs.gnu.org.
Toggle the display of automated, internal messages from the tracker.
Report forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#6986
; Package
coreutils
.
(Sun, 05 Sep 2010 13:35:02 GMT)
Full text and
rfc822 format available.
Acknowledgement sent
to
Dieter Plaetinck <dieter <at> plaetinck.be>
:
New bug report received and forwarded. Copy sent to
bug-coreutils <at> gnu.org
.
(Sun, 05 Sep 2010 13:35:02 GMT)
Full text and
rfc822 format available.
Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):
In the test program, there is '-ef' which checks whether files
are on the same device *and* have the same inode number.
This change introduces '-ed' which is basically the same, minus the
inode number checking
---
src/test.c | 19 +++++++++++++++----
1 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/src/test.c b/src/test.c
index e2247d2..8e738e9 100644
--- a/src/test.c
+++ b/src/test.c
@@ -174,9 +174,9 @@ static bool
binop (char const *s)
{
return ((STREQ (s, "=")) || (STREQ (s, "!=")) || (STREQ (s, "-nt")) ||
- (STREQ (s, "-ot")) || (STREQ (s, "-ef")) || (STREQ (s, "-eq")) ||
- (STREQ (s, "-ne")) || (STREQ (s, "-lt")) || (STREQ (s, "-le")) ||
- (STREQ (s, "-gt")) || (STREQ (s, "-ge")));
+ (STREQ (s, "-ot")) || (STREQ (s, "-ed")) || (STREQ (s, "-ef")) ||
+ (STREQ (s, "-eq")) || (STREQ (s, "-ne")) || (STREQ (s, "-lt")) ||
+ (STREQ (s, "-le")) || (STREQ (s, "-gt")) || (STREQ (s, "-ge")));
}
/*
@@ -191,7 +191,7 @@ binop (char const *s)
* string
* string ('!='|'=') string
* <int> '-'(eq|ne|le|lt|ge|gt) <int>
- * file '-'(nt|ot|ef) file
+ * file '-'(nt|ot|ed|ef) file
* '(' <expr> ')'
* int ::=
* '-l' string
@@ -327,6 +327,16 @@ binary_operator (bool l_is_l)
break;
case 'e':
+ if (argv[op][2] == 'd' && !argv[op][3])
+ {
+ /* ed - same device? */
+ pos += 3;
+ if (l_is_l || r_is_l)
+ test_syntax_error (_("-ed does not accept -l"), NULL);
+ return (stat (argv[op - 1], &stat_buf) == 0
+ && stat (argv[op + 1], &stat_spare) == 0
+ && stat_buf.st_dev == stat_spare.st_dev);
+ }
if (argv[op][2] == 'f' && !argv[op][3])
{
/* ef - hard link? */
@@ -726,6 +736,7 @@ EXPRESSION is true or false and sets exit status. It is one of:\n\
"), stdout);
fputs (_("\
\n\
+ FILE1 -ed FILE2 FILE1 and FILE2 have the same device number\n\
FILE1 -ef FILE2 FILE1 and FILE2 have the same device and inode numbers\n\
FILE1 -nt FILE2 FILE1 is newer (modification date) than FILE2\n\
FILE1 -ot FILE2 FILE1 is older than FILE2\n\
--
1.7.2.3
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#6986
; Package
coreutils
.
(Mon, 06 Sep 2010 18:23:02 GMT)
Full text and
rfc822 format available.
Message #8 received at 6986 <at> debbugs.gnu.org (full text, mbox):
Dieter Plaetinck wrote:
> In the test program, there is '-ef' which checks whether files
> are on the same device *and* have the same inode number.
> This change introduces '-ed' which is basically the same, minus the
> inode number checking
> ---
> src/test.c | 19 +++++++++++++++----
> 1 files changed, 15 insertions(+), 4 deletions(-)
>
> diff --git a/src/test.c b/src/test.c
Thank you for the patch.
However, can you make a case for adding this to test
rather than using an existing tool like stat?
For example, here's a tiny shell function:
same_dev()
{
local d1=$(stat --format=%d "$1") || return 1
local d2=$(stat --format=%d "$2") || return 1
test "$d1" = "$d2"
}
You could use it like this:
$ same_dev a b && echo same
same
$ same_dev a / && echo same || echo different devices
different devices
That it's so easy to accomplish the same thing with
existing tools makes it hard to justify adding the feature.
Besides, if you're really interested in getting this feature
into "test", you don't want to start with coreutils.
Its "test" program is used only rarely, since "test"
is always a shell built-in, these days.
Thus you'd want to request that your feature be added
to at least bash and zsh.
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#6986
; Package
coreutils
.
(Mon, 06 Sep 2010 20:07:02 GMT)
Full text and
rfc822 format available.
Message #11 received at 6986 <at> debbugs.gnu.org (full text, mbox):
On Mon, 06 Sep 2010 20:24:16 +0200
Jim Meyering <jim <at> meyering.net> wrote:
> Dieter Plaetinck wrote:
> > In the test program, there is '-ef' which checks whether files
> > are on the same device *and* have the same inode number.
> > This change introduces '-ed' which is basically the same, minus the
> > inode number checking
> > ---
> > src/test.c | 19 +++++++++++++++----
> > 1 files changed, 15 insertions(+), 4 deletions(-)
> >
> > diff --git a/src/test.c b/src/test.c
>
> Thank you for the patch.
> However, can you make a case for adding this to test
> rather than using an existing tool like stat?
>
> For example, here's a tiny shell function:
>
> same_dev()
> {
> local d1=$(stat --format=%d "$1") || return 1
> local d2=$(stat --format=%d "$2") || return 1
> test "$d1" = "$d2"
> }
>
> You could use it like this:
>
> $ same_dev a b && echo same
> same
> $ same_dev a / && echo same || echo different devices
> different devices
>
> That it's so easy to accomplish the same thing with
> existing tools makes it hard to justify adding the feature.
>
> Besides, if you're really interested in getting this feature
> into "test", you don't want to start with coreutils.
> Its "test" program is used only rarely, since "test"
> is always a shell built-in, these days.
> Thus you'd want to request that your feature be added
> to at least bash and zsh.
Hey Jim,
at first I considered writing a shell function like the one you suggest.
But putting it in test seemed like a better, more generally useful
place, especially since there are some similar functions in test.
(like -ef), and it's just a few lines of C code.
I would argue some of the existing functionality in test can as
easily be removed in favor of a shell function. (I don't suggest
doing so)
Ie, for test -O :
owned_by_me ()
{
local owner_id=$(stat --format='%u' "$1") || return 1
test $owner_id -eq $EUID
}
I know some shells provide the 'test' features as a built-in,
that's fine. But they should mimic the features test has.
It makes the shell implementation dependent on test, not the
other way around. If this feature is considered useful for test, and
gets merged into test, shells will follow soon enough.
But anyway, your call :)
At least thanks for the timely feedback and have a nice day.
Dieter
Information forwarded
to
owner <at> debbugs.gnu.org, bug-coreutils <at> gnu.org
:
bug#6986
; Package
coreutils
.
(Sun, 17 Apr 2011 09:30:02 GMT)
Full text and
rfc822 format available.
Message #14 received at 6986 <at> debbugs.gnu.org (full text, mbox):
tags 6986 wishlist notabug
thanks
Dieter Plaetinck wrote:
...
> I know some shells provide the 'test' features as a built-in,
> that's fine. But they should mimic the features test has.
> It makes the shell implementation dependent on test, not the
> other way around. If this feature is considered useful for test, and
> gets merged into test, shells will follow soon enough.
>
> But anyway, your call :)
> At least thanks for the timely feedback and have a nice day.
Reclassifying this as "wishlist" (i.e., not a bug).
Added tag(s) notabug.
Request was from
Jim Meyering <jim <at> meyering.net>
to
control <at> debbugs.gnu.org
.
(Sun, 17 Apr 2011 11:27:02 GMT)
Full text and
rfc822 format available.
Severity set to 'wishlist' from 'normal'
Request was from
Jim Meyering <jim <at> meyering.net>
to
control <at> debbugs.gnu.org
.
(Mon, 18 Apr 2011 07:33:02 GMT)
Full text and
rfc822 format available.
This bug report was last modified 14 years and 62 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.