1
1
use std:: io:: Read ;
2
+ use std:: time:: Duration ;
2
3
use std:: {
3
4
collections:: BTreeMap ,
4
5
path:: { Path , PathBuf } ,
@@ -87,8 +88,8 @@ pub fn scripted_fixture_repo_read_only_with_args(
87
88
script_name : impl AsRef < Path > ,
88
89
args : impl IntoIterator < Item = & ' static str > ,
89
90
) -> Result < PathBuf > {
90
- let script_name = script_name. as_ref ( ) ;
91
- let script_path = fixture_path ( script_name ) ;
91
+ let script_location = script_name. as_ref ( ) ;
92
+ let script_path = fixture_path ( script_location ) ;
92
93
93
94
// keep this lock to assure we don't return unfinished directories for threaded callers
94
95
let args: Vec < String > = args. into_iter ( ) . map ( Into :: into) . collect ( ) ;
@@ -106,7 +107,7 @@ pub fn scripted_fixture_repo_read_only_with_args(
106
107
} )
107
108
. to_owned ( ) ;
108
109
109
- let script_basename = script_name . file_stem ( ) . unwrap_or ( script_name . as_os_str ( ) ) ;
110
+ let script_basename = script_location . file_stem ( ) . unwrap_or ( script_location . as_os_str ( ) ) ;
110
111
let archive_file_path = fixture_path (
111
112
Path :: new ( "generated-archives" )
112
113
. join ( crate_under_test ( ) )
@@ -118,14 +119,19 @@ pub fn scripted_fixture_repo_read_only_with_args(
118
119
. join ( format ! ( "{}" , script_identity) ) ,
119
120
) ;
120
121
122
+ let _marker = git_lock:: Marker :: acquire_to_hold_resource (
123
+ script_basename,
124
+ git_lock:: acquire:: Fail :: AfterDurationWithBackoff ( Duration :: from_secs ( 5 ) ) ,
125
+ None ,
126
+ ) ?;
121
127
if !script_result_directory. is_dir ( ) {
128
+ std:: fs:: create_dir_all ( & script_result_directory) ?;
122
129
match extract_archive ( & archive_file_path, & script_result_directory, script_identity) {
123
130
Ok ( _) => { }
124
131
Err ( err) => {
125
132
if err. kind ( ) != std:: io:: ErrorKind :: NotFound {
126
133
eprintln ! ( "{}" , err) ;
127
134
}
128
- std:: fs:: create_dir_all ( & script_result_directory) ?;
129
135
let script_absolute_path = std:: env:: current_dir ( ) ?. join ( script_path) ;
130
136
let output = std:: process:: Command :: new ( "bash" )
131
137
. arg ( script_absolute_path)
@@ -206,8 +212,6 @@ fn populate_meta_dir(destination_dir: &Path, script_identity: u32) -> std::io::R
206
212
/// `required_script_identity` is the identity of the script that generated the state that is contained in `archive`.
207
213
/// If this is not the case, the arvhive will be ignored.
208
214
fn extract_archive ( archive : & Path , destination_dir : & Path , required_script_identity : u32 ) -> std:: io:: Result < ( ) > {
209
- std:: fs:: create_dir_all ( destination_dir) ?;
210
-
211
215
let mut archive_buf = Vec :: < u8 > :: new ( ) ;
212
216
let mut decoder = xz2:: bufread:: XzDecoder :: new ( std:: io:: BufReader :: new ( std:: fs:: File :: open ( archive) ?) ) ;
213
217
std:: io:: copy ( & mut decoder, & mut archive_buf) ?;
0 commit comments