File tree 5 files changed +52
-44
lines changed
5 files changed +52
-44
lines changed Original file line number Diff line number Diff line change 1
1
use cfg_if:: cfg_if;
2
2
3
+ fn emulate_freebsd_from_env ( ) -> bool {
4
+ use once_cell:: sync:: OnceCell ;
5
+ static CELL : OnceCell < bool > = OnceCell :: new ( ) ;
6
+ * CELL . get_or_init ( || {
7
+ let emulate = !matches ! (
8
+ std:: env:: var( "POSSUM_EMULATE_FREEBSD" ) ,
9
+ Err ( std:: env:: VarError :: NotPresent )
10
+ ) ;
11
+ if emulate {
12
+ super :: error!( "emulating freebsd" ) ;
13
+ }
14
+ emulate
15
+ } )
16
+ }
17
+
18
+ /// FreeBSD doesn't support file range locking or block cloning (yet). We can emulate FreeBSD on
19
+ /// platforms that have flock().
3
20
pub ( crate ) fn emulate_freebsd ( ) -> bool {
4
21
cfg_if ! {
5
22
if #[ cfg( target_os = "freebsd" ) ] {
6
23
true
7
24
} else {
8
- use once_cell:: sync:: OnceCell ;
9
- static CELL : OnceCell <bool > = OnceCell :: new( ) ;
10
- * CELL . get_or_init( || {
11
- let emulate = !matches!(
12
- std:: env:: var( "POSSUM_EMULATE_FREEBSD" ) ,
13
- Err ( std:: env:: VarError :: NotPresent )
14
- ) ;
15
- if emulate {
16
- super :: error!( "emulating freebsd" ) ;
17
- }
18
- emulate
19
- } )
25
+ emulate_freebsd_from_env( )
20
26
}
21
27
}
22
28
}
23
29
30
+ /// Whether to use flock() instead of file segment locking. flock() is not available on Windows.
24
31
pub ( crate ) fn flocking ( ) -> bool {
25
32
emulate_freebsd ( )
26
33
}
Original file line number Diff line number Diff line change @@ -6,9 +6,9 @@ use shuttle::sync;
6
6
#[ cfg( not( shuttle) ) ]
7
7
use std:: sync;
8
8
9
- pub use sync:: * ;
10
9
use sync:: Mutex as InnerMutex ;
11
10
use sync:: MutexGuard as InnerMutexGuard ;
11
+ pub use sync:: * ;
12
12
// These types work in any sync context.
13
13
use std:: sync:: { LockResult , PoisonError } ;
14
14
Original file line number Diff line number Diff line change @@ -15,8 +15,6 @@ pub use flock::*;
15
15
pub ( crate ) use pathconf:: * ;
16
16
pub use punchfile:: * ;
17
17
18
- use crate :: env:: { emulate_freebsd, flocking} ;
19
-
20
18
cfg_if ! {
21
19
if #[ cfg( windows) ] {
22
20
mod windows;
@@ -75,30 +73,3 @@ pub trait FileSystemFlags {
75
73
pub trait DirMeta {
76
74
fn file_system_flags ( & self ) -> io:: Result < impl FileSystemFlags > ;
77
75
}
78
-
79
- struct UnixFilesystemFlags { }
80
-
81
- impl FileSystemFlags for UnixFilesystemFlags {
82
- fn supports_sparse_files ( & self ) -> bool {
83
- // AFAIK, all unix systems support sparse files on all filesystems.
84
- true
85
- }
86
-
87
- fn supports_block_cloning ( & self ) -> Option < bool > {
88
- // AFAIK there's no way to check if a filesystem supports block cloning on non-Windows
89
- // platforms, and even then it depends on where you're copying to/from, sometimes even on
90
- // the same filesystem.
91
- if emulate_freebsd ( ) {
92
- Some ( false )
93
- } else {
94
- None
95
- }
96
- }
97
- }
98
-
99
- #[ cfg( not( windows) ) ]
100
- impl DirMeta for File {
101
- fn file_system_flags ( & self ) -> io:: Result < impl FileSystemFlags > {
102
- Ok ( UnixFilesystemFlags { } )
103
- }
104
- }
Original file line number Diff line number Diff line change
1
+ use std:: fs:: File ;
2
+ use std:: io;
1
3
use std:: path:: Path ;
2
4
3
5
pub ( crate ) use nix:: errno:: errno;
6
+ use crate :: sys:: { DirMeta , FileSystemFlags } ;
7
+
8
+ use crate :: env:: { emulate_freebsd} ;
4
9
5
10
pub fn path_disk_allocation ( path : & Path ) -> std:: io:: Result < u64 > {
6
11
let metadata = std:: fs:: metadata ( path) ?;
7
12
use std:: os:: unix:: fs:: MetadataExt ;
8
13
Ok ( metadata. blocks ( ) * 512 )
9
14
}
15
+
16
+ struct UnixFilesystemFlags { }
17
+
18
+ impl FileSystemFlags for UnixFilesystemFlags {
19
+ fn supports_sparse_files ( & self ) -> bool {
20
+ // AFAIK, all unix systems support sparse files on all filesystems.
21
+ true
22
+ }
23
+
24
+ fn supports_block_cloning ( & self ) -> Option < bool > {
25
+ // AFAIK there's no way to check if a filesystem supports block cloning on non-Windows
26
+ // platforms, and even then it depends on where you're copying to/from, sometimes even on
27
+ // the same filesystem.
28
+ if emulate_freebsd ( ) {
29
+ Some ( false )
30
+ } else {
31
+ None
32
+ }
33
+ }
34
+ }
35
+
36
+ impl DirMeta for File {
37
+ fn file_system_flags ( & self ) -> io:: Result < impl FileSystemFlags > {
38
+ Ok ( UnixFilesystemFlags { } )
39
+ }
40
+ }
Original file line number Diff line number Diff line change @@ -10,8 +10,7 @@ use crate::testing::*;
10
10
11
11
pub ( crate ) fn check_concurrency (
12
12
f : impl Fn ( ) -> anyhow:: Result < ( ) > + Send + Sync + ' static ,
13
- #[ allow( unused_variables) ]
14
- iterations_hint : usize ,
13
+ #[ allow( unused_variables) ] iterations_hint : usize ,
15
14
) -> anyhow:: Result < ( ) > {
16
15
#[ cfg( loom) ]
17
16
{
You can’t perform that action at this time.
0 commit comments