@@ -79,9 +79,48 @@ export class Caching {
7979 return ;
8080 }
8181
82- await CloudRunnerSystem . Run (
83- `tar -cf ${ cacheArtifactName } .tar${ compressionSuffix } "${ path . basename ( sourceFolder ) } "` ,
84- ) ;
82+ // Check disk space before creating tar archive
83+ try {
84+ const diskCheckOutput = await CloudRunnerSystem . Run ( `df -h . 2>/dev/null || df -h /data 2>/dev/null || true` ) ;
85+ CloudRunnerLogger . log ( `Disk space before tar: ${ diskCheckOutput } ` ) ;
86+ } catch ( error ) {
87+ // Ignore disk check errors
88+ }
89+
90+ // Clean up any existing incomplete tar files
91+ try {
92+ await CloudRunnerSystem . Run ( `rm -f ${ cacheArtifactName } .tar${ compressionSuffix } 2>/dev/null || true` ) ;
93+ } catch ( error ) {
94+ // Ignore cleanup errors
95+ }
96+
97+ try {
98+ await CloudRunnerSystem . Run (
99+ `tar -cf ${ cacheArtifactName } .tar${ compressionSuffix } "${ path . basename ( sourceFolder ) } "` ,
100+ ) ;
101+ } catch ( error : any ) {
102+ // Check if error is due to disk space
103+ const errorMessage = error ?. message || error ?. toString ( ) || '' ;
104+ if ( errorMessage . includes ( 'No space left' ) || errorMessage . includes ( 'Wrote only' ) ) {
105+ CloudRunnerLogger . log ( `Disk space error detected. Attempting cleanup...` ) ;
106+ // Try to clean up old cache files
107+ try {
108+ const cacheParent = path . dirname ( cacheFolder ) ;
109+ if ( await fileExists ( cacheParent ) ) {
110+ // Find and remove old cache entries (keep only the most recent)
111+ await CloudRunnerSystem . Run (
112+ `find ${ cacheParent } -name "*.tar*" -type f -mtime +1 -delete 2>/dev/null || true` ,
113+ ) ;
114+ }
115+ } catch ( cleanupError ) {
116+ CloudRunnerLogger . log ( `Cleanup attempt failed: ${ cleanupError } ` ) ;
117+ }
118+ throw new Error (
119+ `Failed to create cache archive due to insufficient disk space. Error: ${ errorMessage } . Please free up disk space and retry.` ,
120+ ) ;
121+ }
122+ throw error ;
123+ }
85124 await CloudRunnerSystem . Run ( `du ${ cacheArtifactName } .tar${ compressionSuffix } ` ) ;
86125 assert ( await fileExists ( `${ cacheArtifactName } .tar${ compressionSuffix } ` ) , 'cache archive exists' ) ;
87126 assert ( await fileExists ( path . basename ( sourceFolder ) ) , 'source folder exists' ) ;
0 commit comments