@@ -22,7 +22,13 @@ pub(crate) enum Mode {
2222
2323/// Utilities
2424impl Handle < ( ) > {
25- fn at_path ( path : & Path , directory : ContainingDirectory , cleanup : AutoRemove , mode : Mode ) -> io:: Result < usize > {
25+ fn at_path (
26+ path : & Path ,
27+ directory : ContainingDirectory ,
28+ cleanup : AutoRemove ,
29+ mode : Mode ,
30+ permissions : Option < std:: fs:: Permissions > ,
31+ ) -> io:: Result < usize > {
2632 let tempfile = {
2733 let mut builder = tempfile:: Builder :: new ( ) ;
2834 let dot_ext_storage;
@@ -34,6 +40,9 @@ impl Handle<()> {
3440 dot_ext_storage = format ! ( ".{}" , ext. to_string_lossy( ) ) ;
3541 builder. suffix ( & dot_ext_storage) ;
3642 }
43+ if let Some ( permissions) = permissions {
44+ builder. permissions ( permissions) ;
45+ }
3746 let parent_dir = path. parent ( ) . expect ( "parent directory is present" ) ;
3847 let parent_dir = directory. resolve ( parent_dir) ?;
3948 ForksafeTempfile :: new ( builder. rand_bytes ( 0 ) . tempfile_in ( parent_dir) ?, cleanup, mode)
@@ -76,7 +85,20 @@ impl Handle<Closed> {
7685 /// signal is encountered as destructors won't run. See [the top-level documentation](crate) for more.
7786 pub fn at ( path : impl AsRef < Path > , directory : ContainingDirectory , cleanup : AutoRemove ) -> io:: Result < Self > {
7887 Ok ( Handle {
79- id : Handle :: < ( ) > :: at_path ( path. as_ref ( ) , directory, cleanup, Mode :: Closed ) ?,
88+ id : Handle :: < ( ) > :: at_path ( path. as_ref ( ) , directory, cleanup, Mode :: Closed , None ) ?,
89+ _marker : Default :: default ( ) ,
90+ } )
91+ }
92+
93+ /// Like [`at`](Self::at()), but with support for filesystem `permissions`.
94+ pub fn at_with_permissions (
95+ path : impl AsRef < Path > ,
96+ directory : ContainingDirectory ,
97+ cleanup : AutoRemove ,
98+ permissions : std:: fs:: Permissions ,
99+ ) -> io:: Result < Self > {
100+ Ok ( Handle {
101+ id : Handle :: < ( ) > :: at_path ( path. as_ref ( ) , directory, cleanup, Mode :: Closed , Some ( permissions) ) ?,
80102 _marker : Default :: default ( ) ,
81103 } )
82104 }
@@ -104,7 +126,20 @@ impl Handle<Writable> {
104126 /// signal is encountered as destructors won't run. See [the top-level documentation](crate) for more.
105127 pub fn at ( path : impl AsRef < Path > , directory : ContainingDirectory , cleanup : AutoRemove ) -> io:: Result < Self > {
106128 Ok ( Handle {
107- id : Handle :: < ( ) > :: at_path ( path. as_ref ( ) , directory, cleanup, Mode :: Writable ) ?,
129+ id : Handle :: < ( ) > :: at_path ( path. as_ref ( ) , directory, cleanup, Mode :: Writable , None ) ?,
130+ _marker : Default :: default ( ) ,
131+ } )
132+ }
133+
134+ /// Like [`at`](Self::at()), but with support for filesystem `permissions`.
135+ pub fn at_with_permissions (
136+ path : impl AsRef < Path > ,
137+ directory : ContainingDirectory ,
138+ cleanup : AutoRemove ,
139+ permissions : std:: fs:: Permissions ,
140+ ) -> io:: Result < Self > {
141+ Ok ( Handle {
142+ id : Handle :: < ( ) > :: at_path ( path. as_ref ( ) , directory, cleanup, Mode :: Writable , Some ( permissions) ) ?,
108143 _marker : Default :: default ( ) ,
109144 } )
110145 }
0 commit comments