@@ -447,20 +447,38 @@ func postServerDecompressFiles(c *gin.Context) {
447447
448448 s := middleware .ExtractServer (c )
449449 lg := middleware .ExtractLogger (c ).WithFields (log.Fields {"root_path" : data .RootPath , "file" : data .File })
450- lg .Debug ("checking if space is available for file decompression" )
451- err := s .Filesystem ().SpaceAvailableForDecompression (context .Background (), data .RootPath , data .File )
450+
451+ // Check if there's enough space for decompression. This uses a 5-second timeout
452+ // to avoid delays on large archives - if it times out, decompression proceeds
453+ // with incremental space checking during extraction.
454+ err := s .Filesystem ().SpaceAvailableForDecompression (c .Request .Context (), data .RootPath , data .File )
452455 if err != nil {
453456 if filesystem .IsErrorCode (err , filesystem .ErrCodeUnknownArchive ) {
454457 lg .WithField ("error" , err ).Warn ("failed to decompress file: unknown archive format" )
455458 c .AbortWithStatusJSON (http .StatusBadRequest , gin.H {"error" : "The archive provided is in a format Wings does not understand." })
456459 return
457460 }
461+ if filesystem .IsErrorCode (err , filesystem .ErrCodeDiskSpace ) {
462+ lg .WithField ("error" , err ).Warn ("failed to decompress file: not enough disk space" )
463+ c .AbortWithStatusJSON (http .StatusBadRequest , gin.H {"error" : "There is not enough disk space available to decompress this archive." })
464+ return
465+ }
458466 middleware .CaptureAndAbort (c , err )
459467 return
460468 }
461469
462470 lg .Info ("starting file decompression" )
463- if err := s .Filesystem ().DecompressFile (context .Background (), data .RootPath , data .File ); err != nil {
471+ if err := s .Filesystem ().DecompressFile (c .Request .Context (), data .RootPath , data .File ); err != nil {
472+ if filesystem .IsErrorCode (err , filesystem .ErrCodeUnknownArchive ) {
473+ lg .WithField ("error" , err ).Warn ("failed to decompress file: unknown archive format" )
474+ c .AbortWithStatusJSON (http .StatusBadRequest , gin.H {"error" : "The archive provided is in a format Wings does not understand." })
475+ return
476+ }
477+ if filesystem .IsErrorCode (err , filesystem .ErrCodeDiskSpace ) {
478+ lg .WithField ("error" , err ).Warn ("failed to decompress file: not enough disk space" )
479+ c .AbortWithStatusJSON (http .StatusBadRequest , gin.H {"error" : "There is not enough disk space available to decompress this archive." })
480+ return
481+ }
464482 // If the file is busy for some reason just return a nicer error to the user since there is not
465483 // much we specifically can do. They'll need to stop the running server process in order to overwrite
466484 // a file like this.
0 commit comments