[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
"tar cf x.tar /" creates bad tar file
From: |
Pozsar Balazs |
Subject: |
"tar cf x.tar /" creates bad tar file |
Date: |
Thu, 17 Jul 2003 16:13:08 +0200 (CEST) |
Hi!
I recently found a bug while archiving a whole harddrive with tar.
When then command
tar cf x.tar /
is used, tar says "Removing leading `/' from member names", which is okay,
but unfortunately it stores the root directory entry also ('/'), with the
leading '/' removed, so in effect, a directory with the name "" (empty
string) is stored in the archive.
The above command reproduces it :), but a faster way to show the bug is:
address@hidden:~# tar cf - / | tar tv | head
tar: Removing leading `/' from member names
drwxr-xr-x root/root 0 2003-06-15 10:13:34
drwx------ root/root 0 2003-07-17 15:08:35 lost+found/
drwxr-xr-x root/root 0 2003-07-16 07:36:12 boot/
drwxr-xr-x root/root 0 2003-07-17 00:34:04 etc/
-rw-r--r-- root/root 184 2002-12-28 20:35:59 etc/fstab
-rw-r--r-- root/root 107 2002-12-14 14:28:25 etc/crontab
drwxr-xr-x root/root 0 2003-03-26 17:11:10 etc/a2ps/
-rw-r--r-- root/root 2557 2003-03-23 14:18:39 etc/a2ps/a2ps-site.cfg
-rw-r--r-- root/root 15141 2003-03-23 14:18:39 etc/a2ps/a2ps.cfg
drwxr-xr-x root/root 0 2002-12-28 20:37:54 etc/acpi/
address@hidden:~#
You can clearly see the directory stored with the empty name.
This makes a problem if you want to extract the archive, because tar will
try to mkdir(""), which obviously fails.
I do think, that this should be fixed at the creating stage, namely the
'/' root directory should never be stored. I have created this patch:
diff -Naurd tar-1.13.25.orig/src/create.c tar-1.13.25/src/create.c
--- tar-1.13.25.orig/src/create.c 2001-08-29 23:21:02.000000000 +0200
+++ tar-1.13.25/src/create.c 2003-07-17 01:13:32.000000000 +0200
@@ -803,6 +803,8 @@
open_archive (ACCESS_WRITE);
+ add_avoided_name("/");
+
if (incremental_option)
{
size_t buffer_size = 1000;
With this applied, the root dir entry is not stored, and everything goes
well:
address@hidden:~# tar cf - / | tar tv | head
tar: Removing leading `/' from member names
drwx------ root/root 0 2003-07-17 15:08:35 lost+found/
drwxr-xr-x root/root 0 2003-07-16 07:36:12 boot/
drwxr-xr-x root/root 0 2003-07-17 00:34:04 etc/
-rw-r--r-- root/root 184 2002-12-28 20:35:59 etc/fstab
-rw-r--r-- root/root 107 2002-12-14 14:28:25 etc/crontab
drwxr-xr-x root/root 0 2003-03-26 17:11:10 etc/a2ps/
-rw-r--r-- root/root 2557 2003-03-23 14:18:39 etc/a2ps/a2ps-site.cfg
-rw-r--r-- root/root 15141 2003-03-23 14:18:39 etc/a2ps/a2ps.cfg
drwxr-xr-x root/root 0 2002-12-28 20:37:54 etc/acpi/
drwxr-xr-x root/root 0 2003-03-26 17:26:02 etc/acpi/events/
address@hidden:~#
Please apply or comment on it.
Thanks,
--
Balazs Pozsar
- "tar cf x.tar /" creates bad tar file,
Pozsar Balazs <=