Sha256: f035fd3e113da34f33d93bb28bf7e21f43d7e43c729df85070cc58119704ed87

Contents?: true

Size: 1.7 KB

Versions: 5

Compression:

Stored size: 1.7 KB

Contents

#[cfg(windows_by_handle)]
use super::get_path::concatenate;
use crate::fs::{FollowSymlinks, Metadata};
use std::path::Path;
use std::{fs, io};
#[cfg(not(windows_by_handle))]
use windows_sys::Win32::Storage::FileSystem::{
    FILE_FLAG_BACKUP_SEMANTICS, FILE_FLAG_OPEN_REPARSE_POINT,
};
#[cfg(not(windows_by_handle))]
use {
    crate::fs::{open_unchecked, OpenOptions},
    std::os::windows::fs::OpenOptionsExt,
};

/// *Unsandboxed* function similar to `stat`, but which does not perform
/// sandboxing.
pub(crate) fn stat_unchecked(
    start: &fs::File,
    path: &Path,
    follow: FollowSymlinks,
) -> io::Result<Metadata> {
    // When we have `windows_by_handle`, we just call `fs::metadata` etc. and it
    // has everything.
    #[cfg(windows_by_handle)]
    {
        let full_path = concatenate(start, path)?;
        match follow {
            FollowSymlinks::Yes => fs::metadata(full_path),
            FollowSymlinks::No => fs::symlink_metadata(full_path),
        }
        .map(Metadata::from_just_metadata)
    }

    // Otherwise, attempt to open the file to get the metadata that way, as
    // that gives us all the info.
    #[cfg(not(windows_by_handle))]
    {
        let mut opts = OpenOptions::new();
        opts.access_mode(0);
        match follow {
            FollowSymlinks::Yes => {
                opts.custom_flags(FILE_FLAG_BACKUP_SEMANTICS);
                opts.follow(FollowSymlinks::Yes);
            }
            FollowSymlinks::No => {
                opts.custom_flags(FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS);
                opts.follow(FollowSymlinks::No);
            }
        }
        let file = open_unchecked(start, path, &opts)?;
        Metadata::from_file(&file)
    }
}

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
wasmtime-6.0.1 ./ext/cargo-vendor/cap-primitives-1.0.5/src/windows/fs/stat_unchecked.rs
wasmtime-6.0.0 ./ext/cargo-vendor/cap-primitives-1.0.5/src/windows/fs/stat_unchecked.rs
wasmtime-5.0.0 ./ext/cargo-vendor/cap-primitives-1.0.4/src/windows/fs/stat_unchecked.rs
wasmtime-0.4.1 ./ext/cargo-vendor/cap-primitives-1.0.3/src/windows/fs/stat_unchecked.rs
wasmtime-0.4.0 ./ext/cargo-vendor/cap-primitives-1.0.2/src/windows/fs/stat_unchecked.rs