Skip to content

Add a --chmod option to set file mode on uploaded files#1506

Merged
svenstaro merged 10 commits intosvenstaro:masterfrom
lilydjwg:master
Sep 16, 2025
Merged

Add a --chmod option to set file mode on uploaded files#1506
svenstaro merged 10 commits intosvenstaro:masterfrom
lilydjwg:master

Conversation

@lilydjwg
Copy link
Copy Markdown
Contributor

@lilydjwg lilydjwg commented Jul 8, 2025

see also #124.

I haven't looked into tests / docs yet. It works for me so I send it first to get early feedback.

@lilydjwg lilydjwg marked this pull request as ready for review July 11, 2025 03:06
Copy link
Copy Markdown
Owner

@svenstaro svenstaro left a comment

Choose a reason for hiding this comment

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

Hey, this is excellent! Make sure to also update the README, please.

Comment on lines +539 to +544
#[cfg(unix)]
#[rstest]
#[case(server(&["-u"]), 0o600)]
#[case(server(&["-u", "--chmod", "660"]), 0o660)]
#[case(server(&["-u", "--chmod", "644"]), 0o644)]
fn chmod(#[case] server: TestServer, #[case] expected_mode: u32) -> Result<(), Error> {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Seems like a good test but please add a doc comment explaining the intention. I'd also love to see a second test that tests the chmod error in case you don't have permissions for the chmod but I recognize it might be hard. If you don't find an easy way to test that, it's fine.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, it's hard because the file owner can always chmod the file.

src/args.rs Outdated
long = "chmod",
value_parser(parse_file_mode),
env = "MINISERVE_CHMOD",
default_value = "0600"
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

So far, the default behavior was that we uploaded with default permissions of the underlying system. This changes it and that's a problem. If this option is not set, we shouldn't also apply permissions that differ from the system's default.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So far, the default behavior was that we uploaded with default permissions of the underlying system.

This isn't the case since 413a63a. The file is created with 0600 since then (and it is a problem for me, thus this pr).

I can change it default to what umask says.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Oh crap. Well, looks like no one noticed. Might as well leave your change as it is, then.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've implemented this. It's pretty simple, but I don't know how to write the test (I can't use the utility function to determine the default file mode).

@svenstaro
Copy link
Copy Markdown
Owner

The CI failure looks legit. Wanna look into it?

@lilydjwg
Copy link
Copy Markdown
Contributor Author

I hope it works on all three platforms this time...

@svenstaro
Copy link
Copy Markdown
Owner

This looks great! Thanks! Merging as-is. Sorry for taking some time on this.

@svenstaro svenstaro merged commit 72902f5 into svenstaro:master Sep 16, 2025
20 of 45 checks passed
svenstaro added a commit that referenced this pull request Sep 16, 2025
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