@@ -65,6 +65,10 @@ enum ContainerOpts {
65
65
66
66
/// Image reference, e.g. registry:quay.io/exampleos/exampleos:latest
67
67
imgref : String ,
68
+
69
+ /// Create an ostree ref pointing to the imported commit
70
+ #[ structopt( long) ]
71
+ write_ref : Option < String > ,
68
72
} ,
69
73
70
74
/// Print information about an exported ostree-container image.
@@ -139,7 +143,7 @@ fn tar_export(opts: &ExportOpts) -> Result<()> {
139
143
}
140
144
141
145
/// Import a container image with an encapsulated ostree commit.
142
- async fn container_import ( repo : & str , imgref : & str ) -> Result < ( ) > {
146
+ async fn container_import ( repo : & str , imgref : & str , write_ref : Option < & str > ) -> Result < ( ) > {
143
147
let repo = & ostree:: Repo :: open_at ( libc:: AT_FDCWD , repo, gio:: NONE_CANCELLABLE ) ?;
144
148
let imgref = imgref. try_into ( ) ?;
145
149
let ( tx_progress, rx_progress) = tokio:: sync:: watch:: channel ( Default :: default ( ) ) ;
@@ -153,19 +157,32 @@ async fn container_import(repo: &str, imgref: &str) -> Result<()> {
153
157
let import = crate :: container:: import ( repo, & imgref, Some ( tx_progress) ) ;
154
158
tokio:: pin!( import) ;
155
159
tokio:: pin!( rx_progress) ;
156
- loop {
160
+ let import = loop {
157
161
tokio:: select! {
158
162
_ = rx_progress. changed( ) => {
159
163
let n = rx_progress. borrow( ) . processed_bytes;
160
164
pb. set_message( & format!( "Processed: {}" , indicatif:: HumanBytes ( n) ) ) ;
161
165
}
162
166
import = & mut import => {
163
167
pb. finish( ) ;
164
- println!( "Imported: {}" , import?. ostree_commit) ;
165
- return Ok ( ( ) )
168
+ break import?;
166
169
}
167
170
}
171
+ } ;
172
+
173
+ if let Some ( write_ref) = write_ref {
174
+ repo. set_ref_immediate (
175
+ None ,
176
+ write_ref,
177
+ Some ( import. ostree_commit . as_str ( ) ) ,
178
+ gio:: NONE_CANCELLABLE ,
179
+ ) ?;
180
+ println ! ( "Imported: {} => {}" , write_ref, import. ostree_commit. as_str( ) ) ;
181
+ } else {
182
+ println ! ( "Imported: {}" , import. ostree_commit) ;
168
183
}
184
+
185
+ Ok ( ( ) )
169
186
}
170
187
171
188
/// Export a container image with an encapsulated ostree commit.
@@ -216,8 +233,8 @@ where
216
233
Opt :: Tar ( TarOpts :: Import ( ref opt) ) => tar_import ( opt) . await ,
217
234
Opt :: Tar ( TarOpts :: Export ( ref opt) ) => tar_export ( opt) ,
218
235
Opt :: Container ( ContainerOpts :: Info { imgref } ) => container_info ( imgref. as_str ( ) ) . await ,
219
- Opt :: Container ( ContainerOpts :: Import { repo, imgref } ) => {
220
- container_import ( & repo, & imgref) . await
236
+ Opt :: Container ( ContainerOpts :: Import { repo, imgref, write_ref } ) => {
237
+ container_import ( & repo, & imgref, write_ref . as_deref ( ) ) . await
221
238
}
222
239
Opt :: Container ( ContainerOpts :: Export { repo, rev, imgref } ) => {
223
240
container_export ( & repo, & rev, & imgref) . await
0 commit comments