On Thursday 19 March 2009 11:27:11 Sven Joachim wrote:
> While the ordering of hidden files in "ls -v" seems to be fixed
> now, there are still inconsistencies.  Here's what I get in the latest
> snapshot:
>
> ,----
>
> | LANG=C /usr/local/src/coreutils-7.1.63-8e6a6/src/ls -alv
> | total 0
> | drwxr-xr-x 2 sven sven 160 Mar 19 11:13 .
> | drwxrwxrwt 9 root root 200 Mar 19 11:15 ..
> | -rw-r--r-- 1 sven sven   0 Mar 19 11:13 a~
> | -rw-r--r-- 1 sven sven   0 Mar 19 11:13 a
> | -rw-r--r-- 1 sven sven   0 Mar 19 11:13 a.b
> | -rw-r--r-- 1 sven sven   0 Mar 19 11:13 a.bc
> | -rw-r--r-- 1 sven sven   0 Mar 19 11:13 a.b~
> | -rw-r--r-- 1 sven sven   0 Mar 19 11:13 a.bc~
>
> `----
>
> Note that a~ sorts before a, but a.b~ after a.b.
>
> Regards,
>         Sven


Thanks again! The file suffix regex doesn't match any suffix containing '~'. 

I've changed it this way:
/(\.[A-Za-z][A-Za-z0-9]*)*$/
/(\.[A-Za-z~][A-Za-z0-9~]*)*$/

Now it works correctly with simple and numbered backups. Simple patch 
including clarifying test cases is attached.


Kamil
From d889021cebb7bf798d1b7bf24149c354627e9553 Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdu...@redhat.com>
Date: Fri, 20 Mar 2009 11:20:12 +0100
Subject: [PATCH] filevercmp: extension for simple and numbered backups

---
 ChangeLog               |    5 +++++
 lib/filevercmp.c        |    6 +++---
 lib/filevercmp.h        |    2 +-
 tests/test-filevercmp.c |    9 +++++++--
 4 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 0bc942d..83075df 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-03-20  Kamil Dudka  <kdu...@redhat.com>
+
+	* lib/filevercmp.c: Treat simple or numbered backup suffix as suffix.
+	* tests/test-filevercmp.c: Add tests for backup suffixes.
+
 2009-03-19  Eric Blake  <e...@byu.net>
 
 	doc: mention more functions added in cygwin 1.7.0
diff --git a/lib/filevercmp.c b/lib/filevercmp.c
index 7b40c98..b1ceab6 100644
--- a/lib/filevercmp.c
+++ b/lib/filevercmp.c
@@ -27,7 +27,7 @@
 #include <limits.h>
 
 /* Match a file suffix defined by this regular expression:
-   /(\.[A-Za-z][A-Za-z0-9]*)*$/
+   /(\.[A-Za-z~][A-Za-z0-9~]*)*$/
    Scan the string *STR and return a pointer to the matching suffix, or
    NULL if not found.  Upon return, *STR points to terminating NUL.  */
 static const char *
@@ -40,7 +40,7 @@ match_suffix (const char **str)
       if (read_alpha)
         {
           read_alpha = false;
-          if (!c_isalpha (**str))
+          if (!c_isalpha (**str) && '~' != **str)
             match = NULL;
         }
       else if ('.' == **str)
@@ -49,7 +49,7 @@ match_suffix (const char **str)
           if (!match)
             match = *str;
         }
-      else if (!c_isalnum (**str))
+      else if (!c_isalnum (**str) && '~' != **str)
         match = NULL;
       (*str)++;
     }
diff --git a/lib/filevercmp.h b/lib/filevercmp.h
index 569b4d0..9568d15 100644
--- a/lib/filevercmp.h
+++ b/lib/filevercmp.h
@@ -32,7 +32,7 @@
    It returns number >0 for S1 > S2, 0 for S1 == S2 and number <0 for S1 < S2.
 
    This function compares strings, in a way that if VER1 and VER2 are version
-   numbers and PREFIX and SUFFIX (SUFFIX defined as (\.[A-Za-z][A-Za-z0-9]*)*)
+   numbers and PREFIX and SUFFIX (SUFFIX defined as (\.[A-Za-z~][A-Za-z0-9~]*)*)
    are strings then VER1 < VER2 implies filevercmp (PREFIX VER1 SUFFIX,
    PREFIX VER2 SUFFIX) < 0.
 
diff --git a/tests/test-filevercmp.c b/tests/test-filevercmp.c
index fe54dc2..45a594b 100644
--- a/tests/test-filevercmp.c
+++ b/tests/test-filevercmp.c
@@ -45,10 +45,15 @@ static const char *const examples[] =
   ".b",
   "a~",
   "a",
+  "a.b~",
+  "a.b",
+  "a.bc~",
+  "a.bc",
   "b~",
   "b",
-  "gcc-c++-10.fc9.tar.gz",
-  "gcc-c++-10.8.12-0.7rc2.fc9.tar.bz2",
+  "gcc-c++-10.fc9.tar.gz.~1~",
+  "gcc-c++-10.fc9.tar.gz.~2~",
+  "gcc-c++-10.8.12-0.7rc2.fc9.tar.bz2.~1~",
   "glibc-2-0.1.beta1.fc10.rpm",
   "glibc-common-5-0.2.beta2.fc9.ebuild",
   "glibc-common-5-0.2b.deb",
-- 
1.6.1.2

Reply via email to