GNU bug report logs - #6986
[PATCH] test: add check to determine whether files are on the same device

Previous Next

Package: coreutils;

Reported by: Dieter Plaetinck <dieter <at> plaetinck.be>

Date: Sun, 5 Sep 2010 13:35:02 UTC

Severity: wishlist

Tags: notabug, patch

Full log


View this message in rfc822 format

From: Dieter Plaetinck <dieter <at> plaetinck.be>
To: 6986 <at> debbugs.gnu.org
Subject: bug#6986: [PATCH] test: add check to determine whether files are on the same device
Date: Sun, 5 Sep 2010 13:13:42 +0200
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





This bug report was last modified 14 years and 63 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.