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

Tweak mkdir_p uses #2159

Merged
merged 1 commit into from
May 15, 2019
Merged

Tweak mkdir_p uses #2159

merged 1 commit into from
May 15, 2019

Conversation

rgrinberg
Copy link
Member

If the directory that we're trying to create exists, then this is never an error.

We now forbid actions to create external or source dirs.

This should fix #2158

@rgrinberg rgrinberg requested review from a user and aalekseyev May 15, 2019 05:51
@rgrinberg rgrinberg requested a review from emillon as a code owner May 15, 2019 05:51
else if Path.exists path then
()
else
die "action attempted to create %a outside the build dir" Path.pp path
Copy link
Member Author

Choose a reason for hiding this comment

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

It's a bit unfortunate that we can't give the user a proper location here, but passing the location along would be quite painful

@ghost
Copy link

ghost commented May 15, 2019

One sec, where does such an action come from? The mkdir action is not exposed in the action DSL.

@ghost
Copy link

ghost commented May 15, 2019

Additionally, the check_mkdir in action_unexpanded.ml should catch this

@rgrinberg
Copy link
Member Author

Additionally, the check_mkdir in action_unexpanded.ml should catch this

Ah yes, then we can just turn this check into an assert I think.

One sec, where does such an action come from? The mkdir action is not exposed in the action DSL.

From the chdir I believe.

@ghost
Copy link

ghost commented May 15, 2019

Ah yes, then we can just turn this check into an assert I think.

Seems good. Or a Exn.code_error.

From the chdir I believe.

These are handled in build_system.ml. It must be from somewhere else

@aalekseyev
Copy link
Collaborator

aalekseyev commented May 15, 2019

Do you have a motivating example? At a first glance, it seems to me that it makes the logic more complicated for no obvious gain.
Sorry, I can't read.

@rgrinberg
Copy link
Member Author

rgrinberg commented May 15, 2019

These are handled in build_system.ml. It must be from somewhere else

The error from the bug report indeed comes from build_syste.ml. In particular, Mkdir_p.exec:

  let exec p =
    if Path.is_managed p then
      Memo.exec def p
    else
      Exn.code_error "Mkdir_p.exec: attempted to create unmanaged dir"
        [ "p", Path.to_sexp p
        ]

So the first commit will fix the bug for sure.

The second commit was a preventative measure after reviewing more uses of mkdir. It's not necessary to fix the bug.

@rgrinberg
Copy link
Member Author

Do you have a motivating example? At a first glance, it seems to me that it makes the logic more complicated for no obvious gain.

The first commit fixes a bug reported in #2158

The second commit can be omitted, but I think it would be useful to turn it into Exn.code_error

@aalekseyev
Copy link
Collaborator

It would be nice to have a test for this because I imagine that use case is very easy to forget about and break in the future.

@rgrinberg
Copy link
Member Author

I'll add a test case.

@ghost
Copy link

ghost commented May 15, 2019

Turning it into a code error seems good. However, Dune should never try to create directories outside of the workspace. So I feel like we are hiding a real problem by silently ignoring external mkdirs when the external path exists.

@ghost
Copy link

ghost commented May 15, 2019

From the chdir I believe.

These are handled in build_system.ml. It must be from somewhere else

Sorry, I read the code wrong, I thought this was touching action_exec.ml. However, looking at the stacktrace, you are right that this come from a chdir. What we should do is not call Mkdir_p for external chdirs. For instance, we could replace Action.chdirs by Action.managed_chdirs that would only return managed paths.

@rgrinberg
Copy link
Member Author

What we should do is not call Mkdir_p for external chdirs. For instance, we could replace Action.chdirs by Action.managed_chdirs that would only return managed paths.

Managed? If we're restricting this, I think we should go all the way and only allow build dirs. Chdir'ing into the source dir seems dangerous to me.

Just to confirm: #2158 is not considered to be a regression, and that we indeed don't allow to chdir into external paths.

Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
@rgrinberg
Copy link
Member Author

I removed the "fix" which ignored the mkdir_p on external dirs when the dir already existed. All that remains is the assertion that we're only creating a build dir in the action. I think we can safely merge that.

@ghost
Copy link

ghost commented May 15, 2019

Seems good to me

@rgrinberg rgrinberg merged commit 6166600 into ocaml:master May 15, 2019
@ghost ghost mentioned this pull request May 20, 2019
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.

Mkdir_p.exec: attempted to create unmanaged dir in Dune 1.9
2 participants