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

Don't touch access timestamp when inferring type from path #102

Open
pmetras opened this issue Nov 6, 2024 · 0 comments
Open

Don't touch access timestamp when inferring type from path #102

pmetras opened this issue Nov 6, 2024 · 0 comments

Comments

@pmetras
Copy link

pmetras commented Nov 6, 2024

On Unix, when opening a file with std::fs::File::open(), the file is opened with O_RDONLY mode but the access timestamp in the file metadata is updated (see https://github.com/posborne/rust-systems-programming/blob/master/file-io.md and man 7 inode). In the case of infer, trying to infer a file type with infer::get_from_path should be without this side effect as it is on Windows where the file type can be deducted from the extension.

The way to do it is to open the file with the mode O_NOATIME, that can be done with the following code:

// We open the file without changing the access time in the metadata
let mode = (libc::O_RDONLY | libc::O_NOATIME).try_into().unwrap();
let mut file = OpenOptions::new().mode(mode).open(entry.path())?;

Please change infer::get_from_path to remove this side effect.

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

No branches or pull requests

1 participant