@@ -8,7 +8,6 @@ use anyhow::{anyhow, Context, Result};
88use cap_std_ext:: prelude:: CapStdExtCommandExt ;
99use cap_std_ext:: { cap_std, cap_tempfile} ;
1010use futures_util:: Future ;
11- use once_cell:: sync:: Lazy ;
1211use serde:: { Deserialize , Serialize } ;
1312use std:: fs:: File ;
1413use std:: ops:: Range ;
@@ -17,7 +16,7 @@ use std::os::unix::prelude::CommandExt;
1716use std:: path:: PathBuf ;
1817use std:: pin:: Pin ;
1918use std:: process:: { Command , Stdio } ;
20- use std:: sync:: { Arc , Mutex } ;
19+ use std:: sync:: { Arc , Mutex , OnceLock } ;
2120use tokio:: io:: { AsyncBufRead , AsyncReadExt } ;
2221use tokio:: sync:: Mutex as AsyncMutex ;
2322use tokio:: task:: JoinError ;
@@ -38,11 +37,16 @@ pub const RESERVED_FD_RANGE: Range<i32> = 100..200;
3837// Note that payload data (non-metadata) should go over a pipe file descriptor.
3938const MAX_MSG_SIZE : usize = 32 * 1024 ;
4039
41- // Introduced in https://github.com/containers/skopeo/pull/1523
42- static BASE_PROTO_VERSION : Lazy < semver:: VersionReq > =
43- Lazy :: new ( || semver:: VersionReq :: parse ( "0.2.3" ) . unwrap ( ) ) ;
44- static LAYER_INFO_PROTO_VERSION : Lazy < semver:: VersionReq > =
45- Lazy :: new ( || semver:: VersionReq :: parse ( "0.2.5" ) . unwrap ( ) ) ;
40+ fn base_proto_version ( ) -> & ' static semver:: VersionReq {
41+ // Introduced in https://github.com/containers/skopeo/pull/1523
42+ static BASE_PROTO_VERSION : OnceLock < semver:: VersionReq > = OnceLock :: new ( ) ;
43+ BASE_PROTO_VERSION . get_or_init ( || semver:: VersionReq :: parse ( "0.2.3" ) . unwrap ( ) )
44+ }
45+
46+ fn layer_info_proto_version ( ) -> & ' static semver:: VersionReq {
47+ static LAYER_INFO_PROTO_VERSION : OnceLock < semver:: VersionReq > = OnceLock :: new ( ) ;
48+ LAYER_INFO_PROTO_VERSION . get_or_init ( || semver:: VersionReq :: parse ( "0.2.5" ) . unwrap ( ) )
49+ }
4650
4751#[ derive( Serialize ) ]
4852struct Request {
@@ -279,7 +283,7 @@ impl ImageProxy {
279283 tracing:: debug!( "Remote protocol version: {protover}" ) ;
280284 let protover = semver:: Version :: parse ( protover. as_str ( ) ) ?;
281285 // Previously we had a feature to opt-in to requiring newer versions using `if cfg!()`.
282- let supported = & * BASE_PROTO_VERSION ;
286+ let supported = base_proto_version ( ) ;
283287 if !supported. matches ( & protover) {
284288 return Err ( anyhow ! (
285289 "Unsupported protocol version {} (compatible: {})" ,
@@ -500,7 +504,7 @@ impl ImageProxy {
500504 img : & OpenedImage ,
501505 ) -> Result < Option < Vec < ConvertedLayerInfo > > > {
502506 tracing:: debug!( "Getting layer info" ) ;
503- if !LAYER_INFO_PROTO_VERSION . matches ( & self . protover ) {
507+ if !layer_info_proto_version ( ) . matches ( & self . protover ) {
504508 return Ok ( None ) ;
505509 }
506510 let reply = self . impl_request ( "GetLayerInfo" , [ img. 0 ] ) . await ?;
0 commit comments