Conversation
|
Any special-casing of Miri in the standard library requires review. cc @rust-lang/miri |
|
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| fn metadata_at_native(&self, path: &[u16], reparse: ReparsePoint) -> io::Result<FileAttr> { | ||
| let mut opts = OpenOptions::new(); | ||
| // No read or write permissions are necessary | ||
| opts.access_mode(0); | ||
| opts.custom_flags(c::FILE_FLAG_BACKUP_SEMANTICS | reparse.as_flag()); | ||
|
|
||
| // Attempt to open the file normally. | ||
| // FIXME: `fs::metadata` has a fallback path when that fails. That has not (yet) been ported | ||
| // to directory handles. | ||
| let name = UnicodeStrRef::from_slice(path); | ||
| let object_attributes = c::OBJECT_ATTRIBUTES { | ||
| RootDirectory: self.handle.as_raw_handle(), | ||
| ObjectName: name.as_ptr().cast_mut(), | ||
| ..c::OBJECT_ATTRIBUTES::with_length() | ||
| }; | ||
| let create_opt = 0; // We don't want to create anything, only open existing things. | ||
| let handle = unsafe { nt_create_file(&opts, &object_attributes, create_opt)? }; | ||
| File { handle }.file_attr() | ||
| } |
There was a problem hiding this comment.
@ChrisDenton I hope this makes sense, I am mostly guessing here.^^ Especially about passing 0 for create_opt; the only other caller passes if dir { c::FILE_DIRECTORY_FILE } else { c::FILE_NON_DIRECTORY_FILE } but we cannot know in advance whether this is a directory or a file...
I also didn't copy the complicated fallback stuff from fs::metadata as I had no idea what that would look like with directory handles. I hope this first step is still useful and we can always add more fallback code later?
There was a problem hiding this comment.
I left some notes but essentially NT APIs are a bit different to the higher level win32 APIs. I'm ok with a partial implementation since I think I'm likely going to be rewriting (or at least refactoring) a lot of this anyway.
This comment was marked as resolved.
This comment was marked as resolved.
This comment has been minimized.
This comment has been minimized.
Add `Dir::metadata_at` & `Dir::symlink_metadata_at` try-job: test*msvc*
63a2987 to
6edd866
Compare
This comment has been minimized.
This comment has been minimized.
23f96b7 to
473f0c0
Compare
This comment has been minimized.
This comment has been minimized.
|
Hm... Does this not support This isn't even in my new method, the failure is from dir.open_file_with("subdir/bar.txt", &OpenOptions::new().create(true).write(true))I should file an issue... EDIT: #163032 |
473f0c0 to
cb648f2
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment has been minimized.
This comment has been minimized.
Add `Dir::metadata_at` & `Dir::symlink_metadata_at` try-job: test-*-msvc-1
| /// } | ||
| /// ``` | ||
| #[unstable(feature = "dirfd", issue = "120426")] | ||
| pub fn metadata_at<P: AsRef<Path>>(&self, path: P) -> io::Result<Metadata> { |
There was a problem hiding this comment.
The name does match the operation in fs that it corresponds to -- but Dir::metadata is already taken. So I went for a new name, inspired by the Linux naming scheme with the *at calls working on directory handles.
Alternatives that have been suggested or that I can think of:
- Use just
metadatafor this, and ask people to writedir.metadata(".")to get the metadata of the directory itself. But that seems silly in terms of the extra syscalls it causes. - Use just
metadatafor this, and useself_metadata/metadata_selfor so for the metadata of the directory handle itself.
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
cb648f2 to
eca304d
Compare
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as outdated.
This comment was marked as outdated.
This comment has been minimized.
This comment has been minimized.
Add `Dir::metadata_at` & `Dir::symlink_metadata_at` try-job: test-*-msvc-1
This comment has been minimized.
This comment has been minimized.
This comment was marked as outdated.
This comment was marked as outdated.
| let mut opts = OpenOptions::new(); | ||
| // No read or write permissions are necessary | ||
| opts.access_mode(0); | ||
| opts.custom_flags(c::FILE_FLAG_BACKUP_SEMANTICS | reparse.as_flag()); |
There was a problem hiding this comment.
custom_flags is currently ignored by nt_create_file and those are the wrong types of flags anyway (win32 flags instead of the lower level NT). You'll need to do something like:
let create_opt = if reparse == ReparsePoint::Open { c::FILE_OPEN_REPARSE_POINT } else { 0 };There was a problem hiding this comment.
Hm, so is the existing code also wrong then? rename_native also sets custom_flags.
9fc06fa to
5877c7e
Compare
|
@bors try jobs=test-x86_64-msvc-1 |
This comment has been minimized.
This comment has been minimized.
Add `Dir::metadata_at` & `Dir::symlink_metadata_at` try-job: test-x86_64-msvc-1
|
That seems to have worked, thanks. :-) |
This comment has been minimized.
This comment has been minimized.
5877c7e to
ad2ff3c
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
ad2ff3c to
6fccac1
Compare
This comment has been minimized.
This comment has been minimized.
6fccac1 to
626622f
Compare
View all comments
This adds methods to
Dirthat allow querying the metadata of files/directories relative to aDir. Miri would really like to be able to do this so I figured I'd give it a shot. :)The first commit refactors the Unix
DirEntrymethods a bit withcfg_selectto avoid repeating thecfgcondition.Tracking issue: #120426
try-jobs: test-x86_64-msvc-1