wings/server/backup/backup_local.go
Dane Everitt de30e2fcc9
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?
2020-09-27 11:16:38 -07:00

56 lines
1.1 KiB
Go

package backup
import (
"context"
"github.com/pkg/errors"
"os"
)
type LocalBackup struct {
Backup
}
var _ BackupInterface = (*LocalBackup)(nil)
// Locates the backup for a server and returns the local path. This will obviously only
// work if the backup was created as a local backup.
func LocateLocal(uuid string) (*LocalBackup, os.FileInfo, error) {
b := &LocalBackup{
Backup{
Uuid: uuid,
IgnoredFiles: nil,
},
}
st, err := os.Stat(b.Path())
if err != nil {
return nil, nil, errors.WithStack(err)
}
if st.IsDir() {
return nil, nil, errors.New("invalid archive, is directory")
}
return b, st, nil
}
// Removes a backup from the system.
func (b *LocalBackup) Remove() error {
return os.Remove(b.Path())
}
// Generates a backup of the selected files and pushes it to the defined location
// for this instance.
func (b *LocalBackup) Generate(included *IncludedFiles, prefix string) (*ArchiveDetails, error) {
a := &Archive{
TrimPrefix: prefix,
Files: included,
}
if err := a.Create(b.Path(), context.Background()); err != nil {
return nil, errors.WithStack(err)
}
return b.Details(), nil
}