File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,15 @@ pub fn metadata<P: AsRef<Path>>(path: P) -> Result<fs::Metadata> {
5353 fs:: metadata ( path) . map_err ( |source| Error :: new ( source, path) )
5454}
5555
56+ pub use fs:: Permissions ;
57+
58+ /// A wrapper around std::fs::set_permissions
59+ pub fn set_permissions < P : AsRef < Path > > ( path : P , permissions : Permissions ) -> Result < ( ) > {
60+ let path = path. as_ref ( ) ;
61+
62+ fs:: set_permissions ( path, permissions) . map_err ( |source| Error :: new ( source, path) )
63+ }
64+
5665/// A wrapper around std::fs::File that contains file path information in error
5766/// cases.
5867#[ derive( Debug ) ]
Original file line number Diff line number Diff line change @@ -117,9 +117,20 @@ impl ToolCache {
117117 let exe_name = tool_identifier_to_exe_name ( source, & version) ;
118118 tool_path. push ( exe_name) ;
119119
120- let mut output = BufWriter :: new ( File :: create ( tool_path) . unwrap ( ) ) ;
120+ let mut output = BufWriter :: new ( File :: create ( & tool_path) . unwrap ( ) ) ;
121121 io:: copy ( & mut file, & mut output) . unwrap ( ) ;
122122
123+ // On Unix systems, we need to preserve permissions from the archive
124+ // like executability.
125+ #[ cfg( unix) ]
126+ {
127+ use std:: os:: unix:: fs:: PermissionsExt ;
128+
129+ if let Some ( mode) = file. unix_mode ( ) {
130+ fs:: set_permissions ( & tool_path, fs:: Permissions :: from_mode ( mode) ) . unwrap ( ) ;
131+ }
132+ }
133+
123134 log:: trace!( "Updating tool cache" ) ;
124135 let mut cache = Self :: load ( ) . unwrap ( ) ;
125136 let tool = cache. tools . entry ( source. to_owned ( ) ) . or_default ( ) ;
You can’t perform that action at this time.
0 commit comments