Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion gleam.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
11 changes: 1 addition & 10 deletions src/simplifile.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 1 addition & 2 deletions src/simplifile_erl.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

-module(simplifile_erl).

% We call the
-compile({no_auto_import,[link/2]}).

%% API
Expand Down Expand Up @@ -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) ->
Expand Down
4 changes: 2 additions & 2 deletions src/simplifile_js.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 8 additions & 0 deletions test/simplifile_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}