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

std: Expose a mode accessor for Permissions on unix #22744

Merged
merged 1 commit into from
Feb 25, 2015

Conversation

alexcrichton
Copy link
Member

Currently we have a set_mode mutator, so this just adds the pairing of a
mode accessor to read the value.

Closes #22738

Currently we have a `set_mode` mutator, so this just adds the pairing of a
`mode` accessor to read the value.

Closes rust-lang#22738
@rust-highfive
Copy link
Collaborator

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member Author

r? @aturon (or others who feel comfortable)

@rust-highfive rust-highfive assigned aturon and unassigned nikomatsakis Feb 23, 2015
@aturon
Copy link
Member

aturon commented Feb 24, 2015

@bors: r+ 537d694

@aturon
Copy link
Member

aturon commented Feb 24, 2015

Note: I am not necessarily happy with this API in the long run!

Manishearth added a commit to Manishearth/rust that referenced this pull request Feb 25, 2015
 Currently we have a `set_mode` mutator, so this just adds the pairing of a
`mode` accessor to read the value.

Closes rust-lang#22738
@bors
Copy link
Contributor

bors commented Feb 25, 2015

⌛ Testing commit 537d694 with merge 8555419...

@bors
Copy link
Contributor

bors commented Feb 25, 2015

💔 Test failed - auto-win-32-nopt-t

@bors bors merged commit 537d694 into rust-lang:master Feb 25, 2015
@alexcrichton alexcrichton deleted the issue-22738 branch March 27, 2015 20:37
@jondot
Copy link

jondot commented Jul 13, 2020

@alexcrichton @aturon coming from the future to haunt you, well, it turns out that reading mode gives out a 16-bit format (includes the file type). It probably relays what ever value the OS has given directly.

However reading after immediately setting the classic 9 bit format (755 for example), gives out the same 9 bit format value, which is different from when we read directly without setting (it gives 16 bit value). It probably relays what ever value Rust cached directly which results in the same 9 bit value which we just set.

So this will fail on the second assert:

    let f = File::create("foo.bar")?;
    let metadata = f.metadata()?;
    let mut permissions = metadata.permissions();
    permissions.set_mode(0o755);
    assert_eq!(permissions.mode(), 0o755);
    fs::set_permissions("foo.bar", permissions)?;

    let f = File::open("foo.bar")?;
    let metadata = f.metadata()?;
    let permissions = metadata.permissions();
    assert_eq!(permissions.mode(), 0o755);   // we are actually getting 0o100755 from the OS here

while the data is correct on the filesystem, this is a surprising behavior in the API.

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.

Accessor for mode bits on Permissions on unix
6 participants