@@ -27,7 +27,7 @@ use tracing::warn;
27
27
) ]
28
28
pub struct AptCli {
29
29
#[ command( flatten) ]
30
- common : CommonArgs ,
30
+ pub common : CommonArgs ,
31
31
32
32
#[ clap( subcommand) ]
33
33
operation : PluginOp ,
@@ -88,7 +88,7 @@ struct SoftwareModuleUpdate {
88
88
pub path : Option < String > ,
89
89
}
90
90
91
- fn run_op ( apt : AptCli ) -> Result < ExitStatus , InternalError > {
91
+ fn run_op ( apt : AptCli , tedge_config : Option < TEdgeConfig > ) -> Result < ExitStatus , InternalError > {
92
92
if let Err ( err) = log_init (
93
93
"tedge-apt-plugin" ,
94
94
& apt. common . log_args ,
@@ -147,7 +147,7 @@ fn run_op(apt: AptCli) -> Result<ExitStatus, InternalError> {
147
147
file_path,
148
148
} => {
149
149
let ( installer, _metadata) = get_installer ( module, version, file_path) ?;
150
- let dpk_option = get_dpk_option ( apt . common . config_dir . as_std_path ( ) ) ;
150
+ let dpk_option = get_dpk_option ( & tedge_config ) ;
151
151
AptGetCmd :: Install ( dpk_option, vec ! [ installer] ) . run ( ) ?
152
152
}
153
153
@@ -173,7 +173,7 @@ fn run_op(apt: AptCli) -> Result<ExitStatus, InternalError> {
173
173
// which will get cleaned up once it goes out of scope after this block
174
174
let mut metadata_vec = Vec :: new ( ) ;
175
175
let mut args: Vec < String > = Vec :: new ( ) ;
176
- let dpk_option = get_dpk_option ( apt . common . config_dir . as_std_path ( ) ) ;
176
+ let dpk_option = get_dpk_option ( & tedge_config ) ;
177
177
178
178
for update_module in updates {
179
179
match update_module. action {
@@ -319,8 +319,8 @@ impl AptGetCmd {
319
319
}
320
320
}
321
321
322
- fn get_dpk_option ( config_dir : & Path ) -> AptConfig {
323
- match get_config ( config_dir ) {
322
+ fn get_dpk_option ( tedge_config : & Option < TEdgeConfig > ) -> AptConfig {
323
+ match tedge_config {
324
324
None => AptConfig :: KeepNew ,
325
325
Some ( config) => config. apt . dpk . options . config . clone ( ) ,
326
326
}
@@ -334,10 +334,10 @@ fn get_name_and_version(line: &str) -> (&str, &str) {
334
334
( name, version)
335
335
}
336
336
337
- fn get_config ( config_dir : & Path ) -> Option < TEdgeConfig > {
337
+ pub async fn get_config ( config_dir : & Path ) -> Option < TEdgeConfig > {
338
338
let tedge_config_location = TEdgeConfigLocation :: from_custom_root ( config_dir) ;
339
339
340
- match TEdgeConfig :: try_new_sync ( tedge_config_location) {
340
+ match TEdgeConfig :: try_new ( tedge_config_location) . await {
341
341
Ok ( config) => Some ( config) ,
342
342
Err ( err) => {
343
343
warn ! ( "Failed to load TEdgeConfig: {}" , err) ;
@@ -346,9 +346,9 @@ fn get_config(config_dir: &Path) -> Option<TEdgeConfig> {
346
346
}
347
347
}
348
348
349
- pub fn run_and_exit ( mut apt : AptCli ) -> ! {
349
+ pub fn run_and_exit ( mut apt : AptCli , tedge_config : Option < TEdgeConfig > ) -> ! {
350
350
if let PluginOp :: List { name, maintainer } = & mut apt. operation {
351
- if let Some ( config) = get_config ( apt . common . config_dir . as_std_path ( ) ) {
351
+ if let Some ( config) = & tedge_config {
352
352
if name. is_none ( ) {
353
353
* name = config. apt . name . or_none ( ) . cloned ( ) ;
354
354
}
@@ -359,7 +359,7 @@ pub fn run_and_exit(mut apt: AptCli) -> ! {
359
359
}
360
360
}
361
361
362
- match run_op ( apt) {
362
+ match run_op ( apt, tedge_config ) {
363
363
Ok ( status) if status. success ( ) => {
364
364
std:: process:: exit ( 0 ) ;
365
365
}
@@ -414,6 +414,6 @@ mod tests {
414
414
config_dir : "" . into ( ) ,
415
415
} ,
416
416
} ;
417
- assert ! ( run_op( apt) . is_ok( ) )
417
+ assert ! ( run_op( apt, None ) . is_ok( ) )
418
418
}
419
419
}
0 commit comments