gruenewa
gruenewa

Reputation: 1676

End_of_file exception when creating TAR file with *ocaml_tar*

When I try to create a TAR file using ocaml_tar library, I get an End_of_file exception.

My code ...

#require "tar";;
#require "tar.unix";;
let f = Unix.openfile "test.tar" [ Unix.O_RDWR; Unix.O_CREAT ] 0o600;;
Tar_unix.Archive.create ["write_ex.ml"] f;;
Unix.close f;;

... produces the following stacktrace:

$ utop write_ex.ml
Exception: End_of_file.
Raised at file "lib/tar.ml", line 549, characters 36-47
Called from file "lib/tar.ml", line 460, characters 4-11
Called from file "stream.ml", line 149, characters 33-38
Called from file "lib/tar.ml", line 578, characters 6-28
Called from file "toplevel/toploop.ml", line 180, characters 17-56

Does anyone know what's wrong?

Upvotes: 2

Views: 156

Answers (1)

ivg
ivg

Reputation: 35260

There is nothing wrong with your code. It is actually a bug in the Tar_unix module. The output function wasn't robust enough and fails with End_of_file exception if the write was truncated. I've fixed the issue and your code works fine. See my PR for more information.

Update

The PR is merged and the newer (0.5.1) version is released to opam. Upgrade to the latest version with:

opam update
opam upgrade

Make sure, that the latest (>= 0.5.1) version is installed, by querying opam

opam show tar-format

If it is still old, then force opam to install the latest one:

opam install 'tar-format>=0.5.1'

Upvotes: 5

Related Questions