mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-07 21:44:36 +08:00
Resolve paths instead of raising
This commit is contained in:
parent
797befe28f
commit
7050180242
2 changed files with 8 additions and 18 deletions
|
@ -29,13 +29,7 @@ defmodule Livebook.FileSystem.File do
|
|||
|
||||
path =
|
||||
if path do
|
||||
resolved_path = FileSystem.resolve_path(file_system, default_path, path)
|
||||
|
||||
unless path == resolved_path do
|
||||
raise ArgumentError, "expected an expanded absolute path, got: #{inspect(path)}"
|
||||
end
|
||||
|
||||
path
|
||||
FileSystem.resolve_path(file_system, default_path, path)
|
||||
else
|
||||
default_path
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
defmodule Livebook.FileSystem.FileTest do
|
||||
defmodule Livebook.FileSystem.FileTest do
|
||||
use ExUnit.Case, async: true
|
||||
|
||||
import Livebook.TestHelpers
|
||||
|
@ -6,22 +6,18 @@ defmodule Livebook.FileSystem.FileTest do
|
|||
alias Livebook.FileSystem
|
||||
|
||||
describe "new/2" do
|
||||
test "raises an error when a relative path is given" do
|
||||
test "resolves relative paths" do
|
||||
file_system = FileSystem.Local.new()
|
||||
|
||||
assert_raise ArgumentError, ~s{expected an expanded absolute path, got: "file.txt"}, fn ->
|
||||
FileSystem.File.new(file_system, "file.txt")
|
||||
end
|
||||
assert FileSystem.File.new(file_system, "file.txt").path ==
|
||||
Path.join(File.cwd!(), "file.txt")
|
||||
end
|
||||
|
||||
test "raises an error when a unexpanded path is given" do
|
||||
test "resolves unexpanded paths" do
|
||||
file_system = FileSystem.Local.new()
|
||||
|
||||
assert_raise ArgumentError,
|
||||
~s{expected an expanded absolute path, got: "/dir/nested/../file.txt"},
|
||||
fn ->
|
||||
FileSystem.File.new(file_system, "/dir/nested/../file.txt")
|
||||
end
|
||||
assert FileSystem.File.new(file_system, "/dir/nested/../file.txt").path ==
|
||||
Path.expand("/dir/file.txt")
|
||||
end
|
||||
|
||||
test "uses default file system path if non is given" do
|
||||
|
|
Loading…
Add table
Reference in a new issue