Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Path.mkdirs #594

Closed
wants to merge 3 commits into from
Closed

Conversation

patricoferris
Copy link
Collaborator

As per one of the tasks in #510. I'm almost certainly doing something wrong... Unfortunately I don't have a windows machine so I blindly added the windows test.

@patricoferris
Copy link
Collaborator Author

Hmm I think the Linux error (or the macOS/Windows incorrect success) is caused by catching

if leaf = ".." then (
hence the diff in the mdx test :/

lib_eio/path.ml Outdated Show resolved Hide resolved
lib_eio/path.ml Outdated
make_directory dir;
loop dir xs
in
loop "" (separate path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably more efficient to start by checking the direct parent. If that exists (which is the common) case, there's no need to check further up (see e.g. Python's makedirs or Bos's create).

(** [mkdir ?exist_ok ~perm t] creates a new directory [t] with permissions [perm]. *)

val mkdirs : ?exists_ok:bool -> perm:File.Unix_perm.t -> _ t -> unit
(** Recursively create directories. If [exist_ok] is [false] (the default) then we raise
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exists_ok should only affect the final directory, not the intermediate ones (most of which will exist).

@talex5
Copy link
Collaborator

talex5 commented Sep 29, 2023

Closing in favour of the newer version in #625 - thanks!

@talex5 talex5 closed this Sep 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants