1
1
use std:: {
2
+ ffi:: OsString ,
2
3
fs:: create_dir_all,
3
4
path:: { Path , PathBuf } ,
4
5
sync:: Arc ,
@@ -12,7 +13,7 @@ use rustix::fs::CWD;
12
13
use composefs_boot:: { write_boot, BootOps } ;
13
14
14
15
use composefs:: {
15
- fsverity:: { FsVerityHashValue , Sha256HashValue } ,
16
+ fsverity:: { FsVerityHashValue , Sha512HashValue } ,
16
17
repository:: Repository ,
17
18
} ;
18
19
@@ -37,7 +38,6 @@ pub struct App {
37
38
cmd : Command ,
38
39
}
39
40
40
- #[ cfg( feature = "oci" ) ]
41
41
#[ derive( Debug , Subcommand ) ]
42
42
enum OciCommand {
43
43
/// Stores a tar file as a splitstream in the repository.
@@ -109,7 +109,6 @@ enum Command {
109
109
reference : String ,
110
110
} ,
111
111
/// Commands for dealing with OCI layers
112
- #[ cfg( feature = "oci" ) ]
113
112
Oci {
114
113
#[ clap( subcommand) ]
115
114
cmd : OciCommand ,
@@ -146,39 +145,39 @@ enum Command {
146
145
ImageObjects {
147
146
name : String ,
148
147
} ,
149
- #[ cfg( feature = "http" ) ]
150
- Fetch {
151
- url : String ,
152
- name : String ,
153
- } ,
154
148
}
155
149
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 ( ) ? )
161
155
}
162
156
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
+ ) ;
166
165
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)
173
170
} 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 )
177
174
} 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;
182
181
183
182
match args. cmd {
184
183
Command :: Transaction => {
@@ -194,11 +193,10 @@ async fn main() -> Result<()> {
194
193
let image_id = repo. import_image ( & reference, & mut std:: io:: stdin ( ) ) ?;
195
194
println ! ( "{}" , image_id. to_id( ) ) ;
196
195
}
197
- #[ cfg( feature = "oci" ) ]
198
196
Command :: Oci { cmd : oci_cmd } => match oci_cmd {
199
197
OciCommand :: ImportLayer { name, sha256 } => {
200
198
let object_id = composefs_oci:: import_layer (
201
- & Arc :: new ( repo) ,
199
+ & repo,
202
200
& composefs:: util:: parse_sha256 ( sha256) ?,
203
201
name. as_deref ( ) ,
204
202
& mut std:: io:: stdin ( ) ,
@@ -247,8 +245,7 @@ async fn main() -> Result<()> {
247
245
println ! ( "{}" , image_id. to_id( ) ) ;
248
246
}
249
247
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 ?;
252
249
253
250
println ! ( "sha256 {}" , hex:: encode( sha256) ) ;
254
251
println ! ( "verity {}" , verity. to_hex( ) ) ;
@@ -258,8 +255,7 @@ async fn main() -> Result<()> {
258
255
ref config_verity,
259
256
} => {
260
257
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 ( ) ) ?;
263
259
println ! ( "sha256 {}" , hex:: encode( sha256) ) ;
264
260
println ! ( "verity {}" , verity. to_id( ) ) ;
265
261
}
@@ -301,7 +297,7 @@ async fn main() -> Result<()> {
301
297
let state = args
302
298
. repo
303
299
. as_ref ( )
304
- . map ( |p : & PathBuf | p. parent ( ) . unwrap ( ) )
300
+ . map ( |p : & PathBuf | p. parent ( ) . unwrap_or ( p ) )
305
301
. unwrap_or ( Path :: new ( "/sysroot" ) )
306
302
. join ( "state/deploy" )
307
303
. join ( id. to_hex ( ) ) ;
@@ -359,12 +355,6 @@ async fn main() -> Result<()> {
359
355
Command :: GC => {
360
356
repo. gc ( ) ?;
361
357
}
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
- }
368
358
}
369
359
Ok ( ( ) )
370
360
}
0 commit comments