From bb2b84c35e75ae80174ef54dad7babf6c6fa9075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Wed, 9 Apr 2014 16:30:49 +0200 Subject: Correct end of tape marker The POSIX standard for tar says that there must be at least two 512-bytes zero blocks at the end of the tar archive file. Our implementation would only emit a single 512-byte zero block if the size of the last file was in the range 18*512 through 19*512-1 (modulo 20*512). GNU tar would correctly unpack such tar archive file, but would emit a warning: tar: A lone zero block at 20 --- lib/stdlib/src/erl_tar.erl | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'lib/stdlib/src') diff --git a/lib/stdlib/src/erl_tar.erl b/lib/stdlib/src/erl_tar.erl index 89b4ea6c04..acf7a5cd40 100644 --- a/lib/stdlib/src/erl_tar.erl +++ b/lib/stdlib/src/erl_tar.erl @@ -397,9 +397,17 @@ to_string(Str0, Count) -> pad_file(File) -> {ok,Position} = file:position(File, {cur,0}), - %% There must be at least one empty record at the end of the file. - Zeros = zeroes(?block_size - (Position rem ?block_size)), - file:write(File, Zeros). + %% There must be at least two zero records at the end. + Fill = case ?block_size - (Position rem ?block_size) of + Fill0 when Fill0 < 2*?record_size -> + %% We need to another block here to ensure that there + %% are at least two zero records at the end. + Fill0 + ?block_size; + Fill0 -> + %% Large enough. + Fill0 + end, + file:write(File, zeroes(Fill)). split_filename(Name) when length(Name) =< ?th_name_len -> {"", Name}; -- cgit v1.2.3