On Tuesday 02 November 2010 08:38:34 Paul Eggert wrote:
> Ah, thanks, that explains things. But the problem was not
> within tar: it was that tar was being given the wrong
> command-line argument.
No Paul, the bug really occures when tar unquotes a string passed
from command line. I changed your test program a bit to accept
a file name from command line ...
#include <stdio.h>
#include <sys/stat.h>
int
main (int argc, char **argv)
{
const char *file_name = (argc > 1 )
? *++argv
: "Please provide a filename";
struct stat st;
int status = lstat (file_name, &st);
fprintf(stderr,"lstat('%s'): status was %d = %m\n",file_name,status);
return status ? 1 : 0;
}
... and compiled it to a program named "test2".
$ touch 'hello world\n'
$ ls -l hello\ world\\n
-rw-r--r-- 1 hm hm 0 Nov 2 11:31 hello world\n
$ ./test2 hello\ world\\n
lstat('hello world\n'): status was 0 = Success
$ ./test2 "hello world\\n"
lstat('hello world\n'): status was 0 = Success
$ ./test2 'hello world\n'
lstat('hello world\n'): status was 0 = Success
$ ./test2 "hello world\n"
lstat('hello world\n'): status was 0 = Success
$ ./test2 'hello world\\n'
lstat('hello world\\n'): status was -1 = No such file or directory
Now running the same tests with tar:
$ tar --version
tar (GNU tar) 1.24
$ tar -cf x.tar hello\ world\\n
tar: hello world\n: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
$ tar -cf x.tar "hello world\\n"
tar: hello world\n: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
$ tar -cf x.tar 'hello world\n'
tar: hello world\n: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
$ tar -cf x.tar "hello world\n"
tar: hello world\n: Cannot stat: No such file or directory
tar: Exiting with failure status due to previous errors
$ tar -cf x.tar 'hello world\\n'
(Success)