1
1
use std:: {
2
2
collections:: { BTreeMap , BTreeSet } ,
3
3
fmt:: Debug ,
4
- fs:: { self , rename } ,
5
- path:: { Path , PathBuf } ,
4
+ fs,
5
+ path:: PathBuf ,
6
6
process:: Command ,
7
7
time:: { Duration , SystemTime , UNIX_EPOCH } ,
8
8
} ;
@@ -13,7 +13,12 @@ use mktemp::Temp;
13
13
use serde:: Serialize ;
14
14
use tracing:: { error, info, trace, warn} ;
15
15
16
- use crate :: { data:: get_runner_data_path, github:: ApiRunner , libvirt:: libvirt_prefix, shell:: SHELL } ;
16
+ use crate :: {
17
+ data:: get_runner_data_path,
18
+ github:: ApiRunner ,
19
+ libvirt:: { libvirt_prefix, update_screenshot} ,
20
+ shell:: SHELL ,
21
+ } ;
17
22
18
23
#[ derive( Debug , Serialize ) ]
19
24
pub struct Runners {
@@ -194,38 +199,23 @@ impl Runners {
194
199
}
195
200
}
196
201
197
- pub fn update_runner_screenshots ( & self ) {
202
+ pub fn update_screenshots ( & self ) {
198
203
for & id in self . runners . keys ( ) {
199
- if let Err ( error) = self . update_runner_screenshot ( id) {
204
+ if let Err ( error) = self . update_screenshot ( id) {
200
205
error ! ( id, ?error, "Failed to update screenshot for runner" ) ;
201
206
}
202
207
}
203
208
}
204
209
205
- fn update_runner_screenshot ( & self , id : usize ) -> eyre:: Result < ( ) > {
210
+ fn update_screenshot ( & self , id : usize ) -> eyre:: Result < ( ) > {
206
211
let Some ( runner) = self . runners . get ( & id) else {
207
212
bail ! ( "No runner with id exists: {id}" ) ;
208
213
} ;
209
214
let Some ( guest_name) = runner. guest_name . as_deref ( ) else {
210
215
bail ! ( "Tried to screenshot a runner with no libvirt guest: {id}" ) ;
211
216
} ;
212
- let new_path = get_runner_data_path ( id, "screenshot.png.new" ) ?;
213
- let exit_status = SHELL
214
- . lock ( )
215
- . map_err ( |e| eyre ! ( "Mutex poisoned: {e:?}" ) ) ?
216
- . run (
217
- include_str ! ( "screenshot-guest.sh" ) ,
218
- [ Path :: new ( guest_name) , & new_path] ,
219
- ) ?
220
- . spawn ( ) ?
221
- . wait ( ) ?;
222
- if !exit_status. success ( ) {
223
- eyre:: bail!( "Command exited with status {}" , exit_status) ;
224
- }
225
-
226
- // Update the runner’s screenshot.png atomically
227
- let path = get_runner_data_path ( id, "screenshot.png" ) ?;
228
- rename ( new_path, path) ?;
217
+ let output_dir = get_runner_data_path ( id, "." ) ?;
218
+ update_screenshot ( guest_name, & output_dir) ?;
229
219
230
220
Ok ( ( ) )
231
221
}
0 commit comments