djs55/ocaml-tar — pull request #7 by dra27 (2014-10-01 14:28:30+00:00)
Title: Add ustar and GNU tar support for long filenames

Minor breaking change: added the extra fields to Header.t for parsing ustar headers (some pattern matching on Header.t may break, construction almost certainly fine as Header.t or Tar_unix.Header.of_file most likely used). This could be done with a new type, but it seems better to encourage pattern matching on the record to use {...; _} style as other fields (e.g. atime and ctime) may want adding in future.
Added additional constructors to Header.Link.t for the other common file types (including directory) but by if set V7 mode (the default), ocaml-tar will continue to return directory entries as Normal (this is correct for V7, which technically did not include symbolic link support). The worst this should cause is incomplete matching errors, though a similar strategy should apply as for Header.t for client-code.
The patch adds support for long filenames using ustar's prefix field or using GNU tar's @LongLink extra headers. Ustar headers are automatically de-coded (as they are V7 compatible), GNU tar headers require the ~level parameter (either to Archive.list or to Header.get_next_header) to be set to Header.GNU or the @LongLink header items simply show as files. An exception is raised in Header.marshal if either link_name or file_name is too long for the given compatibility level.
None of these changes have been made to Lwt (converting Tar_lwt to use Tar.Make is probably a good idea, but afraid that's not high on my agenda!).
The idea behind this patch was to get long filename and long linkname support working and to set that up in a way which reasonably elegantly (and compatibly) allows other features of the tar variants to be added in future (ustar is completely support in this patch, but GNU tar has many other variants and it would also be possible to add pax/posix header support too). The FreeBSD docs have a lot of format information at http://www.freebsd.org/cgi/man.cgi?query=tar&sektion=5 and the GNU tar manual also has a fair bit at http://www.gnu.org/software/tar/manual/html_section/tar_68.html.