]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Partial fix for Issue 5: If -P is not specified, strip Windows drive
authorTim Kientzle <kientzle@gmail.com>
Sat, 21 Feb 2009 06:13:58 +0000 (01:13 -0500)
committerTim Kientzle <kientzle@gmail.com>
Sat, 21 Feb 2009 06:13:58 +0000 (01:13 -0500)
letters as well as leading '/' characters.

SVN-Revision: 682

tar/util.c

index e251bc18c602e9410e734219318c8f54509ed10f..8e5db331c75a96ba4ef6d73cd09428f36caec025 100644 (file)
@@ -517,18 +517,41 @@ edit_pathname(struct bsdtar *bsdtar, struct archive_entry *entry)
        while (name[0] == '/' && name[1] == '/')
                name++;
 
-       /* Strip leading '/' unless user has asked us not to. */
-       if (name[0] == '/' && !bsdtar->option_absolute_paths) {
-               /* Generate a warning the first time this happens. */
-               if (!bsdtar->warned_lead_slash) {
-                       bsdtar_warnc(bsdtar, 0,
-                           "Removing leading '/' from member names");
-                       bsdtar->warned_lead_slash = 1;
+       /* By default, don't write or restore absolute pathnames. */
+       if (!bsdtar->option_absolute_paths) {
+               /* Strip Windows drive letters. */
+               if (((name[0] >= 'A' && name[0] <= 'Z')
+                       || (name[0] >= 'a' && name[0] <= 'z'))
+                   && name[1] == ':'
+                   && (name[2] == '/' || name[2] == '\\'))
+               {
+                       /* Generate a warning the first time this happens. */
+                       if (!bsdtar->warned_lead_slash) {
+                               bsdtar_warnc(bsdtar, 0,
+                                   "Removing leading drive letter from member names");
+                               bsdtar->warned_lead_slash = 1;
+                       }
+                       name += 3;
+                       while (*name == '/' || *name == '\\')
+                               ++name;
+                       /* Special case: Stripping everything yields ".". */
+                       if (*name == '\0')
+                               name = ".";
+               }
+
+               /* Strip leading '/'. */
+               if (name[0] == '/') {
+                       /* Generate a warning the first time this happens. */
+                       if (!bsdtar->warned_lead_slash) {
+                               bsdtar_warnc(bsdtar, 0,
+                                   "Removing leading '/' from member names");
+                               bsdtar->warned_lead_slash = 1;
+                       }
+                       name++;
+                       /* Special case: Stripping everything yields ".". */
+                       if (*name == '\0')
+                               name = ".";
                }
-               name++;
-               /* Special case: Stripping leading '/' from "/" yields ".". */
-               if (*name == '\0')
-                       name = ".";
        }
 
        /* Safely replace name in archive_entry. */