mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-27 13:56:21 +08:00
Guard files listing to not crash on emoji names (#2558)
This commit is contained in:
parent
18ec115dbd
commit
f4a29840bc
1 changed files with 26 additions and 1 deletions
|
|
@ -46,7 +46,7 @@ defimpl Livebook.FileSystem, for: Livebook.FileSystem.Local do
|
|||
def list(file_system, path, recursive) do
|
||||
FileSystem.Utils.assert_dir_path!(path)
|
||||
|
||||
case File.ls(path) do
|
||||
case file_ls(path) do
|
||||
{:ok, filenames} ->
|
||||
paths =
|
||||
Enum.map(filenames, fn name ->
|
||||
|
|
@ -73,6 +73,31 @@ defimpl Livebook.FileSystem, for: Livebook.FileSystem.Local do
|
|||
end
|
||||
end
|
||||
|
||||
defp file_ls(dir) do
|
||||
# TODO: use File.ls/1 back once this is fixed in the OTP version
|
||||
# that we require. See https://github.com/erlang/otp/issues/4779
|
||||
#
|
||||
# Erlang currently chokes on emoji directories on Windows, so we
|
||||
# discard those
|
||||
case :file.list_dir(dir) do
|
||||
{:ok, names} ->
|
||||
{:ok,
|
||||
for(
|
||||
name <- names,
|
||||
string =
|
||||
try do
|
||||
IO.chardata_to_string(name)
|
||||
rescue
|
||||
_ -> nil
|
||||
end,
|
||||
do: string
|
||||
)}
|
||||
|
||||
{:error, error} ->
|
||||
{:error, error}
|
||||
end
|
||||
end
|
||||
|
||||
def read(_file_system, path) do
|
||||
FileSystem.Utils.assert_regular_path!(path)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue