@@ -5,13 +5,13 @@ use git_hash::oid;
55use git_object:: bstr:: ByteSlice ;
66use quick_error:: quick_error;
77use std:: convert:: TryFrom ;
8- use std:: fs;
9- use std:: fs :: create_dir_all ;
8+ use std:: fs:: { create_dir_all , OpenOptions } ;
9+ use std:: io :: Write ;
1010use std:: path:: { Path , PathBuf } ;
1111use std:: time:: Duration ;
1212
1313#[ cfg( unix) ]
14- use std:: os:: unix:: fs:: PermissionsExt ;
14+ use std:: os:: unix:: fs:: OpenOptionsExt ;
1515
1616quick_error ! {
1717 #[ derive( Debug ) ]
@@ -57,12 +57,15 @@ where
5757 match entry. mode {
5858 git_index:: entry:: Mode :: FILE | git_index:: entry:: Mode :: FILE_EXECUTABLE => {
5959 let obj = find ( & entry. id , & mut buf) . ok_or_else ( || Error :: NotFound ( entry. id , path. to_path_buf ( ) ) ) ?;
60- std:: fs:: write ( & dest, obj. data ) ?;
60+ let mut options = OpenOptions :: new ( ) ;
61+ options. write ( true ) . create_new ( true ) ;
62+ #[ cfg( unix) ]
6163 if entry. mode == git_index:: entry:: Mode :: FILE_EXECUTABLE {
62- #[ cfg( unix) ]
63- fs:: set_permissions ( & dest, fs:: Permissions :: from_mode ( 0o777 ) ) ?;
64+ options. mode ( 0o777 ) ;
6465 }
65- let met = std:: fs:: symlink_metadata ( & dest) ?;
66+ let mut file = options. open ( & dest) ?;
67+ file. write_all ( obj. data ) ?;
68+ let met = file. metadata ( ) ?;
6669 let ctime = met
6770 . created ( )
6871 . map_or ( Ok ( Duration :: from_secs ( 0 ) ) , |x| x. duration_since ( std:: time:: UNIX_EPOCH ) ) ;
0 commit comments