@@ -19,7 +19,7 @@ async function main() {
1919
2020 if ( accessible ) {
2121 core . info ( 'Checking cache size' ) ;
22- const size = await totalSize ( cache_path ) ;
22+ const size = await dirSize ( cache_path ) ;
2323 const size_limit = core . getInput ( 'cache-size-limit' ) * 1024 * 1024 ; // MiB -> bytes
2424 if ( size_limit !== 0 && size > size_limit ) {
2525 core . info ( `Cache directory reached ${ size } bytes, exceeding limit of ${ size_limit } bytes; clearing cache` ) ;
@@ -35,25 +35,27 @@ async function main() {
3535 const name = prefix + github . context . runId ;
3636 core . info ( 'Saving Zig cache' ) ;
3737 await cache . saveCache ( [ cache_path ] , name ) ;
38+ } else {
39+ core . info ( 'Zig cache directory is inaccessible; nothing to save' ) ;
3840 }
3941 }
4042 } catch ( err ) {
4143 core . setFailed ( err . message ) ;
4244 }
4345}
4446
45- async function totalSize ( p ) {
47+ async function dirSize ( dir_path ) {
4648 try {
47- const stat = await fs . stat ( p ) ;
48- if ( stat . isFile ( ) ) return stat . size ;
49- if ( stat . isDirectory ( ) ) {
50- let total = 0 ;
51- for ( const entry of await fs . readdir ( p ) ) {
52- total += await totalSize ( path . join ( p , entry ) ) ;
49+ let total = 0 ;
50+ for ( const ent of await fs . readdir ( dir_path , { withFileTypes : true , recursive : true } ) ) {
51+ if ( ent . isFile ( ) ) {
52+ try {
53+ const stat = await fs . stat ( path . join ( ent . parentPath , ent . name ) ) ;
54+ total += stat . size ;
55+ } catch { }
5356 }
54- return total ;
5557 }
56- return 0 ;
58+ return total ;
5759 } catch {
5860 return 0 ;
5961 }
0 commit comments