-
Notifications
You must be signed in to change notification settings - Fork 125
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
Figure out how to deal with inaccessible parent directories #40
Comments
According to What non-Linux Unixes support openat? from StackOverflow:
|
Ah. The information I was looking at was from 2011. Good to know. |
|
I'm tracking all 4.0 changes in #327. |
Hm. Actually, I'm going to re-open this so we have a place to discuss it. To implement this:
Maybe just implement the latter? |
Plenty of other ways in which a base directory name/path might start not working right:
Holding the dirfd of an immediate parent handles most of these problems (with the chief problem of it being difficult to have a full-featured API that also supports windows in the same way). The only thing I'm not super sure of is whether |
A: yes, if the write permissions on the directory change while holding the use rustix::fs::*;
fn main() {
let cwd = open(".", OFlags::DIRECTORY, Mode::empty()).unwrap();
mkdirat(&cwd, "testdir", Mode::RWXU).expect("remove ./testdir before trying again");
let dirfd = openat(&cwd, "testdir", OFlags::DIRECTORY, Mode::empty()).unwrap();
let file = openat(&dirfd, "filename", OFlags::CREATE | OFlags::TRUNC | OFlags::WRONLY, Mode::RWXU).unwrap();
fchmod(&dirfd, Mode::empty()).unwrap(); // same with `r-x` or `rw-`
drop(file); // close
unlinkat(&dirfd, "filename", AtFlags::empty()).unwrap(); // fails with PermissionDenied
} But at least we wouldn't be deleting files in potentially wrong places altogether. |
I think the remaining issues would be:
In terms of Windows support, I can actually delete files by handle (probably, there are some edge cases). I should switch to that anyways. The main reason I haven't done this is that it'll cost another file descriptor, even in cases where the user might not expect it (e.g., |
So, unix really is lovely...
As written, this library has the same problem as the second case. We use the absolute path when creating temporary files instead of the relative path. I believe this can actually be an issue in practice with some jails.
Fixing this on linux is doable with
openat
andunlinkat
. Fixing this on osx is possible using per-thread CWDs (at the cost of two extra syscalls to set/unset the thread-local CWD).The text was updated successfully, but these errors were encountered: