11use std:: {
2+ ffi:: OsString ,
23 fs:: create_dir_all,
34 path:: { Path , PathBuf } ,
45 sync:: Arc ,
@@ -12,7 +13,7 @@ use rustix::fs::CWD;
1213use composefs_boot:: { write_boot, BootOps } ;
1314
1415use composefs:: {
15- fsverity:: { FsVerityHashValue , Sha256HashValue } ,
16+ fsverity:: { FsVerityHashValue , Sha512HashValue } ,
1617 repository:: Repository ,
1718} ;
1819
@@ -37,7 +38,6 @@ pub struct App {
3738 cmd : Command ,
3839}
3940
40- #[ cfg( feature = "oci" ) ]
4141#[ derive( Debug , Subcommand ) ]
4242enum OciCommand {
4343 /// Stores a tar file as a splitstream in the repository.
@@ -109,7 +109,6 @@ enum Command {
109109 reference : String ,
110110 } ,
111111 /// Commands for dealing with OCI layers
112- #[ cfg( feature = "oci" ) ]
113112 Oci {
114113 #[ clap( subcommand) ]
115114 cmd : OciCommand ,
@@ -146,39 +145,39 @@ enum Command {
146145 ImageObjects {
147146 name : String ,
148147 } ,
149- #[ cfg( feature = "http" ) ]
150- Fetch {
151- url : String ,
152- name : String ,
153- } ,
154148}
155149
156- fn verity_opt ( opt : & Option < String > ) -> Result < Option < Sha256HashValue > > {
157- Ok ( match opt {
158- Some ( value ) => Some ( FsVerityHashValue :: from_hex ( value ) ? ) ,
159- None => None ,
160- } )
150+ fn verity_opt ( opt : & Option < String > ) -> Result < Option < Sha512HashValue > > {
151+ Ok ( opt
152+ . as_ref ( )
153+ . map ( |value| FsVerityHashValue :: from_hex ( value ) )
154+ . transpose ( ) ? )
161155}
162156
163- #[ tokio:: main]
164- async fn main ( ) -> Result < ( ) > {
165- env_logger:: init ( ) ;
157+ pub ( crate ) async fn run_from_iter < I > ( system_store : & crate :: store:: Storage , args : I ) -> Result < ( ) >
158+ where
159+ I : IntoIterator ,
160+ I :: Item : Into < OsString > + Clone ,
161+ {
162+ let args = App :: parse_from (
163+ std:: iter:: once ( OsString :: from ( "cfs" ) ) . chain ( args. into_iter ( ) . map ( Into :: into) ) ,
164+ ) ;
166165
167- let args = App :: parse ( ) ;
168-
169- let mut repo: Repository < Sha256HashValue > = ( if let Some ( path) = & args. repo {
170- Repository :: open_path ( CWD , path)
171- } else if args. system {
172- Repository :: open_system ( )
166+ let repo = if let Some ( path) = & args. repo {
167+ let mut r = Repository :: open_path ( CWD , path) ?;
168+ r. set_insecure ( args. insecure ) ;
169+ Arc :: new ( r)
173170 } else if args. user {
174- Repository :: open_user ( )
175- } else if rustix :: process :: getuid ( ) . is_root ( ) {
176- Repository :: open_system ( )
171+ let mut r = Repository :: open_user ( ) ? ;
172+ r . set_insecure ( args . insecure ) ;
173+ Arc :: new ( r )
177174 } else {
178- Repository :: open_user ( )
179- } ) ?;
180-
181- repo. set_insecure ( args. insecure ) ;
175+ if args. insecure {
176+ anyhow:: bail!( "Cannot override insecure state for system repo" ) ;
177+ }
178+ system_store. get_ensure_composefs ( ) ?
179+ } ;
180+ let repo = & repo;
182181
183182 match args. cmd {
184183 Command :: Transaction => {
@@ -194,11 +193,10 @@ async fn main() -> Result<()> {
194193 let image_id = repo. import_image ( & reference, & mut std:: io:: stdin ( ) ) ?;
195194 println ! ( "{}" , image_id. to_id( ) ) ;
196195 }
197- #[ cfg( feature = "oci" ) ]
198196 Command :: Oci { cmd : oci_cmd } => match oci_cmd {
199197 OciCommand :: ImportLayer { name, sha256 } => {
200198 let object_id = composefs_oci:: import_layer (
201- & Arc :: new ( repo) ,
199+ & repo,
202200 & composefs:: util:: parse_sha256 ( sha256) ?,
203201 name. as_deref ( ) ,
204202 & mut std:: io:: stdin ( ) ,
@@ -247,8 +245,7 @@ async fn main() -> Result<()> {
247245 println ! ( "{}" , image_id. to_id( ) ) ;
248246 }
249247 OciCommand :: Pull { ref image, name } => {
250- let ( sha256, verity) =
251- composefs_oci:: pull ( & Arc :: new ( repo) , image, name. as_deref ( ) ) . await ?;
248+ let ( sha256, verity) = composefs_oci:: pull ( & repo, image, name. as_deref ( ) ) . await ?;
252249
253250 println ! ( "sha256 {}" , hex:: encode( sha256) ) ;
254251 println ! ( "verity {}" , verity. to_hex( ) ) ;
@@ -258,8 +255,7 @@ async fn main() -> Result<()> {
258255 ref config_verity,
259256 } => {
260257 let verity = verity_opt ( config_verity) ?;
261- let ( sha256, verity) =
262- composefs_oci:: seal ( & Arc :: new ( repo) , config_name, verity. as_ref ( ) ) ?;
258+ let ( sha256, verity) = composefs_oci:: seal ( & repo, config_name, verity. as_ref ( ) ) ?;
263259 println ! ( "sha256 {}" , hex:: encode( sha256) ) ;
264260 println ! ( "verity {}" , verity. to_id( ) ) ;
265261 }
@@ -301,7 +297,7 @@ async fn main() -> Result<()> {
301297 let state = args
302298 . repo
303299 . as_ref ( )
304- . map ( |p : & PathBuf | p. parent ( ) . unwrap ( ) )
300+ . map ( |p : & PathBuf | p. parent ( ) . unwrap_or ( p ) )
305301 . unwrap_or ( Path :: new ( "/sysroot" ) )
306302 . join ( "state/deploy" )
307303 . join ( id. to_hex ( ) ) ;
@@ -359,12 +355,6 @@ async fn main() -> Result<()> {
359355 Command :: GC => {
360356 repo. gc ( ) ?;
361357 }
362- #[ cfg( feature = "http" ) ]
363- Command :: Fetch { url, name } => {
364- let ( sha256, verity) = composefs_http:: download ( & url, & name, Arc :: new ( repo) ) . await ?;
365- println ! ( "sha256 {}" , hex:: encode( sha256) ) ;
366- println ! ( "verity {}" , verity. to_hex( ) ) ;
367- }
368358 }
369359 Ok ( ( ) )
370360}
0 commit comments