@@ -1212,9 +1212,8 @@ pub fn readdir(p: &Path) -> io::Result<ReadDir> {
12121212 }
12131213}
12141214
1215- pub fn unlink ( p : & Path ) -> io:: Result < ( ) > {
1216- let p_u16s = maybe_verbatim ( p) ?;
1217- if unsafe { c:: DeleteFileW ( p_u16s. as_ptr ( ) ) } == 0 {
1215+ pub fn unlink ( path : & [ u16 ] ) -> io:: Result < ( ) > {
1216+ if unsafe { c:: DeleteFileW ( path. as_ptr ( ) ) } == 0 {
12181217 let err = api:: get_last_error ( ) ;
12191218 // if `DeleteFileW` fails with ERROR_ACCESS_DENIED then try to remove
12201219 // the file while ignoring the readonly attribute.
@@ -1223,7 +1222,7 @@ pub fn unlink(p: &Path) -> io::Result<()> {
12231222 let mut opts = OpenOptions :: new ( ) ;
12241223 opts. access_mode ( c:: DELETE ) ;
12251224 opts. custom_flags ( c:: FILE_FLAG_OPEN_REPARSE_POINT ) ;
1226- if let Ok ( f) = File :: open_native ( & p_u16s , & opts) {
1225+ if let Ok ( f) = File :: open_native ( & path , & opts) {
12271226 if f. posix_delete ( ) . is_ok ( ) {
12281227 return Ok ( ( ) ) ;
12291228 }
@@ -1236,10 +1235,7 @@ pub fn unlink(p: &Path) -> io::Result<()> {
12361235 }
12371236}
12381237
1239- pub fn rename ( old : & Path , new : & Path ) -> io:: Result < ( ) > {
1240- let old = maybe_verbatim ( old) ?;
1241- let new = maybe_verbatim ( new) ?;
1242-
1238+ pub fn rename ( old : & [ u16 ] , new : & [ u16 ] ) -> io:: Result < ( ) > {
12431239 if unsafe { c:: MoveFileExW ( old. as_ptr ( ) , new. as_ptr ( ) , c:: MOVEFILE_REPLACE_EXISTING ) } == 0 {
12441240 let err = api:: get_last_error ( ) ;
12451241 // if `MoveFileExW` fails with ERROR_ACCESS_DENIED then try to move
@@ -1309,20 +1305,19 @@ pub fn rename(old: &Path, new: &Path) -> io::Result<()> {
13091305 Ok ( ( ) )
13101306}
13111307
1312- pub fn rmdir ( p : & Path ) -> io:: Result < ( ) > {
1313- let p = maybe_verbatim ( p) ?;
1308+ pub fn rmdir ( p : & [ u16 ] ) -> io:: Result < ( ) > {
13141309 cvt ( unsafe { c:: RemoveDirectoryW ( p. as_ptr ( ) ) } ) ?;
13151310 Ok ( ( ) )
13161311}
13171312
1318- pub fn remove_dir_all ( path : & Path ) -> io:: Result < ( ) > {
1313+ pub fn remove_dir_all ( path : & [ u16 ] ) -> io:: Result < ( ) > {
13191314 // Open a file or directory without following symlinks.
13201315 let mut opts = OpenOptions :: new ( ) ;
13211316 opts. access_mode ( c:: FILE_LIST_DIRECTORY ) ;
13221317 // `FILE_FLAG_BACKUP_SEMANTICS` allows opening directories.
13231318 // `FILE_FLAG_OPEN_REPARSE_POINT` opens a link instead of its target.
13241319 opts. custom_flags ( c:: FILE_FLAG_BACKUP_SEMANTICS | c:: FILE_FLAG_OPEN_REPARSE_POINT ) ;
1325- let file = File :: open ( path, & opts) ?;
1320+ let file = File :: open_native ( path, & opts) ?;
13261321
13271322 // Test if the file is not a directory or a symlink to a directory.
13281323 if ( file. basic_info ( ) ?. FileAttributes & c:: FILE_ATTRIBUTE_DIRECTORY ) == 0 {
@@ -1333,14 +1328,14 @@ pub fn remove_dir_all(path: &Path) -> io::Result<()> {
13331328 remove_dir_all_iterative ( file) . io_result ( )
13341329}
13351330
1336- pub fn readlink ( path : & Path ) -> io:: Result < PathBuf > {
1331+ pub fn readlink ( path : & [ u16 ] ) -> io:: Result < PathBuf > {
13371332 // Open the link with no access mode, instead of generic read.
13381333 // By default FILE_LIST_DIRECTORY is denied for the junction "C:\Documents and Settings", so
13391334 // this is needed for a common case.
13401335 let mut opts = OpenOptions :: new ( ) ;
13411336 opts. access_mode ( 0 ) ;
13421337 opts. custom_flags ( c:: FILE_FLAG_OPEN_REPARSE_POINT | c:: FILE_FLAG_BACKUP_SEMANTICS ) ;
1343- let file = File :: open ( path, & opts) ?;
1338+ let file = File :: open_native ( & path, & opts) ?;
13441339 file. readlink ( )
13451340}
13461341
@@ -1378,19 +1373,17 @@ pub fn symlink_inner(original: &Path, link: &Path, dir: bool) -> io::Result<()>
13781373}
13791374
13801375#[ cfg( not( target_vendor = "uwp" ) ) ]
1381- pub fn link ( original : & Path , link : & Path ) -> io:: Result < ( ) > {
1382- let original = maybe_verbatim ( original) ?;
1383- let link = maybe_verbatim ( link) ?;
1376+ pub fn link ( original : & [ u16 ] , link : & [ u16 ] ) -> io:: Result < ( ) > {
13841377 cvt ( unsafe { c:: CreateHardLinkW ( link. as_ptr ( ) , original. as_ptr ( ) , ptr:: null_mut ( ) ) } ) ?;
13851378 Ok ( ( ) )
13861379}
13871380
13881381#[ cfg( target_vendor = "uwp" ) ]
1389- pub fn link ( _original : & Path , _link : & Path ) -> io:: Result < ( ) > {
1382+ pub fn link ( _original : & [ u16 ] , _link : & [ u16 ] ) -> io:: Result < ( ) > {
13901383 return Err ( io:: const_error!( io:: ErrorKind :: Unsupported , "hard link are not supported on UWP" ) ) ;
13911384}
13921385
1393- pub fn stat ( path : & Path ) -> io:: Result < FileAttr > {
1386+ pub fn stat ( path : & [ u16 ] ) -> io:: Result < FileAttr > {
13941387 match metadata ( path, ReparsePoint :: Follow ) {
13951388 Err ( err) if err. raw_os_error ( ) == Some ( c:: ERROR_CANT_ACCESS_FILE as i32 ) => {
13961389 if let Ok ( attrs) = lstat ( path) {
@@ -1404,7 +1397,7 @@ pub fn stat(path: &Path) -> io::Result<FileAttr> {
14041397 }
14051398}
14061399
1407- pub fn lstat ( path : & Path ) -> io:: Result < FileAttr > {
1400+ pub fn lstat ( path : & [ u16 ] ) -> io:: Result < FileAttr > {
14081401 metadata ( path, ReparsePoint :: Open )
14091402}
14101403
@@ -1420,7 +1413,7 @@ impl ReparsePoint {
14201413 }
14211414}
14221415
1423- fn metadata ( path : & Path , reparse : ReparsePoint ) -> io:: Result < FileAttr > {
1416+ fn metadata ( path : & [ u16 ] , reparse : ReparsePoint ) -> io:: Result < FileAttr > {
14241417 let mut opts = OpenOptions :: new ( ) ;
14251418 // No read or write permissions are necessary
14261419 opts. access_mode ( 0 ) ;
@@ -1429,7 +1422,7 @@ fn metadata(path: &Path, reparse: ReparsePoint) -> io::Result<FileAttr> {
14291422 // Attempt to open the file normally.
14301423 // If that fails with `ERROR_SHARING_VIOLATION` then retry using `FindFirstFileExW`.
14311424 // If the fallback fails for any reason we return the original error.
1432- match File :: open ( path, & opts) {
1425+ match File :: open_native ( & path, & opts) {
14331426 Ok ( file) => file. file_attr ( ) ,
14341427 Err ( e)
14351428 if [ Some ( c:: ERROR_SHARING_VIOLATION as _ ) , Some ( c:: ERROR_ACCESS_DENIED as _ ) ]
@@ -1442,8 +1435,6 @@ fn metadata(path: &Path, reparse: ReparsePoint) -> io::Result<FileAttr> {
14421435 // However, there are special system files, such as
14431436 // `C:\hiberfil.sys`, that are locked in a way that denies even that.
14441437 unsafe {
1445- let path = maybe_verbatim ( path) ?;
1446-
14471438 // `FindFirstFileExW` accepts wildcard file names.
14481439 // Fortunately wildcards are not valid file names and
14491440 // `ERROR_SHARING_VIOLATION` means the file exists (but is locked)
@@ -1482,8 +1473,7 @@ fn metadata(path: &Path, reparse: ReparsePoint) -> io::Result<FileAttr> {
14821473 }
14831474}
14841475
1485- pub fn set_perm ( p : & Path , perm : FilePermissions ) -> io:: Result < ( ) > {
1486- let p = maybe_verbatim ( p) ?;
1476+ pub fn set_perm ( p : & [ u16 ] , perm : FilePermissions ) -> io:: Result < ( ) > {
14871477 unsafe {
14881478 cvt ( c:: SetFileAttributesW ( p. as_ptr ( ) , perm. attrs ) ) ?;
14891479 Ok ( ( ) )
@@ -1499,17 +1489,17 @@ fn get_path(f: &File) -> io::Result<PathBuf> {
14991489 )
15001490}
15011491
1502- pub fn canonicalize ( p : & Path ) -> io:: Result < PathBuf > {
1492+ pub fn canonicalize ( p : & [ u16 ] ) -> io:: Result < PathBuf > {
15031493 let mut opts = OpenOptions :: new ( ) ;
15041494 // No read or write permissions are necessary
15051495 opts. access_mode ( 0 ) ;
15061496 // This flag is so we can open directories too
15071497 opts. custom_flags ( c:: FILE_FLAG_BACKUP_SEMANTICS ) ;
1508- let f = File :: open ( p, & opts) ?;
1498+ let f = File :: open_native ( p, & opts) ?;
15091499 get_path ( & f)
15101500}
15111501
1512- pub fn copy ( from : & Path , to : & Path ) -> io:: Result < u64 > {
1502+ pub fn copy ( from : & [ u16 ] , to : & [ u16 ] ) -> io:: Result < u64 > {
15131503 unsafe extern "system" fn callback (
15141504 _TotalFileSize : i64 ,
15151505 _TotalBytesTransferred : i64 ,
@@ -1528,13 +1518,11 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
15281518 c:: PROGRESS_CONTINUE
15291519 }
15301520 }
1531- let pfrom = maybe_verbatim ( from) ?;
1532- let pto = maybe_verbatim ( to) ?;
15331521 let mut size = 0i64 ;
15341522 cvt ( unsafe {
15351523 c:: CopyFileExW (
1536- pfrom . as_ptr ( ) ,
1537- pto . as_ptr ( ) ,
1524+ from . as_ptr ( ) ,
1525+ to . as_ptr ( ) ,
15381526 Some ( callback) ,
15391527 ( & raw mut size) as * mut _ ,
15401528 ptr:: null_mut ( ) ,
@@ -1624,14 +1612,14 @@ pub fn junction_point(original: &Path, link: &Path) -> io::Result<()> {
16241612}
16251613
16261614// Try to see if a file exists but, unlike `exists`, report I/O errors.
1627- pub fn exists ( path : & Path ) -> io:: Result < bool > {
1615+ pub fn exists ( path : & [ u16 ] ) -> io:: Result < bool > {
16281616 // Open the file to ensure any symlinks are followed to their target.
16291617 let mut opts = OpenOptions :: new ( ) ;
16301618 // No read, write, etc access rights are needed.
16311619 opts. access_mode ( 0 ) ;
16321620 // Backup semantics enables opening directories as well as files.
16331621 opts. custom_flags ( c:: FILE_FLAG_BACKUP_SEMANTICS ) ;
1634- match File :: open ( path, & opts) {
1622+ match File :: open_native ( path, & opts) {
16351623 Err ( e) => match e. kind ( ) {
16361624 // The file definitely does not exist
16371625 io:: ErrorKind :: NotFound => Ok ( false ) ,
0 commit comments