File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ use helix_stdx:: faccess:: write_with_perms;
12use std:: { collections:: HashSet , fs, path:: PathBuf } ;
23
34use crate :: { data_dir, workspace_exclude_file, workspace_trust_file} ;
@@ -71,8 +72,7 @@ impl WorkspaceTrust {
7172 log:: error!( "Couldn't create helix's data directory: {:?}" , e) ;
7273 } ;
7374 }
74- // TO-DO: ensure only owner has write permission
75- if let Err ( e) = fs:: write ( workspace_trust_file ( ) , trust_text) {
75+ if let Err ( e) = write_with_perms ( workspace_trust_file ( ) , trust_text, 0o0644 ) {
7676 log:: error!( "Error during write of workspace_trust file: {:?}" , e) ;
7777 }
7878 }
@@ -93,8 +93,7 @@ impl WorkspaceTrust {
9393 log:: error!( "Couldn't create helix's data directory: {:?}" , e) ;
9494 } ;
9595 }
96- // TO-DO: ensure only owner has write permission
97- if let Err ( e) = fs:: write ( workspace_exclude_file ( ) , trust_text) {
96+ if let Err ( e) = write_with_perms ( workspace_exclude_file ( ) , trust_text, 0o0644 ) {
9897 log:: error!( "Error during write of workspace_trust file: {:?}" , e) ;
9998 }
10099 } else {
Original file line number Diff line number Diff line change 1- //! Functions for managine file metadata.
1+ //! Functions for managing file metadata.
22//! From <https://github.com/Freaky/faccess>
33
44use std:: io;
@@ -95,6 +95,24 @@ mod imp {
9595 Ok ( ( ) )
9696 }
9797
98+ /// Same as [`fs::write`][std::fs::write], but sets mode bits on Unix targets
99+ pub fn write_with_perms < P : AsRef < Path > , C : AsRef < [ u8 ] > > (
100+ path : P ,
101+ contents : C ,
102+ perms : u16 ,
103+ ) -> io:: Result < ( ) > {
104+ fn inner ( path : & Path , contents : & [ u8 ] , perms : u16 ) -> io:: Result < ( ) > {
105+ let f = std:: fs:: File :: create ( path) ?;
106+ #[ cfg( target_family = "unix" ) ]
107+ {
108+ let p = f. metadata ( ) ?. permissions ( ) . set_mode ( perms) ;
109+ std:: fs:: set_permissions ( f, p) ?
110+ }
111+ f. write_all ( contents)
112+ }
113+ inner ( path. as_ref ( ) , contents. as_ref ( ) , perms)
114+ }
115+
98116 pub fn hardlink_count ( p : & Path ) -> std:: io:: Result < u64 > {
99117 let metadata = p. metadata ( ) ?;
100118 Ok ( metadata. nlink ( ) )
You can’t perform that action at this time.
0 commit comments