@@ -22,7 +22,13 @@ pub(crate) enum Mode {
22
22
23
23
/// Utilities
24
24
impl 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 > {
26
32
let tempfile = {
27
33
let mut builder = tempfile:: Builder :: new ( ) ;
28
34
let dot_ext_storage;
@@ -34,6 +40,9 @@ impl Handle<()> {
34
40
dot_ext_storage = format ! ( ".{}" , ext. to_string_lossy( ) ) ;
35
41
builder. suffix ( & dot_ext_storage) ;
36
42
}
43
+ if let Some ( permissions) = permissions {
44
+ builder. permissions ( permissions) ;
45
+ }
37
46
let parent_dir = path. parent ( ) . expect ( "parent directory is present" ) ;
38
47
let parent_dir = directory. resolve ( parent_dir) ?;
39
48
ForksafeTempfile :: new ( builder. rand_bytes ( 0 ) . tempfile_in ( parent_dir) ?, cleanup, mode)
@@ -76,7 +85,20 @@ impl Handle<Closed> {
76
85
/// signal is encountered as destructors won't run. See [the top-level documentation](crate) for more.
77
86
pub fn at ( path : impl AsRef < Path > , directory : ContainingDirectory , cleanup : AutoRemove ) -> io:: Result < Self > {
78
87
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) ) ?,
80
102
_marker : Default :: default ( ) ,
81
103
} )
82
104
}
@@ -104,7 +126,20 @@ impl Handle<Writable> {
104
126
/// signal is encountered as destructors won't run. See [the top-level documentation](crate) for more.
105
127
pub fn at ( path : impl AsRef < Path > , directory : ContainingDirectory , cleanup : AutoRemove ) -> io:: Result < Self > {
106
128
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) ) ?,
108
143
_marker : Default :: default ( ) ,
109
144
} )
110
145
}
0 commit comments