-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathdevice.rs
More file actions
41 lines (36 loc) · 1.12 KB
/
device.rs
File metadata and controls
41 lines (36 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use derive_more::{Display, From, Into, LowerHex, Octal, UpperHex};
#[cfg(feature = "json")]
use serde::{Deserialize, Serialize};
/// Whether to cross device boundary into a different filesystem.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DeviceBoundary {
Cross,
Stay,
}
impl DeviceBoundary {
/// Derive device boundary from `--one-file-system`.
#[cfg(feature = "cli")]
pub(crate) fn from_one_file_system(one_file_system: bool) -> Self {
match one_file_system {
false => DeviceBoundary::Cross,
true => DeviceBoundary::Stay,
}
}
}
/// The device number of a filesystem.
#[derive(
Debug, Display, LowerHex, UpperHex, Octal, Clone, Copy, PartialEq, Eq, Hash, From, Into,
)]
#[cfg_attr(feature = "json", derive(Deserialize, Serialize))]
pub struct DeviceNumber(u64);
/// POSIX-exclusive functions.
#[cfg(unix)]
impl DeviceNumber {
/// Get device number of a [`std::fs::Metadata`].
#[inline]
pub fn get(stats: &std::fs::Metadata) -> Self {
use pipe_trait::Pipe;
use std::os::unix::fs::MetadataExt;
stats.dev().pipe(DeviceNumber)
}
}