@@ -5,13 +5,13 @@ use git_hash::oid;
5
5
use git_object:: bstr:: ByteSlice ;
6
6
use quick_error:: quick_error;
7
7
use 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 ;
10
10
use std:: path:: { Path , PathBuf } ;
11
11
use std:: time:: Duration ;
12
12
13
13
#[ cfg( unix) ]
14
- use std:: os:: unix:: fs:: PermissionsExt ;
14
+ use std:: os:: unix:: fs:: OpenOptionsExt ;
15
15
16
16
quick_error ! {
17
17
#[ derive( Debug ) ]
@@ -57,12 +57,15 @@ where
57
57
match entry. mode {
58
58
git_index:: entry:: Mode :: FILE | git_index:: entry:: Mode :: FILE_EXECUTABLE => {
59
59
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) ]
61
63
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 ) ;
64
65
}
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 ( ) ?;
66
69
let ctime = met
67
70
. created ( )
68
71
. map_or ( Ok ( Duration :: from_secs ( 0 ) ) , |x| x. duration_since ( std:: time:: UNIX_EPOCH ) ) ;
0 commit comments