Skip to content

Make promoted files read-only#12519

Merged
rgrinberg merged 1 commit intoocaml:mainfrom
MisterDA:make-promoted-files-read-only
Oct 4, 2025
Merged

Make promoted files read-only#12519
rgrinberg merged 1 commit intoocaml:mainfrom
MisterDA:make-promoted-files-read-only

Conversation

@MisterDA
Copy link
Copy Markdown
Contributor

Files promoted to the source directory should be read-only because they are generated. If they're edited, they're going to be eventually overwritten by a following build. Setting them read-only would prevent user confusion.

In this case, read-only would only be useful for humans, and Dune should make the file writable again if it needs to overwrite it.

If the user need to overwrite a promoted file, for instance before distributing a source archive, then she needs to manually set the write permission.

Fixes #12465.

@MisterDA MisterDA force-pushed the make-promoted-files-read-only branch 3 times, most recently from 28175f9 to adaa913 Compare September 30, 2025 10:26
Copy link
Copy Markdown
Collaborator

@Leonidas-from-XIV Leonidas-from-XIV left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, I've got a few comments, mostly about the readability of the code.

Comment thread bin/subst.ml Outdated
Comment thread test/blackbox-tests/test-cases/ignore-promoted-rules-internal-rules.t Outdated
Comment thread test/blackbox-tests/test-cases/promote/old-tests.t/run.t Outdated
Comment thread test/blackbox-tests/test-cases/promote/promote-only-when-needed.t Outdated
@shonfeder shonfeder self-assigned this Sep 30, 2025
@MisterDA MisterDA force-pushed the make-promoted-files-read-only branch from f76fa7a to e4c2a39 Compare September 30, 2025 16:29
@MisterDA
Copy link
Copy Markdown
Contributor Author

Thanks for the review.

Catching the return code and the error message like this is not portable (even between macOS and Linux).

  $ echo plop > file
  file: Permission denied
  [1]

I'm tempted to do, if there is no better alternative,

if ! echo plop >file 2>/dev/null; then >&2 echo "file: Permission denied"; exit 1; fi

@Leonidas-from-XIV
Copy link
Copy Markdown
Collaborator

I think the test could also be changed to check whether the flags are set, so something like dune_cmd stat permissions (which I assume mostly exists to deal with ls output being nonportable).

@MisterDA MisterDA force-pushed the make-promoted-files-read-only branch from e4c2a39 to db39536 Compare October 1, 2025 09:47
@Leonidas-from-XIV
Copy link
Copy Markdown
Collaborator

Ping @nojb on this, as Nicolás expressed interest in this on #12465.

Comment thread doc/changes/12519.md Outdated
Alizter
Alizter previously approved these changes Oct 3, 2025
@Alizter Alizter dismissed their stale review October 3, 2025 09:45

I'm a bit worried about the test-suite errors actually. I will re-review when those are fixed.

Comment thread bin/subst.ml Outdated
Comment thread bin/subst.ml Outdated
@Leonidas-from-XIV
Copy link
Copy Markdown
Collaborator

One of the things I suggested in the original issue was to make this change gated on dune-lang 3.21, to not break users that depend on potentially writing to the file (however I don't know if that would actually affect anyone, so maybe ok to include it in the alpha-release and see if the revdeps have failures).

@MisterDA MisterDA force-pushed the make-promoted-files-read-only branch 2 times, most recently from 1e7249d to d464904 Compare October 3, 2025 16:00
@MisterDA
Copy link
Copy Markdown
Contributor Author

MisterDA commented Oct 3, 2025

Thanks all for the pointers. The patch is nicer now, and the CI is passing.

Comment thread bin/subst.ml Outdated
Signed-off-by: Antonin Décimo <antonin@tarides.com>
@MisterDA MisterDA force-pushed the make-promoted-files-read-only branch from e490798 to c2a4aac Compare October 4, 2025 10:51
@rgrinberg rgrinberg merged commit bcf3242 into ocaml:main Oct 4, 2025
25 checks passed
@MisterDA MisterDA deleted the make-promoted-files-read-only branch October 4, 2025 11:31
@ejgallego
Copy link
Copy Markdown
Collaborator

One of the things I suggested in the original issue was to make this change gated on dune-lang 3.21, to not break users that depend on potentially writing to the file (however I don't know if that would actually affect anyone, so maybe ok to include it in the alpha-release and see if the revdeps have failures).

I came to this issue to ask for the same, this seems like a user impacting change, so indeed gating it under dune-lang 3.21 seems like a good idea.

I am positive that there are lot of projects in the Rocq land (jsRocq, industrial users) that are not in opam, so the impact of these kind of changes are hard to evaluate until dune is fully released.

@MisterDA
Copy link
Copy Markdown
Contributor Author

MisterDA commented Oct 7, 2025

so the impact of these kind of changes are hard to evaluate until dune is fully released.

(🙈🙉🙊 is this why we have patch releases)

@shonfeder shonfeder mentioned this pull request Nov 10, 2025
43 tasks
Alizter added a commit to Alizter/dune that referenced this pull request Nov 24, 2025
This adds a mechanism to thread the workspace level dune lang through
the workspace resolution code and guard the permission changes added in
ocaml#12519 with 3.21.

Signed-off-by: Ali Caglayan <alizter@gmail.com>
shonfeder added a commit that referenced this pull request Nov 28, 2025
shonfeder added a commit to shonfeder/dune that referenced this pull request Nov 28, 2025
This reverts commit bcf3242.

Signed-off-by: Shon Feder <shon.feder@gmail.com>
shonfeder added a commit that referenced this pull request Nov 28, 2025
This reverts commit bcf3242.

Signed-off-by: Shon Feder <shon.feder@gmail.com>
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.

Mark promoted files as read-only

7 participants