summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul R. Eggert <eggert@cs.ucla.edu>2010-07-16 10:25:02 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2010-07-17 15:47:46 -0700
commit427b3b8c79b64f6ca08adbfcea7aa54f4496f124 (patch)
tree5d83041bbb0d06fe7f1cc1ef60fe0e85cd75e1ac
parentc1b30c268f8517bfe61fe253a34613584351efc0 (diff)
downloadtar-427b3b8c79b64f6ca08adbfcea7aa54f4496f124.tar.gz
tar: go back to absolutifying filenames in normalize_filename for now
* src/misc.c (normalize_filename): For now, go back to making filenames absolute, even though this causes 'tar' to fail when getcwd fails. However, do not attempt to resolve ".." as this does not work with symlinks. Also, do the right thing with leading file system prefixes and on hosts where // != /.
-rw-r--r--src/misc.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/misc.c b/src/misc.c
index 12b40ac3..40635bed 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -278,7 +278,32 @@ normalize_filename_x (char *file_name)
char *
normalize_filename (const char *name)
{
- char *copy = xstrdup (name);
+ char *copy = NULL;
+
+ if (IS_RELATIVE_FILE_NAME (name))
+ {
+ /* Set COPY to the absolute file name if possible.
+
+ FIXME: There should be no need to get the absolute file name.
+ getcwd is slow, it might fail, and it does not necessarily
+ return a canonical name even when it succeeds. Perhaps we
+ can use dev+ino pairs instead of names? */
+ copy = xgetcwd ();
+ if (copy)
+ {
+ size_t copylen = strlen (copy);
+ bool need_separator = ! (DOUBLE_SLASH_IS_DISTINCT_ROOT
+ && copylen == 2 && ISSLASH (copy[1]));
+ copy = xrealloc (copy, copylen + need_separator + strlen (name) + 1);
+ copy[copylen] = DIRECTORY_SEPARATOR;
+ strcpy (copy + copylen + need_separator, name);
+ }
+ else
+ WARN ((0, errno, _("Cannot get working directory")));
+ }
+
+ if (! copy)
+ copy = xstrdup (name);
normalize_filename_x (copy);
return copy;
}