diff options
author | Patrik Nyblom <[email protected]> | 2013-01-29 17:28:20 +0100 |
---|---|---|
committer | Björn Gustavsson <[email protected]> | 2013-02-11 14:11:37 +0100 |
commit | aa15249fe5d8819e511ca0f09eae1d1207903e53 (patch) | |
tree | fda2d2070eeebb19ba941fe70ce8ee753f279976 /erts/preloaded/src/prim_file.erl | |
parent | 066c26ec53012ccea106a4f27b85ddbdb58bb2bc (diff) | |
download | otp-aa15249fe5d8819e511ca0f09eae1d1207903e53.tar.gz otp-aa15249fe5d8819e511ca0f09eae1d1207903e53.tar.bz2 otp-aa15249fe5d8819e511ca0f09eae1d1207903e53.zip |
Make prim_file skip invalid filenames in unicode mode
The fix affects list_dir and read_link. Raw filenames are now
never produced, just consumed even if +fnu or +fna is used on
Linux etc.
This also adds the options to get error return or error handler
warning messages with +fn{u|a}{i|w|e} as an option to erl.
This is still not documented and there needs to be other versions
of read_dir and read_link to facilitate reading of all types
of filenames and links.
A check that we will not change to an invalid directory is also needed.
Diffstat (limited to 'erts/preloaded/src/prim_file.erl')
-rw-r--r-- | erts/preloaded/src/prim_file.erl | 32 |
1 files changed, 29 insertions, 3 deletions
diff --git a/erts/preloaded/src/prim_file.erl b/erts/preloaded/src/prim_file.erl index af1a6127c9..27e7640b7e 100644 --- a/erts/preloaded/src/prim_file.erl +++ b/erts/preloaded/src/prim_file.erl @@ -155,13 +155,15 @@ internal_normalize_utf8/1]). -type prim_file_name() :: string() | unicode:unicode_binary(). +-type prim_file_name_error() :: 'error' | 'ignore' | 'warning'. -spec internal_name2native(prim_file_name()) -> binary(). internal_name2native(_) -> erlang:nif_error(undefined). --spec internal_native2name(binary()) -> prim_file_name(). +-spec internal_native2name(binary()) -> + prim_file_name() | {'error',prim_file_name_error()}. internal_native2name(_) -> erlang:nif_error(undefined). @@ -924,7 +926,21 @@ list_dir_response(Port, Acc0) -> end. list_dir_convert([Name|Names]) -> - [prim_file:internal_native2name(Name)|list_dir_convert(Names)]; + %% If the filename cannot be converted, return error or ignore + %% with optional error logger warning, depending on +fn{u|a}{i|e|w} + %% emulator switches. + case prim_file:internal_native2name(Name) of + {error, warning} -> + error_logger:warning_msg("Non-unicode filename ~p ignored\n", + [Name]), + list_dir_convert(Names); + {error, ignore} -> + list_dir_convert(Names); + {error, error} -> + {error, {no_translation, Name}}; + Converted when is_list(Converted) -> + [Converted|list_dir_convert(Names)] + end; list_dir_convert([]) -> []. %%%----------------------------------------------------------------- @@ -933,7 +949,17 @@ list_dir_convert([]) -> []. handle_fname_response(Port) -> case drv_get_response(Port) of {fname, Name} -> - {ok, prim_file:internal_native2name(Name)}; + case prim_file:internal_native2name(Name) of + {error, warning} -> + error_logger:warning_msg("Non-unicode filename ~p " + "ignored when reading link\n", + [Name]), + {error, einval}; + {error, _} -> + {error, einval}; + Converted when is_list(Converted) -> + {ok, Converted} + end; Error -> Error end. |