@@ -81,33 +81,76 @@ fn run(cli: Cli) -> Result<(), Error> {
8181
8282 let mut errors = Vec :: new ( ) ;
8383 let mut updated_files: HashMap < String , PathBuf > = HashMap :: new ( ) ;
84+ let mut any_update_available = false ;
8485
8586 for ( zsync_url, paths) in & groups {
86- if paths. len ( ) > 1 {
87+ if paths. len ( ) > 1 && !cli . check_for_update {
8788 println ! (
8889 "\n === Group ({} AppImages, same update source) ===" ,
8990 paths. len( )
9091 ) ;
9192 }
9293 for path in paths {
93- if appimages. len ( ) > 1 {
94+ if appimages. len ( ) > 1 && !cli . check_for_update {
9495 println ! ( "\n === {} ===" , path. display( ) ) ;
9596 }
96- if let Err ( e) = handle_appimage ( & cli, path, zsync_url, & mut updated_files) {
97+ if cli. check_for_update {
98+ print ! ( "Checking: {} ... " , path. display( ) ) ;
99+ use std:: io:: Write ;
100+ std:: io:: stdout ( ) . flush ( ) . ok ( ) ;
101+ match check_update ( & cli, path) {
102+ Ok ( has_update) => {
103+ if has_update {
104+ println ! ( "Update available" ) ;
105+ any_update_available = true ;
106+ } else {
107+ println ! ( "Up to date" ) ;
108+ }
109+ }
110+ Err ( e) => {
111+ println ! ( "Error: {}" , e) ;
112+ errors. push ( path. clone ( ) ) ;
113+ }
114+ }
115+ } else if let Err ( e) = handle_appimage ( & cli, path, zsync_url, & mut updated_files) {
97116 eprintln ! ( "Error updating {}: {}" , path. display( ) , e) ;
98117 errors. push ( path. clone ( ) ) ;
99118 }
100119 }
101120 }
102121
103122 for path in & ungrouped {
104- println ! ( "\n === {} ===" , path. display( ) ) ;
105- if let Err ( e) = handle_appimage ( & cli, path, "" , & mut updated_files) {
123+ if !cli. check_for_update {
124+ println ! ( "\n === {} ===" , path. display( ) ) ;
125+ }
126+ if cli. check_for_update {
127+ print ! ( "Checking: {} ... " , path. display( ) ) ;
128+ use std:: io:: Write ;
129+ std:: io:: stdout ( ) . flush ( ) . ok ( ) ;
130+ match check_update ( & cli, path) {
131+ Ok ( has_update) => {
132+ if has_update {
133+ println ! ( "Update available" ) ;
134+ any_update_available = true ;
135+ } else {
136+ println ! ( "Up to date" ) ;
137+ }
138+ }
139+ Err ( e) => {
140+ println ! ( "Error: {}" , e) ;
141+ errors. push ( path. clone ( ) ) ;
142+ }
143+ }
144+ } else if let Err ( e) = handle_appimage ( & cli, path, "" , & mut updated_files) {
106145 eprintln ! ( "Error updating {}: {}" , path. display( ) , e) ;
107146 errors. push ( path. clone ( ) ) ;
108147 }
109148 }
110149
150+ if cli. check_for_update {
151+ std:: process:: exit ( if any_update_available { 1 } else { 0 } ) ;
152+ }
153+
111154 if !errors. is_empty ( ) {
112155 eprintln ! ( "\n Failed to update {} AppImage(s)" , errors. len( ) ) ;
113156 std:: process:: exit ( 1 ) ;
@@ -165,6 +208,11 @@ fn create_updater(cli: &Cli, path: &PathBuf) -> Result<Updater, Error> {
165208 }
166209}
167210
211+ fn check_update ( cli : & Cli , path : & PathBuf ) -> Result < bool , Error > {
212+ let updater = create_updater ( cli, path) ?;
213+ updater. check_for_update ( )
214+ }
215+
168216fn handle_appimage (
169217 cli : & Cli ,
170218 path : & PathBuf ,
@@ -191,16 +239,6 @@ fn handle_appimage(
191239 return Ok ( ( ) ) ;
192240 }
193241
194- if cli. check_for_update {
195- let has_update = updater. check_for_update ( ) ?;
196- if has_update {
197- println ! ( "Update available" ) ;
198- } else {
199- println ! ( "Up to date" ) ;
200- }
201- std:: process:: exit ( if has_update { 1 } else { 0 } ) ;
202- }
203-
204242 let source_path = updater. source_path ( ) . to_path_buf ( ) ;
205243 let source_size = updater. source_size ( ) ;
206244 let ( target_path, target_size) = updater. target_info ( ) ?;
0 commit comments