File 8961-stdlib-keep-leading-slash-in-absolute-ustar-filename.patch of Package erlang
From 0937a068c83cfbd2ca4555f9dee3f7e17b21bf80 Mon Sep 17 00:00:00 2001
From: jakob svenningsson <jsvennin@cisco.com>
Date: Wed, 9 Aug 2023 21:05:35 +0200
Subject: [PATCH 1/2] stdlib: keep leading slash in absolute ustar filename
prefixes
The leading slash where previously dropped from absolute ustar
filename prefixes.
---
lib/stdlib/src/erl_tar.erl | 2 +-
lib/stdlib/test/tar_SUITE.erl | 26 ++++++++++++++++++++++++--
2 files changed, 25 insertions(+), 3 deletions(-)
diff --git a/lib/stdlib/src/erl_tar.erl b/lib/stdlib/src/erl_tar.erl
index 90302906a2..fb9df223ad 100644
--- a/lib/stdlib/src/erl_tar.erl
+++ b/lib/stdlib/src/erl_tar.erl
@@ -1149,7 +1149,7 @@ split_ustar_path(Path) ->
false;
true ->
PathBin = binary:list_to_bin(Path),
- case binary:split(PathBin, [<<$/>>], [global, trim_all]) of
+ case filename:split(PathBin) of
[Part] when byte_size(Part) >= ?V7_NAME_LEN ->
false;
Parts ->
diff --git a/lib/stdlib/test/tar_SUITE.erl b/lib/stdlib/test/tar_SUITE.erl
index 294741574c..3b862cbc00 100644
--- a/lib/stdlib/test/tar_SUITE.erl
+++ b/lib/stdlib/test/tar_SUITE.erl
@@ -29,7 +29,7 @@
memory/1,unicode/1,read_other_implementations/1,bsdtgz/1,
sparse/1, init/1, leading_slash/1, dotdot/1,
roundtrip_metadata/1, apply_file_info_opts/1,
- incompatible_options/1]).
+ incompatible_options/1, table_absolute_names/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("kernel/include/file.hrl").
@@ -44,7 +44,7 @@ all() ->
symlinks, open_add_close, cooked_compressed, memory, unicode,
read_other_implementations, bsdtgz,
sparse,init,leading_slash,dotdot,roundtrip_metadata,
- apply_file_info_opts,incompatible_options].
+ apply_file_info_opts,incompatible_options, table_absolute_names].
groups() ->
[].
@@ -1049,6 +1049,28 @@ apply_file_info_opts(Config) when is_list(Config) ->
ok.
+table_absolute_names(Config) ->
+ ok = file:set_cwd(proplists:get_value(priv_dir, Config)),
+ TestFileName1 = lists:duplicate(99, $a),
+ TestFileName2 = lists:duplicate(10, $b),
+ _ = [ok = file:write_file(TestFileName, "hello, world\n") ||
+ TestFileName <- [TestFileName1, TestFileName2]],
+
+ %% File paths greater than 100 bytes will be split and stored
+ %% as a filename and prefix.
+ TarTestFileName1 = filename:join("/tmp", TestFileName1),
+
+ %% File paths less than 100 bytes bytes will not use the prefix field
+ TarTestFileName2 = filename:join("/tmp", TestFileName2),
+
+ TarName = "my_tar_with_long_names.tar",
+ ok = erl_tar:create(TarName, [{TarTestFileName1, TestFileName1},
+ {TarTestFileName2, TestFileName2}]),
+ {ok, TarFiles} = erl_tar:table(TarName),
+ [TarTestFileName1, TarTestFileName2] = lists:sort(TarFiles),
+
+ ok.
+
%% Delete the given list of files.
delete_files([]) -> ok;
delete_files([Item|Rest]) ->
--
2.51.0