1
1
#[ cfg( feature = "fs_utf8" ) ]
2
2
use camino:: Utf8Path ;
3
+ #[ cfg( all( windows, feature = "async_std" , feature = "fs_utf8" ) ) ]
4
+ use cap_primitives:: fs:: stat;
3
5
#[ cfg( not( windows) ) ]
4
6
use cap_primitives:: fs:: symlink;
5
- use cap_primitives:: fs:: { open_dir_nofollow, set_times, set_times_nofollow} ;
6
- #[ cfg( all( windows, feature = "async_std" , feature = "fs_utf8" ) ) ]
7
- use cap_primitives:: fs:: { stat, FollowSymlinks } ;
7
+ use cap_primitives:: fs:: {
8
+ access, open_dir_nofollow, set_symlink_permissions, set_times, set_times_nofollow,
9
+ FollowSymlinks , Permissions ,
10
+ } ;
8
11
#[ cfg( windows) ]
9
12
use cap_primitives:: fs:: { symlink_dir, symlink_file} ;
10
13
use io_lifetimes:: AsFilelike ;
@@ -13,7 +16,7 @@ use std::path::Path;
13
16
#[ cfg( feature = "async_std" ) ]
14
17
use { async_std:: task:: spawn_blocking, async_trait:: async_trait} ;
15
18
16
- pub use cap_primitives:: fs:: SystemTimeSpec ;
19
+ pub use cap_primitives:: fs:: { AccessType , SystemTimeSpec } ;
17
20
18
21
/// Extension trait for `Dir`.
19
22
pub trait DirExt {
@@ -95,6 +98,18 @@ pub trait DirExt {
95
98
/// points to a directory, it cannot be removed with the `remove_file`
96
99
/// operation. This method will remove files and all symlinks.
97
100
fn remove_file_or_symlink < P : AsRef < Path > > ( & self , path : P ) -> io:: Result < ( ) > ;
101
+
102
+ /// Test for accessibility or existence of a filesystem object.
103
+ fn access < P : AsRef < Path > > ( & self , path : P , type_ : AccessType ) -> io:: Result < ( ) > ;
104
+
105
+ /// Test for accessibility or existence of a filesystem object, without
106
+ /// following symbolic links.
107
+ fn access_symlink < P : AsRef < Path > > ( & self , path : P , type_ : AccessType ) -> io:: Result < ( ) > ;
108
+
109
+ /// Changes the permissions found on a file or a directory, without following
110
+ /// symbolic links.
111
+ fn set_symlink_permissions < P : AsRef < Path > > ( & self , path : P , perm : Permissions )
112
+ -> io:: Result < ( ) > ;
98
113
}
99
114
100
115
/// Extension trait for `Dir`, async.
@@ -216,6 +231,17 @@ pub trait AsyncDirExt {
216
231
& self ,
217
232
path : P ,
218
233
) -> io:: Result < ( ) > ;
234
+
235
+ /// Test for accessibility or existence of a filesystem object.
236
+ async fn access < P : AsRef < Path > > ( & self , path : P , type_ : AccessType ) -> io:: Result < ( ) > ;
237
+
238
+ /// Changes the permissions found on a file or a directory, without following
239
+ /// symbolic links.
240
+ async fn set_symlink_permissions < P : AsRef < Path > > (
241
+ & self ,
242
+ path : P ,
243
+ perm : Permissions ,
244
+ ) -> io:: Result < ( ) > ;
219
245
}
220
246
221
247
/// `fs_utf8` version of `DirExt`.
@@ -304,6 +330,21 @@ pub trait DirExtUtf8 {
304
330
/// on symlinks to directories on Windows, similar to how `unlink` works
305
331
/// on symlinks to directories on Posix-ish platforms.
306
332
fn remove_file_or_symlink < P : AsRef < Utf8Path > > ( & self , path : P ) -> io:: Result < ( ) > ;
333
+
334
+ /// Test for accessibility or existence of a filesystem object.
335
+ fn access < P : AsRef < Utf8Path > > ( & self , path : P , type_ : AccessType ) -> io:: Result < ( ) > ;
336
+
337
+ /// Test for accessibility or existence of a filesystem object, without
338
+ /// following symbolic links.
339
+ fn access_symlink < P : AsRef < Utf8Path > > ( & self , path : P , type_ : AccessType ) -> io:: Result < ( ) > ;
340
+
341
+ /// Changes the permissions found on a file or a directory, without following
342
+ /// symbolic links.
343
+ fn set_symlink_permissions < P : AsRef < Utf8Path > > (
344
+ & self ,
345
+ path : P ,
346
+ perm : Permissions ,
347
+ ) -> io:: Result < ( ) > ;
307
348
}
308
349
309
350
/// `fs_utf8` version of `DirExt`.
@@ -410,6 +451,25 @@ pub trait AsyncDirExtUtf8 {
410
451
/// points to a directory, it cannot be removed with the `remove_file`
411
452
/// operation. This method will remove files and all symlinks.
412
453
async fn remove_file_or_symlink < P : AsRef < Utf8Path > + Send > ( & self , path : P ) -> io:: Result < ( ) > ;
454
+
455
+ /// Test for accessibility or existence of a filesystem object.
456
+ async fn access < P : AsRef < Utf8Path > > ( & self , path : P , type_ : AccessType ) -> io:: Result < ( ) > ;
457
+
458
+ /// Test for accessibility or existence of a filesystem object, without
459
+ /// following symbolic links.
460
+ async fn access_symlink < P : AsRef < Utf8Path > > (
461
+ & self ,
462
+ path : P ,
463
+ type_ : AccessType ,
464
+ ) -> io:: Result < ( ) > ;
465
+
466
+ /// Changes the permissions found on a file or a directory, without following
467
+ /// symbolic links.
468
+ async fn set_symlink_permissions < P : AsRef < Utf8Path > > (
469
+ & self ,
470
+ path : P ,
471
+ perm : Permissions ,
472
+ ) -> io:: Result < ( ) > ;
413
473
}
414
474
415
475
#[ cfg( feature = "std" ) ]
@@ -533,7 +593,7 @@ impl DirExt for cap_std::fs::Dir {
533
593
#[ cfg( windows) ]
534
594
#[ inline]
535
595
fn remove_file_or_symlink < P : AsRef < Path > > ( & self , path : P ) -> io:: Result < ( ) > {
536
- use crate :: { FollowSymlinks , OpenOptionsFollowExt } ;
596
+ use crate :: OpenOptionsFollowExt ;
537
597
use cap_primitives:: fs:: _WindowsByHandle;
538
598
use cap_std:: fs:: OpenOptions ;
539
599
use std:: os:: windows:: fs:: OpenOptionsExt ;
@@ -566,6 +626,40 @@ impl DirExt for cap_std::fs::Dir {
566
626
567
627
Ok ( ( ) )
568
628
}
629
+
630
+ /// Test for accessibility or existence of a filesystem object.
631
+ fn access < P : AsRef < Path > > ( & self , path : P , type_ : AccessType ) -> io:: Result < ( ) > {
632
+ access (
633
+ & self . as_filelike_view :: < std:: fs:: File > ( ) ,
634
+ path. as_ref ( ) ,
635
+ type_,
636
+ FollowSymlinks :: Yes ,
637
+ )
638
+ }
639
+
640
+ /// Test for accessibility or existence of a filesystem object.
641
+ fn access_symlink < P : AsRef < Path > > ( & self , path : P , type_ : AccessType ) -> io:: Result < ( ) > {
642
+ access (
643
+ & self . as_filelike_view :: < std:: fs:: File > ( ) ,
644
+ path. as_ref ( ) ,
645
+ type_,
646
+ FollowSymlinks :: No ,
647
+ )
648
+ }
649
+
650
+ /// Changes the permissions found on a file or a directory, without following
651
+ /// symbolic links.
652
+ fn set_symlink_permissions < P : AsRef < Path > > (
653
+ & self ,
654
+ path : P ,
655
+ perm : Permissions ,
656
+ ) -> io:: Result < ( ) > {
657
+ set_symlink_permissions (
658
+ & self . as_filelike_view :: < std:: fs:: File > ( ) ,
659
+ path. as_ref ( ) ,
660
+ perm,
661
+ )
662
+ }
569
663
}
570
664
571
665
#[ cfg( feature = "async_std" ) ]
@@ -829,7 +923,7 @@ impl AsyncDirExt for cap_async_std::fs::Dir {
829
923
& self ,
830
924
path : P ,
831
925
) -> io:: Result < ( ) > {
832
- use crate :: { FollowSymlinks , OpenOptionsFollowExt } ;
926
+ use crate :: OpenOptionsFollowExt ;
833
927
use cap_primitives:: fs:: _WindowsByHandle;
834
928
use cap_std:: fs:: OpenOptions ;
835
929
use std:: os:: windows:: fs:: OpenOptionsExt ;
@@ -996,7 +1090,7 @@ impl DirExtUtf8 for cap_std::fs_utf8::Dir {
996
1090
#[ cfg( windows) ]
997
1091
#[ inline]
998
1092
fn remove_file_or_symlink < P : AsRef < Utf8Path > > ( & self , path : P ) -> io:: Result < ( ) > {
999
- use crate :: { FollowSymlinks , OpenOptionsFollowExt } ;
1093
+ use crate :: OpenOptionsFollowExt ;
1000
1094
use cap_primitives:: fs:: _WindowsByHandle;
1001
1095
use cap_std:: fs:: OpenOptions ;
1002
1096
use std:: os:: windows:: fs:: OpenOptionsExt ;
@@ -1029,6 +1123,40 @@ impl DirExtUtf8 for cap_std::fs_utf8::Dir {
1029
1123
1030
1124
Ok ( ( ) )
1031
1125
}
1126
+
1127
+ /// Test for accessibility or existence of a filesystem object.
1128
+ fn access < P : AsRef < Utf8Path > > ( & self , path : P , type_ : AccessType ) -> io:: Result < ( ) > {
1129
+ access (
1130
+ & self . as_filelike_view :: < std:: fs:: File > ( ) ,
1131
+ path. as_ref ( ) . as_ref ( ) ,
1132
+ type_,
1133
+ FollowSymlinks :: Yes ,
1134
+ )
1135
+ }
1136
+
1137
+ /// Test for accessibility or existence of a filesystem object.
1138
+ fn access_symlink < P : AsRef < Utf8Path > > ( & self , path : P , type_ : AccessType ) -> io:: Result < ( ) > {
1139
+ access (
1140
+ & self . as_filelike_view :: < std:: fs:: File > ( ) ,
1141
+ path. as_ref ( ) . as_ref ( ) ,
1142
+ type_,
1143
+ FollowSymlinks :: No ,
1144
+ )
1145
+ }
1146
+
1147
+ /// Changes the permissions found on a file or a directory, without following
1148
+ /// symbolic links.
1149
+ fn set_symlink_permissions < P : AsRef < Utf8Path > > (
1150
+ & self ,
1151
+ path : P ,
1152
+ perm : Permissions ,
1153
+ ) -> io:: Result < ( ) > {
1154
+ set_symlink_permissions (
1155
+ & self . as_filelike_view :: < std:: fs:: File > ( ) ,
1156
+ path. as_ref ( ) . as_ref ( ) ,
1157
+ perm,
1158
+ )
1159
+ }
1032
1160
}
1033
1161
1034
1162
#[ cfg( all( feature = "async_std" , feature = "fs_utf8" ) ) ]
0 commit comments