pub fn is_file_read_write(file: &File) -> Result<(bool, bool)>
Expand description

Return a pair of booleans indicating whether the given file is opened for reading and writing, respectively.

Examples found in repository?
src/fs/reopen.rs (line 14)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
pub fn reopen(file: &fs::File, options: &OpenOptions) -> io::Result<fs::File> {
    let (read, write) = is_file_read_write(file)?;

    // Don't grant more rights than the original file had. And don't allow
    // it to create a file.
    if options.create
        || options.create_new
        || (!read && options.read)
        || (!write && (options.write || options.append || options.truncate))
    {
        return Err(io::Error::new(
            io::ErrorKind::PermissionDenied,
            "Couldn't reopen file",
        ));
    }

    let new = reopen_impl(file, options)?;

    if !is_same_file(file, &new)? {
        return Err(io::Error::new(io::ErrorKind::Other, "Couldn't reopen file"));
    }

    Ok(new)
}