fix(ft): set more conservative filename length limit
Otherwise, local fs exporter will have a hard time preserving the filemeta, because its filename is even 13 bytes longer.
This commit is contained in:
parent
69b98c1830
commit
dcd59e4f1b
|
@ -42,7 +42,9 @@
|
||||||
%% on most filesystems. Even though, say, S3 does not have such limitations, it's
|
%% on most filesystems. Even though, say, S3 does not have such limitations, it's
|
||||||
%% still useful to have a limit on the filename length, to avoid having to deal with
|
%% still useful to have a limit on the filename length, to avoid having to deal with
|
||||||
%% limits in the storage backends.
|
%% limits in the storage backends.
|
||||||
-define(MAX_FILENAME_BYTELEN, 255).
|
%% Usual realistic limit is 255 bytes actually, but we leave some room for backends
|
||||||
|
%% to spare.
|
||||||
|
-define(MAX_FILENAME_BYTELEN, 240).
|
||||||
|
|
||||||
-import(hoconsc, [ref/2, mk/2]).
|
-import(hoconsc, [ref/2, mk/2]).
|
||||||
|
|
||||||
|
|
|
@ -128,7 +128,17 @@ complete(
|
||||||
Filemeta = FilemetaIn#{checksum => Checksum},
|
Filemeta = FilemetaIn#{checksum => Checksum},
|
||||||
ok = file:close(Handle),
|
ok = file:close(Handle),
|
||||||
_ = filelib:ensure_dir(ResultFilepath),
|
_ = filelib:ensure_dir(ResultFilepath),
|
||||||
_ = file:write_file(mk_manifest_filename(ResultFilepath), encode_filemeta(Filemeta)),
|
ManifestFilepath = mk_manifest_filename(ResultFilepath),
|
||||||
|
case file:write_file(ManifestFilepath, encode_filemeta(Filemeta)) of
|
||||||
|
ok ->
|
||||||
|
ok;
|
||||||
|
{error, Reason} ->
|
||||||
|
?SLOG(warning, "filemeta_write_failed", #{
|
||||||
|
path => ManifestFilepath,
|
||||||
|
meta => Filemeta,
|
||||||
|
reason => Reason
|
||||||
|
})
|
||||||
|
end,
|
||||||
file:rename(Filepath, ResultFilepath).
|
file:rename(Filepath, ResultFilepath).
|
||||||
|
|
||||||
-spec discard(export_st()) ->
|
-spec discard(export_st()) ->
|
||||||
|
|
|
@ -261,6 +261,7 @@ t_nasty_clientids_fileids(_Config) ->
|
||||||
fun({ClientId, FileId}) ->
|
fun({ClientId, FileId}) ->
|
||||||
ok = emqx_ft_test_helpers:upload_file(ClientId, FileId, "justfile", ClientId),
|
ok = emqx_ft_test_helpers:upload_file(ClientId, FileId, "justfile", ClientId),
|
||||||
[Export] = list_files(ClientId),
|
[Export] = list_files(ClientId),
|
||||||
|
?assertMatch(#{meta := #{name := "justfile"}}, Export),
|
||||||
?assertEqual({ok, ClientId}, read_export(Export))
|
?assertEqual({ok, ClientId}, read_export(Export))
|
||||||
end,
|
end,
|
||||||
Transfers
|
Transfers
|
||||||
|
@ -271,13 +272,14 @@ t_nasty_filenames(_Config) ->
|
||||||
{<<"nasty1">>, "146%"},
|
{<<"nasty1">>, "146%"},
|
||||||
{<<"nasty2">>, "🌚"},
|
{<<"nasty2">>, "🌚"},
|
||||||
{<<"nasty3">>, "中文.txt"},
|
{<<"nasty3">>, "中文.txt"},
|
||||||
{<<"nasty4">>, _254Bytes = string:join(lists:duplicate(255 div 5, "LONG"), ".")}
|
{<<"nasty4">>, _239Bytes = string:join(lists:duplicate(240 div 5, "LONG"), ".")}
|
||||||
],
|
],
|
||||||
ok = lists:foreach(
|
ok = lists:foreach(
|
||||||
fun({ClientId, Filename}) ->
|
fun({ClientId, Filename}) ->
|
||||||
FileId = unicode:characters_to_binary(Filename),
|
FileId = unicode:characters_to_binary(Filename),
|
||||||
ok = emqx_ft_test_helpers:upload_file(ClientId, FileId, Filename, FileId),
|
ok = emqx_ft_test_helpers:upload_file(ClientId, FileId, Filename, FileId),
|
||||||
[Export] = list_files(ClientId),
|
[Export] = list_files(ClientId),
|
||||||
|
?assertMatch(#{meta := #{name := Filename}}, Export),
|
||||||
?assertEqual({ok, FileId}, read_export(Export))
|
?assertEqual({ok, FileId}, read_export(Export))
|
||||||
end,
|
end,
|
||||||
Filenames
|
Filenames
|
||||||
|
|
Loading…
Reference in New Issue