OK. The file open mode in tar is defaulting to binary, so the CRLF line endings are not being converted to LF. When tar reads the exclude-from file it gets the CR characters in the pattern, and so the patterns don't match.
The fix lies in the function add_exclude_file() in exclude.c. At the call to fopen(), set the mode parameter to "rt" rather than "r".
Alternatively, create the exclude-from file with an editor that supports *nix line endings.
Regards,
Pete A.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
I'm having trouble with the --exclude-from option in tar.
The following works:
tar -cvf backup.tar --exclude *.exe mydir
in that .exe files are excluded from the archive.
But this does not:
tar -cvf backup.tar --exclude-from exc.txt mydir
where exc.txt contains the line *.exe.
What am I doing wrong?
Platform is Windows 2000 Pro SP4.
tar is tar-1.13-1.
Regards,
Pete A
I have more info.
It's a problem with line endings. The --exclude-from option does work if the file has *nix line endings, LF rather than CRLF.
I'll delve into the source and see if I can post a more specific bug report.
Regards,
Pete A
OK. The file open mode in tar is defaulting to binary, so the CRLF line endings are not being converted to LF. When tar reads the exclude-from file it gets the CR characters in the pattern, and so the patterns don't match.
The fix lies in the function add_exclude_file() in exclude.c. At the call to fopen(), set the mode parameter to "rt" rather than "r".
Alternatively, create the exclude-from file with an editor that supports *nix line endings.
Regards,
Pete A.