@@ -19,7 +19,7 @@ async function main() {
19
19
20
20
if ( accessible ) {
21
21
core . info ( 'Checking cache size' ) ;
22
- const size = await totalSize ( cache_path ) ;
22
+ const size = await dirSize ( cache_path ) ;
23
23
const size_limit = core . getInput ( 'cache-size-limit' ) * 1024 * 1024 ; // MiB -> bytes
24
24
if ( size_limit !== 0 && size > size_limit ) {
25
25
core . info ( `Cache directory reached ${ size } bytes, exceeding limit of ${ size_limit } bytes; clearing cache` ) ;
@@ -35,25 +35,27 @@ async function main() {
35
35
const name = prefix + github . context . runId ;
36
36
core . info ( 'Saving Zig cache' ) ;
37
37
await cache . saveCache ( [ cache_path ] , name ) ;
38
+ } else {
39
+ core . info ( 'Zig cache directory is inaccessible; nothing to save' ) ;
38
40
}
39
41
}
40
42
} catch ( err ) {
41
43
core . setFailed ( err . message ) ;
42
44
}
43
45
}
44
46
45
- async function totalSize ( p ) {
47
+ async function dirSize ( dir_path ) {
46
48
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 { }
53
56
}
54
- return total ;
55
57
}
56
- return 0 ;
58
+ return total ;
57
59
} catch {
58
60
return 0 ;
59
61
}
0 commit comments