@@ -4,6 +4,8 @@ use crate::run::check_system::SystemInfo;
44use std:: path:: Path ;
55use std:: process:: Command ;
66
7+ const METADATA_FILENAME : & str = "./tmp/codspeed-cache-metadata.txt" ;
8+
79fn is_system_compatible ( system_info : & SystemInfo ) -> bool {
810 system_info. os == "ubuntu" || system_info. os == "debian"
911}
@@ -92,7 +94,7 @@ pub fn install(system_info: &SystemInfo, packages: &[&str]) -> Result<()> {
9294 ) ;
9395 }
9496
95- debug ! ( "Installing packages: {packages:?}" ) ;
97+ info ! ( "Installing packages: {}" , packages . join ( ", " ) ) ;
9698
9799 run_with_sudo ( & [ "apt-get" , "update" ] ) ?;
98100 let mut install_cmd = vec ! [ "apt-get" , "install" , "-y" , "--allow-downgrades" ] ;
@@ -130,6 +132,24 @@ fn restore_from_cache(system_info: &SystemInfo, cache_dir: &Path) -> Result<()>
130132 cache_dir. display( )
131133 ) ;
132134
135+ // Read and log the metadata file if it exists
136+ let metadata_path = cache_dir. join ( METADATA_FILENAME ) ;
137+ if metadata_path. exists ( ) {
138+ match std:: fs:: read_to_string ( & metadata_path) {
139+ Ok ( content) => {
140+ info ! (
141+ "Packages restored from cache: {}" ,
142+ content. lines( ) . join( ", " )
143+ ) ;
144+ }
145+ Err ( e) => {
146+ warn ! ( "Failed to read metadata file: {e}" ) ;
147+ }
148+ }
149+ } else {
150+ debug ! ( "No metadata file found in cache directory" ) ;
151+ }
152+
133153 // Use bash to properly handle glob expansion
134154 let cache_dir_str = cache_dir
135155 . to_str ( )
@@ -183,6 +203,27 @@ fn save_to_cache(system_info: &SystemInfo, cache_dir: &Path, packages: &[&str])
183203 bail ! ( "Failed to save packages to cache" ) ;
184204 }
185205
206+ // Create metadata file containing the installed packages
207+ let metadata_path = cache_dir. join ( METADATA_FILENAME ) ;
208+ let metadata_content = packages. join ( "\n " ) ; // TODO: add package versions as well, by using the output of the install command for example
209+ if let Ok ( ( ) ) = std:: fs:: create_dir_all ( metadata_path. parent ( ) . unwrap ( ) ) {
210+ if let Ok ( ( ) ) =
211+ std:: fs:: write ( & metadata_path, metadata_content) . context ( "Failed to write metadata file" )
212+ {
213+ debug ! ( "Metadata file created at: {}" , metadata_path. display( ) ) ;
214+ } else {
215+ warn ! (
216+ "Failed to create metadata file at: {}" ,
217+ metadata_path. display( )
218+ ) ;
219+ }
220+ } else {
221+ warn ! (
222+ "Failed to create metadata file parent directory for: {}" ,
223+ metadata_path. display( )
224+ ) ;
225+ }
226+
186227 debug ! ( "Packages cached successfully" ) ;
187228 Ok ( ( ) )
188229}
0 commit comments