11#[ cfg( feature = "fs_utf8" ) ]
22use camino:: Utf8Path ;
3+ #[ cfg( all( windows, feature = "async_std" , feature = "fs_utf8" ) ) ]
4+ use cap_primitives:: fs:: stat;
35#[ cfg( not( windows) ) ]
46use 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+ } ;
811#[ cfg( windows) ]
912use cap_primitives:: fs:: { symlink_dir, symlink_file} ;
1013use io_lifetimes:: AsFilelike ;
@@ -13,7 +16,7 @@ use std::path::Path;
1316#[ cfg( feature = "async_std" ) ]
1417use { async_std:: task:: spawn_blocking, async_trait:: async_trait} ;
1518
16- pub use cap_primitives:: fs:: SystemTimeSpec ;
19+ pub use cap_primitives:: fs:: { AccessType , SystemTimeSpec } ;
1720
1821/// Extension trait for `Dir`.
1922pub trait DirExt {
@@ -95,6 +98,18 @@ pub trait DirExt {
9598 /// points to a directory, it cannot be removed with the `remove_file`
9699 /// operation. This method will remove files and all symlinks.
97100 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 < ( ) > ;
98113}
99114
100115/// Extension trait for `Dir`, async.
@@ -216,6 +231,17 @@ pub trait AsyncDirExt {
216231 & self ,
217232 path : P ,
218233 ) -> 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 < ( ) > ;
219245}
220246
221247/// `fs_utf8` version of `DirExt`.
@@ -304,6 +330,21 @@ pub trait DirExtUtf8 {
304330 /// on symlinks to directories on Windows, similar to how `unlink` works
305331 /// on symlinks to directories on Posix-ish platforms.
306332 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 < ( ) > ;
307348}
308349
309350/// `fs_utf8` version of `DirExt`.
@@ -410,6 +451,25 @@ pub trait AsyncDirExtUtf8 {
410451 /// points to a directory, it cannot be removed with the `remove_file`
411452 /// operation. This method will remove files and all symlinks.
412453 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 < ( ) > ;
413473}
414474
415475#[ cfg( feature = "std" ) ]
@@ -533,7 +593,7 @@ impl DirExt for cap_std::fs::Dir {
533593 #[ cfg( windows) ]
534594 #[ inline]
535595 fn remove_file_or_symlink < P : AsRef < Path > > ( & self , path : P ) -> io:: Result < ( ) > {
536- use crate :: { FollowSymlinks , OpenOptionsFollowExt } ;
596+ use crate :: OpenOptionsFollowExt ;
537597 use cap_primitives:: fs:: _WindowsByHandle;
538598 use cap_std:: fs:: OpenOptions ;
539599 use std:: os:: windows:: fs:: OpenOptionsExt ;
@@ -566,6 +626,40 @@ impl DirExt for cap_std::fs::Dir {
566626
567627 Ok ( ( ) )
568628 }
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+ }
569663}
570664
571665#[ cfg( feature = "async_std" ) ]
@@ -829,7 +923,7 @@ impl AsyncDirExt for cap_async_std::fs::Dir {
829923 & self ,
830924 path : P ,
831925 ) -> io:: Result < ( ) > {
832- use crate :: { FollowSymlinks , OpenOptionsFollowExt } ;
926+ use crate :: OpenOptionsFollowExt ;
833927 use cap_primitives:: fs:: _WindowsByHandle;
834928 use cap_std:: fs:: OpenOptions ;
835929 use std:: os:: windows:: fs:: OpenOptionsExt ;
@@ -996,7 +1090,7 @@ impl DirExtUtf8 for cap_std::fs_utf8::Dir {
9961090 #[ cfg( windows) ]
9971091 #[ inline]
9981092 fn remove_file_or_symlink < P : AsRef < Utf8Path > > ( & self , path : P ) -> io:: Result < ( ) > {
999- use crate :: { FollowSymlinks , OpenOptionsFollowExt } ;
1093+ use crate :: OpenOptionsFollowExt ;
10001094 use cap_primitives:: fs:: _WindowsByHandle;
10011095 use cap_std:: fs:: OpenOptions ;
10021096 use std:: os:: windows:: fs:: OpenOptionsExt ;
@@ -1029,6 +1123,40 @@ impl DirExtUtf8 for cap_std::fs_utf8::Dir {
10291123
10301124 Ok ( ( ) )
10311125 }
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+ }
10321160}
10331161
10341162#[ cfg( all( feature = "async_std" , feature = "fs_utf8" ) ) ]
0 commit comments