@@ -60,6 +60,8 @@ impl File {
60
60
/// If `boundary_directory` is given, non-existing directories will be created automatically and removed in the case of
61
61
/// a rollback. Otherwise the containing directory is expected to exist, even though the resource doesn't have to.
62
62
///
63
+ /// Note that permissions will be set to `0o666`, which usually results in `0o644` after passing a default umask, on Unix systems.
64
+ ///
63
65
/// ### Warning of potential resource leak
64
66
///
65
67
/// Please note that the underlying file will remain if destructors don't run, as is the case when interrupting the application.
@@ -71,7 +73,11 @@ impl File {
71
73
boundary_directory : Option < PathBuf > ,
72
74
) -> Result < File , Error > {
73
75
let ( lock_path, handle) = lock_with_mode ( at_path. as_ref ( ) , mode, boundary_directory, & |p, d, c| {
74
- gix_tempfile:: writable_at ( p, d, c)
76
+ if let Some ( permissions) = default_permissions ( ) {
77
+ gix_tempfile:: writable_at_with_permissions ( p, d, c, permissions)
78
+ } else {
79
+ gix_tempfile:: writable_at ( p, d, c)
80
+ }
75
81
} ) ?;
76
82
Ok ( File {
77
83
inner : handle,
@@ -87,6 +93,8 @@ impl Marker {
87
93
/// If `boundary_directory` is given, non-existing directories will be created automatically and removed in the case of
88
94
/// a rollback.
89
95
///
96
+ /// Note that permissions will be set to `0o666`, which usually results in `0o644` after passing a default umask, on Unix systems.
97
+ ///
90
98
/// ### Warning of potential resource leak
91
99
///
92
100
/// Please note that the underlying file will remain if destructors don't run, as is the case when interrupting the application.
@@ -98,7 +106,11 @@ impl Marker {
98
106
boundary_directory : Option < PathBuf > ,
99
107
) -> Result < Marker , Error > {
100
108
let ( lock_path, handle) = lock_with_mode ( at_path. as_ref ( ) , mode, boundary_directory, & |p, d, c| {
101
- gix_tempfile:: mark_at ( p, d, c)
109
+ if let Some ( permissions) = default_permissions ( ) {
110
+ gix_tempfile:: mark_at_with_permissions ( p, d, c, permissions)
111
+ } else {
112
+ gix_tempfile:: mark_at ( p, d, c)
113
+ }
102
114
} ) ?;
103
115
Ok ( Marker {
104
116
created_from_file : false ,
@@ -169,6 +181,18 @@ fn add_lock_suffix(resource_path: &Path) -> PathBuf {
169
181
) )
170
182
}
171
183
184
+ fn default_permissions ( ) -> Option < std:: fs:: Permissions > {
185
+ #[ cfg( unix) ]
186
+ {
187
+ use std:: os:: unix:: fs:: PermissionsExt ;
188
+ Some ( std:: fs:: Permissions :: from_mode ( 0o666 ) )
189
+ }
190
+ #[ cfg( not( unix) ) ]
191
+ {
192
+ None
193
+ }
194
+ }
195
+
172
196
#[ cfg( test) ]
173
197
mod tests {
174
198
use super :: * ;
0 commit comments