4

I am maintaining a legacy cygwin (with GNU tar v1.21) system and a legacy Solaris 9 system. The configuration of the Solaris 9 system is fixed and cannot be upgraded (i.e. I can't install gnu tar for Solaris).

I am trying to create a tarball on the cygwin system that can extracted on the Solaris 9 system but unfortunately the directory structure (which is also fixed and cannot be renamed) plus file names exceed 100 characters and I've run into the Great Tar Wars of the last millennium. There is a large (conservative) userbase on the Solaris system so a solution that uses Solaris tar is preferred.

Here are the errors I'm experiencing.

Creating the tar on cygwin:

$ tar -cf dir.tar dir

or

$ tar -c --posix -f dir.tar dir

Gives the following on Solaris:

$ tar -xif dir.tar
tar: directory checksum errors

And the file names in dir are truncated. (i.e. ignoring checksum errors doesn't help)

How do I create a tarball with long pathnames using GNU tar that can be extracted by Solaris tar?

Edit #2: Unable to use Schily Tar (star)

It appears that Joerg Schilling has been able to emulate the Solaris 7/8/9 tar format and provides a suntar option to create a Solaris tarball using star.

Unfortunately star is not available on cygwin. :(

Edit #1: Using --format=posix gives errors when extracting

Errors when extracting --format=posix gnu tarballs using pax on Solaris 9

On cygwin:

$ ls example/this_is_a_path_name_greater_than_one_hundred_characters/when_combined_with_this_file_name_which_is_also_rather_long.txt | wc -m
128
$ tar -c --format=posix -f example.tar example

On Solaris:

$ pax -r -f example.tar
pax: ./PaxHeaders.4440/example : Unknown filetype
pax: example/PaxHeaders.4440/this_is_a_path_name_greater_than_one_hundred_characters : Unknown filetype
pax: example/this_is_a_path_name_greater_than_one_hundred_characters/PaxHeaders.4440/when_combined_with_t : Unknown filetype

Similar errors are given when extracting using Solaris tar.

Nomic
  • 204
  • Did you transfer the file properly? If you ftp'ed, did you set binary before transfer? Also, check with tar tf dir.tar on Cygwin to see the table of contents. – unxnut Jan 07 '14 at 04:05
  • Yes, the file is ftp'd with binary set before transfer. tar tf dir.tar on Cygwin gives the full pathnames. This seems to be an incompatibility between GNU and Solaris implementations of tar. – Nomic Jan 07 '14 at 04:39
  • related, although definitely not a dupe:http://unix.stackexchange.com/questions/101561/what-are-the-differences-between-bsdtar-and-gnu-tar. this also talks a little about different tar implementations, not sure what exact implementation Solaris uses – strugee Jan 07 '14 at 05:32
  • Do any of your file names contain non-ASCII characters? If so, Checksumming problems seems to describe your situation. Try adding -i when extracting. (Answer updated accordingly.) – Mikel Jan 07 '14 at 17:12
  • No, all standard ASCII. Question updated. – Nomic Jan 07 '14 at 22:36
  • I had assumed the names were being truncated at 256 characters when in reality they are being truncated at 100. This is why ustar works, but I'm still not sure why posix does not. – Nomic Jan 10 '14 at 04:33
  • 1
    Star compiles out of the box on Cygwin. Just fetch a schilytools source archive, unpack it and call make – schily Jun 27 '18 at 20:20

3 Answers3

4

GNU tar formats suggests tar -c --format=posix or tar -c --format=pax is the only way to create a portable tar file containing path names longer than 255 characters.

The Solaris tar man page doesn't mention supporting that format, but the Solaris pax man page does.

So first, I'd try to create the archive on your Cygwin (or Linux) system using tar -c --format=posix -f dir.tar dir, and to extract it on your Solaris system using pax -r -x pax -f dir.tar, or likely just pax -r -f dir.tar.

Alternatively, if you have cpio installed on both systems, it seems like the crc format supports 1,023 character paths on both systems. That would look something like find -L dir | cpio -o -H crc > dir.cpio to create and cpio -i -d < dir.cpio to extract it.

Finally, you could try adding the -i flag to ignore directory checksum errors when extracting on Solaris, e.g. tar -x -i -f dir.tar. Checksumming problems says this can be needed if any of the file names in the tar archive are non-ASCII.

Other reading:

Mikel
  • 57,299
  • 15
  • 134
  • 153
  • I second using cpio instead of tar for this instance. – Jenny D Jan 07 '14 at 07:38
  • There is a large (conservative) userbase on the Solaris system so a solution that uses Solaris tar is preferred. I tried using pax to extract the posix formatted GNU tarball but got more errors. It seems GNU and Solaris have different interpretations of the posix standard. Thanks for your suggestions! – Nomic Jan 09 '14 at 05:31
  • Yes, and there are multiple versions of the POSIX standard too. So much fun! Shame format=posix doesn't work. Mind adding the errors you get at the end of your question? Maybe we can fix those somehow. – Mikel Jan 09 '14 at 16:17
  • I've added the errors seen. Further research shows that star has an option to produce a suntar format so I will experiment with that as well. – Nomic Jan 21 '14 at 05:38
  • There is no star package available for cygwin. My next option is to either test for the limitations of ustar or try and emulate the Solaris 9 tar format using GNU's --pax-option – Nomic Jan 22 '14 at 11:23
3

Solaris tar and GNU tar have different interpretations of posix but both support ustar, which in turn supports long(ish) pathnames.

Using GNU tar on cygwin:

$ tar -c --format=ustar -f dir.tar dir

This creates a tarball which is happily extracted on Solaris 9 without errors. Perhaps not a universal solution but one that fits the constrained solution space. Looks like the 80s were useful after all!

Nomic
  • 204
  • The doc you linked to clearly says that ustar only supports up to 256 characters. There is an "extended ustar", but as far as I can see, that's what --format=posix produces. Did you test this? – Mikel Jan 09 '14 at 15:59
  • Yes, that's why --format=posix was my first choice, but it still produced the truncated names whereas --format=ustar did not. I will do some more testing to try and find out why this is so. I've removed the first sentence from my answer as I misinterpreted the linked page based on my test results. – Nomic Jan 09 '14 at 22:56
  • Question updated - the file names are being truncated at 100 characters, not 256. – Nomic Jan 10 '14 at 04:34
2

The main problem in GNU tar is that it does not contain code to control the archive format. GNU tar is too dumb to understand that POSIX.1-1988 may archive file names longer than 100 chars.

GNU tar in such a case switches to GNU proprietary extension in the middle of the archive and this is why Solaris tar will abort in the middle.

I recommend to use star from the schilytools source package.

schily
  • 19,173