diff --git a/CHANGELOG.md b/CHANGELOG.md index 456be30..5d49b3c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ ## Unreleased +## v2.3.1 - 6 November 2025 +- Fix bug with error string typo for `Enotdir` on JS. + ## v2.3.0 - 24 June 2025 - Add `create_link` function for hard-linking - Fix bug where one could silently write non-byte aligned data to file, now throws explicit error. diff --git a/gleam.toml b/gleam.toml index 06ed8ee..33a959a 100644 --- a/gleam.toml +++ b/gleam.toml @@ -1,5 +1,5 @@ name = "simplifile" -version = "2.3.0" +version = "2.3.1" description = "Basic file operations that work on all targets" licences = ["Apache-2.0"] diff --git a/src/simplifile.gleam b/src/simplifile.gleam index f908e3b..b38c40c 100644 --- a/src/simplifile.gleam +++ b/src/simplifile.gleam @@ -507,16 +507,7 @@ pub fn create_file(at filepath: String) -> Result(Nil, FileError) { /// `./a/b.txt`, a folder named `b.txt` will be created, so be sure /// to pass only the path to the required directory. pub fn create_directory_all(dirpath: String) -> Result(Nil, FileError) { - let is_abs = filepath.is_absolute(dirpath) - let path = - dirpath - |> filepath.split - |> list.fold("", filepath.join) - let path = case is_abs { - True -> "/" <> path - False -> path - } - do_create_dir_all(path <> "/") + do_create_dir_all(dirpath <> "/") } @external(erlang, "simplifile_erl", "create_dir_all") diff --git a/src/simplifile_erl.erl b/src/simplifile_erl.erl index 810c2f3..09bef7a 100644 --- a/src/simplifile_erl.erl +++ b/src/simplifile_erl.erl @@ -6,7 +6,6 @@ -module(simplifile_erl). -% We call the -compile({no_auto_import,[link/2]}). %% API @@ -148,7 +147,7 @@ delete(Dir) -> %% Creates the entire path for a given directory to exist create_dir_all(Filename) -> - posix_result(filelib:ensure_dir(Filename)). + posix_result(filelib:ensure_path(Filename)). %% Move file from one path to another rename_file(Source, Destination) -> diff --git a/src/simplifile_js.mjs b/src/simplifile_js.mjs index 22afe4b..1c003df 100644 --- a/src/simplifile_js.mjs +++ b/src/simplifile_js.mjs @@ -136,7 +136,7 @@ export function createSymlink(target, path) { * Create the "hard link" called path pointing to the target * * @param {string} target - * @param {sting} path + * @param {string} path * returns {ok | GError} */ export function createLink(target, path) { @@ -364,7 +364,7 @@ function cast_error(error_code) { return new $simplifile.Enosys(); case "ENOBLK": return new $simplifile.Enotblk(); - case "ENODIR": + case "ENOTDIR": return new $simplifile.Enotdir(); case "ENOTSUP": return new $simplifile.Enotsup(); diff --git a/test/simplifile_test.gleam b/test/simplifile_test.gleam index 1b3f315..48701c6 100644 --- a/test/simplifile_test.gleam +++ b/test/simplifile_test.gleam @@ -753,3 +753,11 @@ pub fn rename_file_succeeds_at_renaming_a_directory_test() { fi |> file_info_type |> should.equal(Directory) read(new_dir <> "/i_am_a_file.txt") |> should.be_ok |> should.equal("Hello") } + +pub fn parse_errors_test() { + // Ensuring the ENOTDIR comes through correctly + simplifile.create_file("./tmp/wumbo") |> should.be_ok + let err = + simplifile.create_directory_all("./tmp/wumbo/wombo") |> should.be_error + err |> should.equal(Enotdir) +}