Dont attempt to get size within archive process, will return empty; ref pterodactyl/panel#2420

The stat call is operating against an unflushed file if called in the archive function, so you'll just get the emtpy archive size, rather than the final size.

Plus, we only used the file stat in one place, so slight efficiency win?
This commit is contained in:
Dane Everitt
2020-09-27 11:16:38 -07:00
parent a0fa5a94b6
commit de30e2fcc9
5 changed files with 21 additions and 31 deletions

View File

@@ -170,6 +170,7 @@ func postServerCopyFile(c *gin.Context) {
if err := s.Filesystem.Copy(data.Location); err != nil {
TrackedServerError(err, s).AbortFilesystemError(c)
return
}
c.Status(http.StatusNoContent)
@@ -313,30 +314,12 @@ func postServerCompressFiles(c *gin.Context) {
return
}
d, err := s.Filesystem.SafePath(data.RootPath)
if err != nil {
TrackedServerError(err, s).AbortWithServerError(c)
return
}
f, err := s.Filesystem.CompressFiles(data.RootPath, data.Files)
if err != nil {
TrackedServerError(err, s).AbortFilesystemError(c)
return
}
if err := s.Filesystem.HasSpaceFor(f.Size()); err != nil {
if errors.Is(err, server.ErrNotEnoughDiskSpace) {
// Exceeding space limits, delete archive and return error. Kind of a waste of resources
// I suppose, but oh well.
_ = os.Remove(filepath.Join(d, f.Name()))
}
TrackedServerError(err, s).AbortFilesystemError(c)
return
}
c.JSON(http.StatusOK, &server.Stat{
Info: f,
Mimetype: "application/tar+gzip",