Skip to content

ACP Implementation of PermissionsExt for Windows #152995

Open
asder8215 wants to merge 2 commits intorust-lang:mainfrom
asder8215:windows_permissions_ext
Open

ACP Implementation of PermissionsExt for Windows #152995
asder8215 wants to merge 2 commits intorust-lang:mainfrom
asder8215:windows_permissions_ext

Conversation

@asder8215
Copy link
Contributor

@asder8215 asder8215 commented Feb 23, 2026

This PR implements the PermissionsExt for Windows ACP and adds file attribute methods in FilePermissions struct (to be decided whether we use them or not). See this tracking issue for further detail and links.

I also added some comments in the code for clarifications about the ACP (e.g. whether we should have a set_file_attributes() + from_file_attributes() method to mirror what unix's PermissionsExt is doing).

Also, some relevant links on this:

Note: Apologies for the multiple forced push. I haven't set up my Windows VM up yet to compile and check the code, so I've been using the CI to help me with that.

r? @ChrisDenton

@rustbot rustbot added O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 23, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 23, 2026

ChrisDenton is currently at their maximum review capacity.
They may take a while to respond.

@rust-log-analyzer

This comment has been minimized.

@asder8215 asder8215 force-pushed the windows_permissions_ext branch from 00739a8 to 2daf248 Compare February 23, 2026 01:04
@rust-log-analyzer

This comment has been minimized.

@asder8215 asder8215 force-pushed the windows_permissions_ext branch from 2daf248 to 29689a6 Compare February 23, 2026 05:47
@rust-log-analyzer

This comment has been minimized.

@asder8215 asder8215 force-pushed the windows_permissions_ext branch from 29689a6 to b752775 Compare February 23, 2026 06:54
@rust-log-analyzer

This comment has been minimized.

@asder8215 asder8215 force-pushed the windows_permissions_ext branch from b752775 to 23a096f Compare February 23, 2026 07:15
/// let mut permissions = Permissions::set_file_attributes(my_file_attr);
/// assert_eq!(permissions.mode(), my_file_attr);
/// ```
pub trait PermissionsExt {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Permissions struct doesn't have a Sealed trait bound (the Unix version of PermissionsExt doesn't use a Sealed trait bound either), so I'm unsure if this should be done here.

Copy link
Member

Choose a reason for hiding this comment

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

Any new structs like this should be sealed. The reason the Unix version of PermissionExt doesn't is an historical artefact and one we'd love to fix. Otherwise it makes adding any functions a breaking change (this can be worked around by adding PermissionExt2 but we'd rather avoid that if possible).

@rust-log-analyzer

This comment has been minimized.

@asder8215 asder8215 force-pushed the windows_permissions_ext branch from 23a096f to 3ed985e Compare February 23, 2026 07:36
@rust-log-analyzer

This comment has been minimized.

…rivate methods in FilePermissions struct (to be decided in PR whether to use or remove)
@asder8215 asder8215 force-pushed the windows_permissions_ext branch from 3ed985e to 696ce60 Compare February 23, 2026 07:58
///
/// // readonly and hidden file attributes that we
/// // want to add to existing file
/// let my_file_attr = 0x1 | 0x2;
Copy link
Member

Choose a reason for hiding this comment

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

Given this is a public example, this should use constants instead of magic values, even if that means defining the constants right about this line.

/// );
/// Ok(())
/// }
/// ```
Copy link
Member

Choose a reason for hiding this comment

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

Actually this whole example seems much more like a test than an example. I think it's better for users if examples are kept short and to the point.

Comment on lines +1166 to +1167
// According to SetFileAttributes, any other values
// passed to this should override FILE_ATTRIBUTE_NORMAL
Copy link
Member

@ChrisDenton ChrisDenton Mar 3, 2026

Choose a reason for hiding this comment

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

Windows itself will override FILE_ATTRIBUTE_NORMAL if another attribute is present so I'm not sure it's necessary for us to do it. But if we do do it then I'd rather use a bitmask rather than repeating if self.normal() each time. Or maybe an internal-only helper function.

@asder8215
Copy link
Contributor Author

asder8215 commented Mar 3, 2026

I'll get to updating this PR later today!

To note, the doctest/example was inspired from the Unix version. I mirrored writing it in the way Unix doc for PermissionsExt did. I do agree with you that I should use const value with specific names than just directly using magic values and clarify the docs a bit more on file attributes. I'm open to bitmasking the normal file attribute out through using an XOR operation and then ORing the result with respective file attributes (and if this actually ends up being unnecessary, I can remove it later down the line).

I'll try and see if I can apply the Sealed trait bound on PermissionsExt, but I also recall receiving a compiler error when I tried that earlier saying that Permissions doesn't implement Sealed trait so I can't implement PermissionsExt on Permissions (I may be misremembering though, will have to check later today).

Thanks for taking a look at this PR @ChrisDenton!

@ChrisDenton
Copy link
Member

I'll try and see if I can apply the Sealed trait bound on PermissionsExt, but I also recall receiving a compiler error when I tried that earlier saying that Permissions doesn't implement Sealed trait so I can't implement PermissionsExt on Permissions (I may be misremembering though, will have to check later today).

You should just be able implement Sealed for PermissionExt.

To note, the doctest/example was inspired from the Unix version. I mirrored writing it in the way Unix doc for PermissionsExt did.

Yeah, after looking at the Unix example I do find that a bit verbose. In either case, considering the example is no_run I do think there should be a test somewhere that actually runs and tests this works.

…d out FILE_ATTRIBUTE_NORMAL in private methods within FilePermissions
@asder8215
Copy link
Contributor Author

asder8215 commented Mar 4, 2026

If there are no compilation errors, then yea I've added your feedback. Let me know if the doc comments for PermissionsExt is okay! I took off the larger no_run example and kept the smaller one in.

On a side note, I've been looking at FilePermissions/Permissions methods and I kind of wished the set_* methods returned itself so that it would be possible to just chain the methods. If the other Windows file attributes have the okay to be implemented on PermissionsExt, do you think it would be fine to just return Self instead of bool for its setter methods?

@rust-log-analyzer
Copy link
Collaborator

The job pr-check-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
/dev/sda15      105M  6.2M   99M   6% /boot/efi
tmpfs           1.6G   12K  1.6G   1% /run/user/1001
================================================================================

Sufficient disk space available (95818016KB >= 52428800KB). Skipping cleanup.
##[group]Run echo "[CI_PR_NUMBER=$num]"
echo "[CI_PR_NUMBER=$num]"
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}

@asder8215
Copy link
Contributor Author

Yeah, after looking at the Unix example I do find that a bit verbose. In either case, considering the example is no_run I do think there should be a test somewhere that actually runs and tests this works.

I'm down to update the Unix example in a separate PR to reduce verbosity. As for testing the functions here, where would be the appropriate place to do that for this PR?

Moreover, does CI here run Windows tests? I've been wondering that a bit because in my Reverse Ancestor PR, I have Windows tests there for paths with Prefix components, but I didn't see anything in CI that mentions that it ran my Windows test (and passes).

@asder8215
Copy link
Contributor Author

Also, yea the Sealed trait bound gives me a compilation error for some reason:
image

  error[E0277]: the trait bound `Permissions: Sealed` is not satisfied
     --> library/std/src/os/windows/fs.rs:399:25
      |
  399 | impl PermissionsExt for Permissions {
      |                         ^^^^^^^^^^^ unsatisfied trait bound
      |
  help: the trait `Sealed` is not implemented for `Permissions`
     --> library/std/src/fs.rs:294:1
      |
  294 | pub struct Permissions(fs_imp::FilePermissions);
      | ^^^^^^^^^^^^^^^^^^^^^^
      = help: the following other types implement trait `Sealed`:
                Child
                OsStr
                OsString
                Simd<f32, N>
                Simd<f64, N>
                StderrLock<'_>
                StdinLock<'_>
                StdoutLock<'_>
              and 12 others
  note: required by a bound in `PermissionsExt`
     --> library/std/src/os/windows/fs.rs:383:27
      |
  383 | pub trait PermissionsExt: Sealed {
      |                           ^^^^^^ required by this bound in `PermissionsExt`

@asder8215 asder8215 requested a review from ChrisDenton March 4, 2026 04:55
@ChrisDenton
Copy link
Member

You'll need to impl Sealed for Permissions. Take a look at FileTypeExt, it should be doing something similar.

@asder8215
Copy link
Contributor Author

asder8215 commented Mar 4, 2026

You'll need to impl Sealed for Permissions. Take a look at FileTypeExt, it should be doing something similar.

Oh okay, I could do that. I was worried that I may not be allowed to do that if it's a breaking change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

O-windows Operating system: Windows S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants