@@ -101,13 +101,15 @@ impl Index {
101101 /// than the currently installed version*. This is useful to check if an update exists for the
102102 /// given target and variant without filtering on file type, e.g. in the case of Linux desktop
103103 /// bundles.
104+ #[ allow( clippy:: too_many_arguments) ]
104105 pub fn find_next_version (
105106 & self ,
106107 target_triple : & TargetTriple ,
107108 variant : & Variant ,
108109 file_type : Option < & FileType > ,
109110 current_version : & str ,
110111 ignore_rollout : bool ,
112+ is_auto_update : bool ,
111113 threshold_override : Option < u8 > ,
112114 ) -> Result < Option < UpdatePackage > , Error > {
113115 if !self . supported . iter ( ) . any ( |support| {
@@ -137,6 +139,7 @@ impl Index {
137139 Some ( rollout) => rollout. start <= right_now,
138140 None => true ,
139141 } )
142+ . filter ( |version| !is_auto_update || !version. disable_autoupdate )
140143 . collect :: < Vec < & RemoteVersion > > ( ) ;
141144
142145 valid_versions. sort_unstable_by ( |lhs, rhs| lhs. version . cmp ( & rhs. version ) ) ;
@@ -252,20 +255,22 @@ struct Support {
252255 file_type : Option < FileType > ,
253256}
254257
255- #[ derive( Debug , PartialEq , Eq , Deserialize , Serialize ) ]
258+ #[ derive( Debug , Clone , PartialEq , Eq , Deserialize , Serialize ) ]
256259pub ( crate ) struct RemoteVersion {
257260 pub version : Version ,
258261 pub rollout : Option < Rollout > ,
259262 pub packages : Vec < Package > ,
263+ #[ serde( default ) ]
264+ pub disable_autoupdate : bool ,
260265}
261266
262- #[ derive( Debug , PartialEq , Eq , Deserialize , Serialize ) ]
267+ #[ derive( Debug , Clone , PartialEq , Eq , Deserialize , Serialize ) ]
263268pub ( crate ) struct Rollout {
264269 start : u64 ,
265270 end : u64 ,
266271}
267272
268- #[ derive( Debug , PartialEq , Eq , Deserialize , Serialize ) ]
273+ #[ derive( Debug , Clone , PartialEq , Eq , Deserialize , Serialize ) ]
269274#[ serde( rename_all = "camelCase" ) ]
270275pub struct Package {
271276 #[ serde( deserialize_with = "deser_enum_other" ) ]
@@ -306,7 +311,7 @@ pub struct UpdatePackage {
306311 pub cli_path : Option < String > ,
307312}
308313
309- #[ derive( Deserialize , Serialize , PartialEq , Eq , EnumString , Debug , Display ) ]
314+ #[ derive( Deserialize , Serialize , PartialEq , Eq , EnumString , Debug , Clone , Display ) ]
310315#[ serde( rename_all = "camelCase" ) ]
311316#[ strum( serialize_all = "camelCase" ) ]
312317pub enum PackageArchitecture {
@@ -360,14 +365,21 @@ pub async fn check_for_updates(
360365 variant : & Variant ,
361366 file_type : Option < & FileType > ,
362367 ignore_rollout : bool ,
368+ is_auto_update : bool ,
363369) -> Result < Option < UpdatePackage > , Error > {
364370 const CURRENT_VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
365- pull ( & channel)
366- . await ?
367- . find_next_version ( target_triple, variant, file_type, CURRENT_VERSION , ignore_rollout, None )
371+ pull ( & channel) . await ?. find_next_version (
372+ target_triple,
373+ variant,
374+ file_type,
375+ CURRENT_VERSION ,
376+ ignore_rollout,
377+ is_auto_update,
378+ None ,
379+ )
368380}
369381
370- pub ( crate ) async fn get_file_type ( ctx : & Context , variant : & Variant ) -> Result < FileType , Error > {
382+ pub async fn get_file_type ( ctx : & Context , variant : & Variant ) -> Result < FileType , Error > {
371383 match ctx. platform ( ) . os ( ) {
372384 fig_os_shim:: Os :: Mac => Ok ( FileType :: Dmg ) ,
373385 fig_os_shim:: Os :: Linux => match variant {
@@ -429,6 +441,7 @@ mod tests {
429441 & Variant :: Full ,
430442 Some ( FileType :: Dmg ) . as_ref ( ) ,
431443 false ,
444+ false ,
432445 )
433446 . await
434447 . unwrap ( ) ;
@@ -515,7 +528,8 @@ mod tests {
515528 "sha256" : "5a6abea56bfa91bd58d49fe40322058d0efea825f7e19f7fb7db1c204ae625b6" ,
516529 "size" : 76836772 ,
517530 }
518- ]
531+ ] ,
532+ "disable_autoupdate" : true ,
519533 } ,
520534 {
521535 "version" : "2.0.0" ,
@@ -560,6 +574,11 @@ mod tests {
560574
561575 assert_eq ! ( index. versions. len( ) , 4 ) ;
562576
577+ assert ! (
578+ !index. versions[ 1 ] . disable_autoupdate,
579+ "missing disable_autoupdate field should default to false"
580+ ) ;
581+
563582 // check the 1.0.0 entry matches
564583 assert_eq ! ( index. versions[ 2 ] , RemoteVersion {
565584 version: Version :: new( 1 , 0 , 0 ) ,
@@ -588,6 +607,7 @@ mod tests {
588607 cli_path: None ,
589608 }
590609 ] ,
610+ disable_autoupdate: true ,
591611 } ) ;
592612 }
593613
@@ -604,6 +624,7 @@ mod tests {
604624 Some ( & FileType :: TarZst ) ,
605625 "1.2.1" ,
606626 true ,
627+ false ,
607628 None ,
608629 )
609630 . unwrap ( ) ;
@@ -619,6 +640,7 @@ mod tests {
619640 Some ( & FileType :: TarZst ) ,
620641 "1.2.0" ,
621642 true ,
643+ false ,
622644 None ,
623645 )
624646 . unwrap ( )
@@ -635,6 +657,7 @@ mod tests {
635657 Some ( & FileType :: TarZst ) ,
636658 "1.2.1" ,
637659 true ,
660+ false ,
638661 None ,
639662 ) ;
640663 assert ! ( next. is_err( ) ) ;
@@ -649,10 +672,50 @@ mod tests {
649672 None ,
650673 "1.0.5" ,
651674 true ,
675+ false ,
652676 None ,
653677 )
654678 . unwrap ( )
655679 . expect ( "should have update package" ) ;
656680 assert_eq ! ( next. version. to_string( ) . as_str( ) , "1.2.1" ) ;
657681 }
682+
683+ #[ test]
684+ fn index_autoupdate_does_not_update_into_disabled ( ) {
685+ let mut index = load_test_index ( ) ;
686+
687+ let next = index
688+ . find_next_version (
689+ & TargetTriple :: X86_64UnknownLinuxGnu ,
690+ & Variant :: Full ,
691+ None ,
692+ "1.0.5" ,
693+ true ,
694+ true ,
695+ None ,
696+ )
697+ . unwrap ( )
698+ . expect ( "should have update package" ) ;
699+ assert_eq ! ( next. version. to_string( ) . as_str( ) , "1.2.0" ) ;
700+
701+ // Push a newer update that does not have autoupdate disabled
702+ let mut last = index. versions . last ( ) . cloned ( ) . unwrap ( ) ;
703+ last. version = Version :: from_str ( "2.0.0" ) . unwrap ( ) ;
704+ last. disable_autoupdate = false ;
705+ index. versions . push ( last) ;
706+
707+ let next = index
708+ . find_next_version (
709+ & TargetTriple :: X86_64UnknownLinuxGnu ,
710+ & Variant :: Full ,
711+ None ,
712+ "1.0.5" ,
713+ true ,
714+ true ,
715+ None ,
716+ )
717+ . unwrap ( )
718+ . expect ( "should have update package" ) ;
719+ assert_eq ! ( next. version. to_string( ) . as_str( ) , "2.0.0" ) ;
720+ }
658721}
0 commit comments