@@ -555,6 +555,8 @@ impl Env {
555555 . map_err ( |err| JailerError :: CreateDir ( jailer_cache_dir. to_owned ( ) , err) ) ?;
556556
557557 for index in 0 ..( MAX_CACHE_LEVEL + 1 ) {
558+ let mut err_str = String :: new ( ) ;
559+
558560 let index_folder = format ! ( "index{}" , index) ;
559561 let host_path = PathBuf :: from ( HOST_CACHE_INFO ) . join ( & index_folder) ;
560562
@@ -575,17 +577,35 @@ impl Env {
575577 let host_cache_file = host_path. join ( entry) ;
576578 let jailer_cache_file = jailer_path. join ( entry) ;
577579
578- let line = readln_special ( & host_cache_file) ?;
579- writeln_special ( & jailer_cache_file, line) ?;
580+ if let Ok ( line) = readln_special ( & host_cache_file) {
581+ writeln_special ( & jailer_cache_file, line) ?;
582+
583+ // We now change the permissions.
584+ let dest_path_cstr = to_cstring ( & jailer_cache_file) ?;
585+ // SAFETY: Safe because dest_path_cstr is null-terminated.
586+ SyscallReturnCode ( unsafe {
587+ libc:: chown ( dest_path_cstr. as_ptr ( ) , self . uid ( ) , self . gid ( ) )
588+ } )
589+ . into_empty_result ( )
590+ . map_err ( |err| {
591+ JailerError :: ChangeFileOwner ( jailer_cache_file. to_owned ( ) , err)
592+ } ) ?;
593+ } else {
594+ err_str += entry;
595+ err_str += ", " ;
596+ }
597+ }
598+
599+ // Pop the last 2 chars if a comma and space are present.
600+ // The unwrap is safe since we check that the string actually
601+ // ends with those 2 chars.
602+ if err_str. ends_with ( ", " ) {
603+ err_str. pop ( ) . unwrap ( ) ;
604+ err_str. pop ( ) . unwrap ( ) ;
605+ }
580606
581- // We now change the permissions.
582- let dest_path_cstr = to_cstring ( & jailer_cache_file) ?;
583- // SAFETY: Safe because dest_path_cstr is null-terminated.
584- SyscallReturnCode ( unsafe {
585- libc:: chown ( dest_path_cstr. as_ptr ( ) , self . uid ( ) , self . gid ( ) )
586- } )
587- . into_empty_result ( )
588- . map_err ( |err| JailerError :: ChangeFileOwner ( jailer_cache_file. to_owned ( ) , err) ) ?;
607+ if !err_str. is_empty ( ) {
608+ println ! ( "Could not read the {err_str} for cache level {index}." ) ;
589609 }
590610 }
591611 Ok ( ( ) )
0 commit comments