@@ -12,11 +12,14 @@ use std::time::{Duration, UNIX_EPOCH};
12
12
13
13
use log:: * ;
14
14
15
+ use crate :: ALL_MOUNTS ;
15
16
use crate :: fs:: dir:: Dir ;
16
17
use crate :: fs:: feature:: xattr;
17
18
use crate :: fs:: feature:: xattr:: { FileAttributes , Attribute } ;
18
19
use crate :: fs:: fields as f;
19
20
21
+ use super :: mounts:: MountedFs ;
22
+
20
23
21
24
/// A **File** is a wrapper around one of Rust’s `PathBuf` values, along with
22
25
/// associated data about the file.
@@ -79,7 +82,9 @@ pub struct File<'dir> {
79
82
pub deref_links : bool ,
80
83
/// The extended attributes of this file.
81
84
pub extended_attributes : Vec < Attribute > ,
82
- }
85
+
86
+ /// The absolute value of this path, used to look up mount points.
87
+ pub absolute_path : PathBuf , }
83
88
84
89
impl < ' dir > File < ' dir > {
85
90
pub fn from_args < PD , FN > ( path : PathBuf , parent_dir : PD , filename : FN , deref_links : bool ) -> io:: Result < File < ' dir > >
@@ -94,8 +99,9 @@ impl<'dir> File<'dir> {
94
99
let metadata = std:: fs:: symlink_metadata ( & path) ?;
95
100
let is_all_all = false ;
96
101
let extended_attributes = File :: gather_extended_attributes ( & path) ;
102
+ let absolute_path = std:: fs:: canonicalize ( & path) ?;
97
103
98
- Ok ( File { name, ext, path, metadata, parent_dir, is_all_all, deref_links, extended_attributes } )
104
+ Ok ( File { name, ext, path, metadata, parent_dir, is_all_all, deref_links, extended_attributes, absolute_path } )
99
105
}
100
106
101
107
pub fn new_aa_current ( parent_dir : & ' dir Dir ) -> io:: Result < File < ' dir > > {
@@ -107,8 +113,9 @@ impl<'dir> File<'dir> {
107
113
let is_all_all = true ;
108
114
let parent_dir = Some ( parent_dir) ;
109
115
let extended_attributes = File :: gather_extended_attributes ( & path) ;
116
+ let absolute_path = std:: fs:: canonicalize ( & path) ?;
110
117
111
- Ok ( File { path, parent_dir, metadata, ext, name : "." . into ( ) , is_all_all, deref_links : false , extended_attributes } )
118
+ Ok ( File { path, parent_dir, metadata, ext, name : "." . into ( ) , is_all_all, deref_links : false , extended_attributes, absolute_path } )
112
119
}
113
120
114
121
pub fn new_aa_parent ( path : PathBuf , parent_dir : & ' dir Dir ) -> io:: Result < File < ' dir > > {
@@ -119,8 +126,9 @@ impl<'dir> File<'dir> {
119
126
let is_all_all = true ;
120
127
let parent_dir = Some ( parent_dir) ;
121
128
let extended_attributes = File :: gather_extended_attributes ( & path) ;
129
+ let absolute_path = std:: fs:: canonicalize ( & path) ?;
122
130
123
- Ok ( File { path, parent_dir, metadata, ext, name : ".." . into ( ) , is_all_all, deref_links : false , extended_attributes } )
131
+ Ok ( File { path, parent_dir, metadata, ext, name : ".." . into ( ) , is_all_all, deref_links : false , extended_attributes, absolute_path } )
124
132
}
125
133
126
134
/// A file’s name is derived from its string. This needs to handle directories
@@ -243,6 +251,21 @@ impl<'dir> File<'dir> {
243
251
self . metadata . file_type ( ) . is_socket ( )
244
252
}
245
253
254
+ /// Whether this file is a mount point
255
+ pub fn is_mount_point ( & self ) -> bool {
256
+ if cfg ! ( target_os = "linux" ) && self . is_directory ( ) {
257
+ return ALL_MOUNTS . contains_key ( & self . absolute_path ) ;
258
+ }
259
+ false
260
+ }
261
+
262
+ /// The filesystem device and type for a mount point
263
+ pub fn mount_point_info ( & self ) -> Option < & MountedFs > {
264
+ if cfg ! ( target_os = "linux" ) {
265
+ return ALL_MOUNTS . get ( & self . absolute_path ) ;
266
+ }
267
+ None
268
+ }
246
269
247
270
/// Re-prefixes the path pointed to by this file, if it’s a symlink, to
248
271
/// make it an absolute path that can be accessed from whichever
@@ -293,7 +316,17 @@ impl<'dir> File<'dir> {
293
316
let ext = File :: ext ( & path) ;
294
317
let name = File :: filename ( & path) ;
295
318
let extended_attributes = File :: gather_extended_attributes ( & absolute_path) ;
296
- let file = File { parent_dir : None , path, ext, metadata, name, is_all_all : false , deref_links : self . deref_links , extended_attributes } ;
319
+ let file = File {
320
+ parent_dir : None ,
321
+ path,
322
+ ext,
323
+ metadata,
324
+ name,
325
+ is_all_all : false ,
326
+ deref_links : self . deref_links ,
327
+ extended_attributes,
328
+ absolute_path
329
+ } ;
297
330
FileTarget :: Ok ( Box :: new ( file) )
298
331
}
299
332
Err ( e) => {
0 commit comments