Remove temporary transfer archives; closes https://github.com/pterodactyl/panel/issues/2742
This commit is contained in:
parent
de51fd1c51
commit
65a861a9b6
|
@ -177,12 +177,10 @@ func postTransfer(c *gin.Context) {
|
||||||
_, err := ioutil.ReadAll(res.Body)
|
_, err := ioutil.ReadAll(res.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.WithField("error", err).WithField("status", res.StatusCode).Error("failed read transfer response body")
|
l.WithField("error", err).WithField("status", res.StatusCode).Error("failed read transfer response body")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l.WithField("error", err).WithField("status", res.StatusCode).Error("failed to request server archive")
|
l.WithField("error", err).WithField("status", res.StatusCode).Error("failed to request server archive")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +197,6 @@ func postTransfer(c *gin.Context) {
|
||||||
} else {
|
} else {
|
||||||
if err := os.Remove(archivePath); err != nil {
|
if err := os.Remove(archivePath); err != nil {
|
||||||
l.WithField("error", err).Warn("failed to remove old archive file")
|
l.WithField("error", err).Warn("failed to remove old archive file")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -208,7 +205,6 @@ func postTransfer(c *gin.Context) {
|
||||||
file, err := os.Create(archivePath)
|
file, err := os.Create(archivePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.WithField("error", err).Error("failed to open archive on disk")
|
l.WithField("error", err).Error("failed to open archive on disk")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,17 +213,28 @@ func postTransfer(c *gin.Context) {
|
||||||
_, err = io.CopyBuffer(file, res.Body, buf)
|
_, err = io.CopyBuffer(file, res.Body, buf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
l.WithField("error", err).Error("failed to copy archive file to disk")
|
l.WithField("error", err).Error("failed to copy archive file to disk")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the file so it can be opened to verify the checksum.
|
// Close the file so it can be opened to verify the checksum.
|
||||||
if err := file.Close(); err != nil {
|
if err := file.Close(); err != nil {
|
||||||
l.WithField("error", err).Error("failed to close archive file")
|
l.WithField("error", err).Error("failed to close archive file")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Whenever the transfer fails or succeeds, delete the temporary transfer archive.
|
||||||
|
defer func() {
|
||||||
|
log.WithField("server", serverID).Debug("deleting temporary transfer archive..")
|
||||||
|
if err := os.Remove(archivePath); err != nil && !os.IsNotExist(err) {
|
||||||
|
l.WithFields(log.Fields{
|
||||||
|
"server": serverID,
|
||||||
|
"error": err,
|
||||||
|
}).Warn("failed to delete transfer archive")
|
||||||
|
} else {
|
||||||
|
l.WithField("server", serverID).Debug("deleted temporary transfer archive successfully")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
l.WithField("server", serverID).Debug("server archive downloaded, computing checksum...")
|
l.WithField("server", serverID).Debug("server archive downloaded, computing checksum...")
|
||||||
|
|
||||||
// Open the archive file for computing a checksum.
|
// Open the archive file for computing a checksum.
|
||||||
|
@ -282,7 +289,7 @@ func postTransfer(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Un-archive the archive. That sounds weird..
|
// Un-archive the archive, that sounds weird..
|
||||||
if err := archiver.NewTarGz().Unarchive(archivePath, i.Server().Filesystem().Path()); err != nil {
|
if err := archiver.NewTarGz().Unarchive(archivePath, i.Server().Filesystem().Path()); err != nil {
|
||||||
l.WithField("error", err).Error("failed to extract server archive")
|
l.WithField("error", err).Error("failed to extract server archive")
|
||||||
return
|
return
|
||||||
|
@ -307,7 +314,7 @@ func postTransfer(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
l.Info("successfully notified panel of transfer success")
|
l.WithField("server", serverID).Info("successfully notified panel of transfer success")
|
||||||
}(buf.Bytes())
|
}(buf.Bytes())
|
||||||
|
|
||||||
c.Status(http.StatusAccepted)
|
c.Status(http.StatusAccepted)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user