@@ -9,6 +9,7 @@ use std::{fmt, result};
9
9
use common:: StableDeref ;
10
10
use fs2:: FileExt ;
11
11
use memmap2:: Mmap ;
12
+ use normpath:: PathExt ;
12
13
use serde:: { Deserialize , Serialize } ;
13
14
use tempfile:: TempDir ;
14
15
@@ -196,9 +197,9 @@ impl MmapDirectory {
196
197
directory_path,
197
198
) ) ) ;
198
199
}
199
- let canonical_path: PathBuf = directory_path. canonicalize ( ) . map_err ( |io_err| {
200
+ let canonical_path: PathBuf = directory_path. normalize ( ) . map_err ( |io_err| {
200
201
OpenDirectoryError :: wrap_io_error ( io_err, PathBuf :: from ( directory_path) )
201
- } ) ?;
202
+ } ) ?. into_path_buf ( ) ;
202
203
if !canonical_path. is_dir ( ) {
203
204
return Err ( OpenDirectoryError :: NotADirectory ( PathBuf :: from (
204
205
directory_path,
@@ -443,26 +444,23 @@ impl Directory for MmapDirectory {
443
444
Ok ( self . inner . watch ( watch_callback) )
444
445
}
445
446
447
+ #[ cfg( windows) ]
448
+ fn sync_directory ( & self ) -> Result < ( ) , io:: Error > {
449
+ // On Windows, it is not necessary to fsync the parent directory to
450
+ // ensure that the directory entry containing the file has also reached
451
+ // disk, and calling sync_data on a handle to directory is a no-op on
452
+ // local disks, but will return an error on virtual drives.
453
+ Ok ( ( ) )
454
+ }
455
+
456
+ #[ cfg( not( windows) ) ]
446
457
fn sync_directory ( & self ) -> Result < ( ) , io:: Error > {
447
458
let mut open_opts = OpenOptions :: new ( ) ;
448
459
449
460
// Linux needs read to be set, otherwise returns EINVAL
450
461
// write must not be set, or it fails with EISDIR
451
462
open_opts. read ( true ) ;
452
463
453
- // On Windows, opening a directory requires FILE_FLAG_BACKUP_SEMANTICS
454
- // and calling sync_all() only works if write access is requested.
455
- #[ cfg( windows) ]
456
- {
457
- use std:: os:: windows:: fs:: OpenOptionsExt ;
458
-
459
- use winapi:: um:: winbase;
460
-
461
- open_opts
462
- . write ( true )
463
- . custom_flags ( winbase:: FILE_FLAG_BACKUP_SEMANTICS ) ;
464
- }
465
-
466
464
let fd = open_opts. open ( & self . inner . root_path ) ?;
467
465
fd. sync_data ( ) ?;
468
466
Ok ( ( ) )
0 commit comments