Sha256: d1ab807433f33a2298096d9f8962452e283282ba3e4d974078f1e4cd6329fc1a

Contents?: true

Size: 1.15 KB

Versions: 39

Compression:

Stored size: 1.15 KB

Contents

//! Re-open a `fs::File` to produce an independent handle.

use crate::fs::{is_file_read_write, is_same_file, reopen_impl, OpenOptions};
use std::{fs, io};

/// Re-open an `fs::File` to produce an independent handle.
///
/// This operation isn't supported by all operating systems in all
/// circumstances, or in some operating systems in any circumstances,
/// so it may return an `io::ErrorKind::Other` error if the file
/// cannot be reopened.
#[inline]
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)
}

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
wasmtime-30.0.2 ./ext/cargo-vendor/cap-primitives-3.4.2/src/fs/reopen.rs
wasmtime-29.0.0 ./ext/cargo-vendor/cap-primitives-3.4.2/src/fs/reopen.rs
wasmtime-28.0.0 ./ext/cargo-vendor/cap-primitives-3.4.2/src/fs/reopen.rs
wasmtime-27.0.0 ./ext/cargo-vendor/cap-primitives-3.4.1/src/fs/reopen.rs
wasmtime-26.0.0 ./ext/cargo-vendor/cap-primitives-3.3.0/src/fs/reopen.rs
wasmtime-25.0.2 ./ext/cargo-vendor/cap-primitives-3.2.0/src/fs/reopen.rs
wasmtime-25.0.1 ./ext/cargo-vendor/cap-primitives-3.2.0/src/fs/reopen.rs
wasmtime-25.0.0 ./ext/cargo-vendor/cap-primitives-3.2.0/src/fs/reopen.rs
wasmtime-24.0.0 ./ext/cargo-vendor/cap-primitives-3.2.0/src/fs/reopen.rs
wasmtime-23.0.2 ./ext/cargo-vendor/cap-primitives-3.1.0/src/fs/reopen.rs
wasmtime-22.0.0 ./ext/cargo-vendor/cap-primitives-3.1.0/src/fs/reopen.rs
wasmtime-21.0.1 ./ext/cargo-vendor/cap-primitives-3.1.0/src/fs/reopen.rs
wasmtime-20.0.2 ./ext/cargo-vendor/cap-primitives-3.1.0/src/fs/reopen.rs
wasmtime-20.0.0 ./ext/cargo-vendor/cap-primitives-3.0.0/src/fs/reopen.rs
wasmtime-18.0.3 ./ext/cargo-vendor/cap-primitives-2.0.1/src/fs/reopen.rs
wasmtime-17.0.1 ./ext/cargo-vendor/cap-primitives-2.0.1/src/fs/reopen.rs
wasmtime-17.0.0 ./ext/cargo-vendor/cap-primitives-2.0.1/src/fs/reopen.rs
wasmtime-16.0.0 ./ext/cargo-vendor/cap-primitives-2.0.1/src/fs/reopen.rs
wasmtime-15.0.1 ./ext/cargo-vendor/cap-primitives-2.0.1/src/fs/reopen.rs
wasmtime-15.0.0 ./ext/cargo-vendor/cap-primitives-2.0.1/src/fs/reopen.rs