@@ -1212,9 +1212,8 @@ pub fn readdir(p: &Path) -> io::Result<ReadDir> {
1212
1212
}
1213
1213
}
1214
1214
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 {
1218
1217
let err = api:: get_last_error ( ) ;
1219
1218
// if `DeleteFileW` fails with ERROR_ACCESS_DENIED then try to remove
1220
1219
// the file while ignoring the readonly attribute.
@@ -1223,7 +1222,7 @@ pub fn unlink(p: &Path) -> io::Result<()> {
1223
1222
let mut opts = OpenOptions :: new ( ) ;
1224
1223
opts. access_mode ( c:: DELETE ) ;
1225
1224
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) {
1227
1226
if f. posix_delete ( ) . is_ok ( ) {
1228
1227
return Ok ( ( ) ) ;
1229
1228
}
@@ -1236,10 +1235,7 @@ pub fn unlink(p: &Path) -> io::Result<()> {
1236
1235
}
1237
1236
}
1238
1237
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 < ( ) > {
1243
1239
if unsafe { c:: MoveFileExW ( old. as_ptr ( ) , new. as_ptr ( ) , c:: MOVEFILE_REPLACE_EXISTING ) } == 0 {
1244
1240
let err = api:: get_last_error ( ) ;
1245
1241
// if `MoveFileExW` fails with ERROR_ACCESS_DENIED then try to move
@@ -1309,20 +1305,19 @@ pub fn rename(old: &Path, new: &Path) -> io::Result<()> {
1309
1305
Ok ( ( ) )
1310
1306
}
1311
1307
1312
- pub fn rmdir ( p : & Path ) -> io:: Result < ( ) > {
1313
- let p = maybe_verbatim ( p) ?;
1308
+ pub fn rmdir ( p : & [ u16 ] ) -> io:: Result < ( ) > {
1314
1309
cvt ( unsafe { c:: RemoveDirectoryW ( p. as_ptr ( ) ) } ) ?;
1315
1310
Ok ( ( ) )
1316
1311
}
1317
1312
1318
- pub fn remove_dir_all ( path : & Path ) -> io:: Result < ( ) > {
1313
+ pub fn remove_dir_all ( path : & [ u16 ] ) -> io:: Result < ( ) > {
1319
1314
// Open a file or directory without following symlinks.
1320
1315
let mut opts = OpenOptions :: new ( ) ;
1321
1316
opts. access_mode ( c:: FILE_LIST_DIRECTORY ) ;
1322
1317
// `FILE_FLAG_BACKUP_SEMANTICS` allows opening directories.
1323
1318
// `FILE_FLAG_OPEN_REPARSE_POINT` opens a link instead of its target.
1324
1319
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) ?;
1326
1321
1327
1322
// Test if the file is not a directory or a symlink to a directory.
1328
1323
if ( file. basic_info ( ) ?. FileAttributes & c:: FILE_ATTRIBUTE_DIRECTORY ) == 0 {
@@ -1333,14 +1328,14 @@ pub fn remove_dir_all(path: &Path) -> io::Result<()> {
1333
1328
remove_dir_all_iterative ( file) . io_result ( )
1334
1329
}
1335
1330
1336
- pub fn readlink ( path : & Path ) -> io:: Result < PathBuf > {
1331
+ pub fn readlink ( path : & [ u16 ] ) -> io:: Result < PathBuf > {
1337
1332
// Open the link with no access mode, instead of generic read.
1338
1333
// By default FILE_LIST_DIRECTORY is denied for the junction "C:\Documents and Settings", so
1339
1334
// this is needed for a common case.
1340
1335
let mut opts = OpenOptions :: new ( ) ;
1341
1336
opts. access_mode ( 0 ) ;
1342
1337
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) ?;
1344
1339
file. readlink ( )
1345
1340
}
1346
1341
@@ -1378,19 +1373,17 @@ pub fn symlink_inner(original: &Path, link: &Path, dir: bool) -> io::Result<()>
1378
1373
}
1379
1374
1380
1375
#[ 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 < ( ) > {
1384
1377
cvt ( unsafe { c:: CreateHardLinkW ( link. as_ptr ( ) , original. as_ptr ( ) , ptr:: null_mut ( ) ) } ) ?;
1385
1378
Ok ( ( ) )
1386
1379
}
1387
1380
1388
1381
#[ cfg( target_vendor = "uwp" ) ]
1389
- pub fn link ( _original : & Path , _link : & Path ) -> io:: Result < ( ) > {
1382
+ pub fn link ( _original : & [ u16 ] , _link : & [ u16 ] ) -> io:: Result < ( ) > {
1390
1383
return Err ( io:: const_error!( io:: ErrorKind :: Unsupported , "hard link are not supported on UWP" ) ) ;
1391
1384
}
1392
1385
1393
- pub fn stat ( path : & Path ) -> io:: Result < FileAttr > {
1386
+ pub fn stat ( path : & [ u16 ] ) -> io:: Result < FileAttr > {
1394
1387
match metadata ( path, ReparsePoint :: Follow ) {
1395
1388
Err ( err) if err. raw_os_error ( ) == Some ( c:: ERROR_CANT_ACCESS_FILE as i32 ) => {
1396
1389
if let Ok ( attrs) = lstat ( path) {
@@ -1404,7 +1397,7 @@ pub fn stat(path: &Path) -> io::Result<FileAttr> {
1404
1397
}
1405
1398
}
1406
1399
1407
- pub fn lstat ( path : & Path ) -> io:: Result < FileAttr > {
1400
+ pub fn lstat ( path : & [ u16 ] ) -> io:: Result < FileAttr > {
1408
1401
metadata ( path, ReparsePoint :: Open )
1409
1402
}
1410
1403
@@ -1420,7 +1413,7 @@ impl ReparsePoint {
1420
1413
}
1421
1414
}
1422
1415
1423
- fn metadata ( path : & Path , reparse : ReparsePoint ) -> io:: Result < FileAttr > {
1416
+ fn metadata ( path : & [ u16 ] , reparse : ReparsePoint ) -> io:: Result < FileAttr > {
1424
1417
let mut opts = OpenOptions :: new ( ) ;
1425
1418
// No read or write permissions are necessary
1426
1419
opts. access_mode ( 0 ) ;
@@ -1429,7 +1422,7 @@ fn metadata(path: &Path, reparse: ReparsePoint) -> io::Result<FileAttr> {
1429
1422
// Attempt to open the file normally.
1430
1423
// If that fails with `ERROR_SHARING_VIOLATION` then retry using `FindFirstFileExW`.
1431
1424
// 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) {
1433
1426
Ok ( file) => file. file_attr ( ) ,
1434
1427
Err ( e)
1435
1428
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> {
1442
1435
// However, there are special system files, such as
1443
1436
// `C:\hiberfil.sys`, that are locked in a way that denies even that.
1444
1437
unsafe {
1445
- let path = maybe_verbatim ( path) ?;
1446
-
1447
1438
// `FindFirstFileExW` accepts wildcard file names.
1448
1439
// Fortunately wildcards are not valid file names and
1449
1440
// `ERROR_SHARING_VIOLATION` means the file exists (but is locked)
@@ -1482,8 +1473,7 @@ fn metadata(path: &Path, reparse: ReparsePoint) -> io::Result<FileAttr> {
1482
1473
}
1483
1474
}
1484
1475
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 < ( ) > {
1487
1477
unsafe {
1488
1478
cvt ( c:: SetFileAttributesW ( p. as_ptr ( ) , perm. attrs ) ) ?;
1489
1479
Ok ( ( ) )
@@ -1499,17 +1489,17 @@ fn get_path(f: &File) -> io::Result<PathBuf> {
1499
1489
)
1500
1490
}
1501
1491
1502
- pub fn canonicalize ( p : & Path ) -> io:: Result < PathBuf > {
1492
+ pub fn canonicalize ( p : & [ u16 ] ) -> io:: Result < PathBuf > {
1503
1493
let mut opts = OpenOptions :: new ( ) ;
1504
1494
// No read or write permissions are necessary
1505
1495
opts. access_mode ( 0 ) ;
1506
1496
// This flag is so we can open directories too
1507
1497
opts. custom_flags ( c:: FILE_FLAG_BACKUP_SEMANTICS ) ;
1508
- let f = File :: open ( p, & opts) ?;
1498
+ let f = File :: open_native ( p, & opts) ?;
1509
1499
get_path ( & f)
1510
1500
}
1511
1501
1512
- pub fn copy ( from : & Path , to : & Path ) -> io:: Result < u64 > {
1502
+ pub fn copy ( from : & [ u16 ] , to : & [ u16 ] ) -> io:: Result < u64 > {
1513
1503
unsafe extern "system" fn callback (
1514
1504
_TotalFileSize : i64 ,
1515
1505
_TotalBytesTransferred : i64 ,
@@ -1528,13 +1518,11 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
1528
1518
c:: PROGRESS_CONTINUE
1529
1519
}
1530
1520
}
1531
- let pfrom = maybe_verbatim ( from) ?;
1532
- let pto = maybe_verbatim ( to) ?;
1533
1521
let mut size = 0i64 ;
1534
1522
cvt ( unsafe {
1535
1523
c:: CopyFileExW (
1536
- pfrom . as_ptr ( ) ,
1537
- pto . as_ptr ( ) ,
1524
+ from . as_ptr ( ) ,
1525
+ to . as_ptr ( ) ,
1538
1526
Some ( callback) ,
1539
1527
( & raw mut size) as * mut _ ,
1540
1528
ptr:: null_mut ( ) ,
@@ -1624,14 +1612,14 @@ pub fn junction_point(original: &Path, link: &Path) -> io::Result<()> {
1624
1612
}
1625
1613
1626
1614
// 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 > {
1628
1616
// Open the file to ensure any symlinks are followed to their target.
1629
1617
let mut opts = OpenOptions :: new ( ) ;
1630
1618
// No read, write, etc access rights are needed.
1631
1619
opts. access_mode ( 0 ) ;
1632
1620
// Backup semantics enables opening directories as well as files.
1633
1621
opts. custom_flags ( c:: FILE_FLAG_BACKUP_SEMANTICS ) ;
1634
- match File :: open ( path, & opts) {
1622
+ match File :: open_native ( path, & opts) {
1635
1623
Err ( e) => match e. kind ( ) {
1636
1624
// The file definitely does not exist
1637
1625
io:: ErrorKind :: NotFound => Ok ( false ) ,
0 commit comments