Sha256: 2ea4f228f2640ce63fcc054c4c74336ba59a5b7cc38862e388a2734466524709

Contents?: true

Size: 1.24 KB

Versions: 13

Compression:

Stored size: 1.24 KB

Contents

use crate::fs::{Metadata, MetadataExt};
use std::{fs, io};

/// Determine if `a` and `b` refer to the same inode on the same device.
pub(crate) fn is_same_file(a: &fs::File, b: &fs::File) -> io::Result<bool> {
    let a_metadata = Metadata::from_file(a)?;
    let b_metadata = Metadata::from_file(b)?;
    is_same_file_metadata(&a_metadata, &b_metadata)
}

/// Determine if `a` and `b` are metadata for the same inode on the same
/// device.
pub(crate) fn is_same_file_metadata(a: &Metadata, b: &Metadata) -> io::Result<bool> {
    Ok(a.dev() == b.dev() && a.ino() == b.ino())
}

/// Determine if `a` and `b` definitely refer to different inodes.
///
/// This is similar to `is_same_file`, but is conservative, and doesn't depend
/// on nightly-only features.
#[allow(dead_code)]
pub(crate) fn is_different_file(a: &fs::File, b: &fs::File) -> io::Result<bool> {
    is_same_file(a, b).map(|same| !same)
}

/// Determine if `a` and `b` are metadata for definitely different inodes.
///
/// This is similar to `is_same_file_metadata`, but is conservative, and
/// doesn't depend on nightly-only features.
#[allow(dead_code)]
pub(crate) fn is_different_file_metadata(a: &Metadata, b: &Metadata) -> io::Result<bool> {
    is_same_file_metadata(a, b).map(|same| !same)
}

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
wasmtime-29.0.0 ./ext/cargo-vendor/cap-primitives-3.4.2/src/rustix/fs/is_same_file.rs
wasmtime-28.0.0 ./ext/cargo-vendor/cap-primitives-3.4.2/src/rustix/fs/is_same_file.rs
wasmtime-27.0.0 ./ext/cargo-vendor/cap-primitives-3.4.1/src/rustix/fs/is_same_file.rs
wasmtime-26.0.0 ./ext/cargo-vendor/cap-primitives-3.3.0/src/rustix/fs/is_same_file.rs
wasmtime-25.0.2 ./ext/cargo-vendor/cap-primitives-3.2.0/src/rustix/fs/is_same_file.rs
wasmtime-25.0.1 ./ext/cargo-vendor/cap-primitives-3.2.0/src/rustix/fs/is_same_file.rs
wasmtime-25.0.0 ./ext/cargo-vendor/cap-primitives-3.2.0/src/rustix/fs/is_same_file.rs
wasmtime-24.0.0 ./ext/cargo-vendor/cap-primitives-3.2.0/src/rustix/fs/is_same_file.rs
wasmtime-23.0.2 ./ext/cargo-vendor/cap-primitives-3.1.0/src/rustix/fs/is_same_file.rs
wasmtime-22.0.0 ./ext/cargo-vendor/cap-primitives-3.1.0/src/rustix/fs/is_same_file.rs
wasmtime-21.0.1 ./ext/cargo-vendor/cap-primitives-3.1.0/src/rustix/fs/is_same_file.rs
wasmtime-20.0.2 ./ext/cargo-vendor/cap-primitives-3.1.0/src/rustix/fs/is_same_file.rs
wasmtime-20.0.0 ./ext/cargo-vendor/cap-primitives-3.0.0/src/rustix/fs/is_same_file.rs