Error handling improvements (#71)
* Remove `emperror.dev/errors`, remove all `errors#Wrap` and `errors#WithStack` calls * Improve logging in `server/backup.go`
This commit is contained in:
@@ -2,9 +2,9 @@ package server
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"emperror.dev/errors"
|
||||
"encoding/hex"
|
||||
"github.com/mholt/archiver/v3"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/server/filesystem"
|
||||
"io"
|
||||
@@ -41,7 +41,7 @@ func (a *Archiver) Exists() bool {
|
||||
func (a *Archiver) Stat() (*filesystem.Stat, error) {
|
||||
s, err := os.Stat(a.Path())
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &filesystem.Stat{
|
||||
@@ -58,7 +58,7 @@ func (a *Archiver) Archive() error {
|
||||
var files []string
|
||||
fileInfo, err := ioutil.ReadDir(path)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
return err
|
||||
}
|
||||
|
||||
for _, file := range fileInfo {
|
||||
@@ -94,17 +94,17 @@ func (a *Archiver) DeleteIfExists() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return errors.WrapIf(os.Remove(a.Path()), "archiver: failed to delete archive from system")
|
||||
return errors.WithMessage(os.Remove(a.Path()), "archiver: failed to delete archive from system")
|
||||
}
|
||||
|
||||
// Checksum computes a SHA256 checksum of the server's archive.
|
||||
func (a *Archiver) Checksum() (string, error) {
|
||||
file, err := os.Open(a.Path())
|
||||
if err != nil {
|
||||
return "", errors.WithStack(err)
|
||||
return "", err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
@@ -112,7 +112,7 @@ func (a *Archiver) Checksum() (string, error) {
|
||||
|
||||
buf := make([]byte, 1024*4)
|
||||
if _, err := io.CopyBuffer(hash, file, buf); err != nil {
|
||||
return "", errors.WithStack(err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
return hex.EncodeToString(hash.Sum(nil)), nil
|
||||
|
||||
@@ -2,8 +2,8 @@ package server
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"emperror.dev/errors"
|
||||
"github.com/apex/log"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pterodactyl/wings/api"
|
||||
"github.com/pterodactyl/wings/server/backup"
|
||||
"os"
|
||||
@@ -21,7 +21,7 @@ func (s *Server) notifyPanelOfBackup(uuid string, ad *backup.ArchiveDetails, suc
|
||||
"error": err,
|
||||
}).Error("failed to notify panel of backup status due to wings error")
|
||||
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return errors.New(err.Error())
|
||||
@@ -37,7 +37,7 @@ func (s *Server) getServerwideIgnoredFiles() ([]string, error) {
|
||||
f, err := os.Open(path.Join(s.Filesystem().Path(), ".pteroignore"))
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return nil, errors.WithStack(err)
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
scanner := bufio.NewScanner(f)
|
||||
@@ -49,7 +49,7 @@ func (s *Server) getServerwideIgnoredFiles() ([]string, error) {
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ func (s *Server) Backup(b backup.BackupInterface) error {
|
||||
// Get the included files based on the root path and the ignored files provided.
|
||||
inc, err := s.GetIncludedBackupFiles(b.Ignored())
|
||||
if err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
ad, err := b.Generate(inc, s.Filesystem().Path())
|
||||
@@ -89,6 +89,11 @@ func (s *Server) Backup(b backup.BackupInterface) error {
|
||||
"backup": b.Identifier(),
|
||||
"error": notifyError,
|
||||
}).Warn("failed to notify panel of failed backup state")
|
||||
} else {
|
||||
s.Log().WithFields(log.Fields{
|
||||
"backup": b.Identifier(),
|
||||
"error": err,
|
||||
}).Info("notified panel of failed backup state")
|
||||
}
|
||||
|
||||
s.Events().PublishJson(BackupCompletedEvent+":"+b.Identifier(), map[string]interface{}{
|
||||
@@ -99,15 +104,17 @@ func (s *Server) Backup(b backup.BackupInterface) error {
|
||||
"file_size": 0,
|
||||
})
|
||||
|
||||
return errors.WrapIf(err, "backup: error while generating server backup")
|
||||
return errors.WithMessage(err, "backup: error while generating server backup")
|
||||
}
|
||||
|
||||
// Try to notify the panel about the status of this backup. If for some reason this request
|
||||
// fails, delete the archive from the daemon and return that error up the chain to the caller.
|
||||
if notifyError := s.notifyPanelOfBackup(b.Identifier(), ad, true); notifyError != nil {
|
||||
b.Remove()
|
||||
|
||||
return errors.WithStackIf(err)
|
||||
s.Log().WithField("error", notifyError).Info("failed to notify panel of successful backup state")
|
||||
return err
|
||||
} else {
|
||||
s.Log().WithField("backup", b.Identifier()).Info("notified panel of successful backup state")
|
||||
}
|
||||
|
||||
// Emit an event over the socket so we can update the backup in realtime on
|
||||
|
||||
@@ -3,9 +3,9 @@ package backup
|
||||
import (
|
||||
"archive/tar"
|
||||
"context"
|
||||
"emperror.dev/errors"
|
||||
"github.com/apex/log"
|
||||
gzip "github.com/klauspost/pgzip"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/remeh/sizedwaitgroup"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"io"
|
||||
@@ -26,7 +26,7 @@ type Archive struct {
|
||||
func (a *Archive) Create(dst string, ctx context.Context) error {
|
||||
f, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
||||
if err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
@@ -58,7 +58,7 @@ func (a *Archive) Create(dst string, ctx context.Context) error {
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return errors.WithStackIf(ctx.Err())
|
||||
return ctx.Err()
|
||||
default:
|
||||
return a.addToArchive(p, tw)
|
||||
}
|
||||
@@ -75,7 +75,7 @@ func (a *Archive) Create(dst string, ctx context.Context) error {
|
||||
log.WithField("location", dst).Warn("failed to delete corrupted backup archive")
|
||||
}
|
||||
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -91,7 +91,7 @@ func (a *Archive) addToArchive(p string, w *tar.Writer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
@@ -102,14 +102,15 @@ func (a *Archive) addToArchive(p string, w *tar.Writer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
header, err := tar.FileInfoHeader(s, strings.TrimPrefix(p, a.TrimPrefix))
|
||||
name := strings.TrimPrefix(p, a.TrimPrefix)
|
||||
header, err := tar.FileInfoHeader(s, name)
|
||||
if err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return errors.WithMessage(err, "failed to get tar#FileInfoHeader for "+name)
|
||||
}
|
||||
header.Name = strings.TrimPrefix(p, a.TrimPrefix)
|
||||
header.Name = name
|
||||
|
||||
// These actions must occur sequentially, even if this function is called multiple
|
||||
// in parallel. You'll get some nasty panic's otherwise.
|
||||
@@ -117,12 +118,12 @@ func (a *Archive) addToArchive(p string, w *tar.Writer) error {
|
||||
defer a.Unlock()
|
||||
|
||||
if err := w.WriteHeader(header); err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
buf := make([]byte, 4*1024)
|
||||
if _, err := io.CopyBuffer(w, io.LimitReader(f, header.Size), buf); err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return errors.WithMessage(err, "failed to copy "+header.Name+" to archive")
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -2,7 +2,6 @@ package backup
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"emperror.dev/errors"
|
||||
"encoding/hex"
|
||||
"github.com/apex/log"
|
||||
"github.com/pterodactyl/wings/api"
|
||||
@@ -87,7 +86,7 @@ func (b *Backup) Path() string {
|
||||
func (b *Backup) Size() (int64, error) {
|
||||
st, err := os.Stat(b.Path())
|
||||
if err != nil {
|
||||
return 0, errors.WithStackIf(err)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
return st.Size(), nil
|
||||
@@ -99,7 +98,7 @@ func (b *Backup) Checksum() ([]byte, error) {
|
||||
|
||||
f, err := os.Open(b.Path())
|
||||
if err != nil {
|
||||
return nil, errors.WithStackIf(err)
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
@@ -128,6 +127,7 @@ func (b *Backup) Details() *ArchiveDetails {
|
||||
"backup": b.Identifier(),
|
||||
"error": err,
|
||||
}).Error("failed to calculate checksum for backup")
|
||||
return
|
||||
}
|
||||
|
||||
checksum = hex.EncodeToString(resp)
|
||||
|
||||
@@ -2,7 +2,7 @@ package backup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"emperror.dev/errors"
|
||||
"errors"
|
||||
"os"
|
||||
)
|
||||
|
||||
@@ -24,7 +24,7 @@ func LocateLocal(uuid string) (*LocalBackup, os.FileInfo, error) {
|
||||
|
||||
st, err := os.Stat(b.Path())
|
||||
if err != nil {
|
||||
return nil, nil, errors.WithStackIf(err)
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if st.IsDir() {
|
||||
@@ -48,7 +48,7 @@ func (b *LocalBackup) Generate(included *IncludedFiles, prefix string) (*Archive
|
||||
}
|
||||
|
||||
if err := a.Create(b.Path(), context.Background()); err != nil {
|
||||
return nil, errors.WithStackIf(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return b.Details(), nil
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package backup
|
||||
|
||||
import (
|
||||
"emperror.dev/errors"
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package backup
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"emperror.dev/errors"
|
||||
"fmt"
|
||||
"github.com/apex/log"
|
||||
"github.com/pterodactyl/wings/api"
|
||||
@@ -31,20 +30,20 @@ func (s *S3Backup) Generate(included *IncludedFiles, prefix string) (*ArchiveDet
|
||||
}
|
||||
|
||||
if err := a.Create(s.Path(), context.Background()); err != nil {
|
||||
return nil, errors.WithStackIf(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rc, err := os.Open(s.Path())
|
||||
if err != nil {
|
||||
return nil, errors.WithStackIf(err)
|
||||
return nil, err
|
||||
}
|
||||
defer rc.Close()
|
||||
|
||||
if err := s.generateRemoteRequest(rc); err != nil {
|
||||
return nil, errors.WithStackIf(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return s.Details(), err
|
||||
return s.Details(), nil
|
||||
}
|
||||
|
||||
// Removes a backup from the system.
|
||||
|
||||
@@ -2,9 +2,9 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"emperror.dev/errors"
|
||||
"fmt"
|
||||
"github.com/mitchellh/colorstring"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/system"
|
||||
"sync"
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
var ErrTooMuchConsoleData = errors.Sentinel("console is outputting too much data")
|
||||
var ErrTooMuchConsoleData = errors.New("console is outputting too much data")
|
||||
|
||||
type ConsoleThrottler struct {
|
||||
mu sync.Mutex
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"emperror.dev/errors"
|
||||
"fmt"
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/environment"
|
||||
@@ -57,7 +56,7 @@ func (s *Server) handleServerCrash() error {
|
||||
|
||||
exitCode, oomKilled, err := s.Environment.ExitState()
|
||||
if err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
// If the system is not configured to detect a clean exit code as a crash, and the
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package server
|
||||
|
||||
import "emperror.dev/errors"
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var ErrIsRunning = errors.Sentinel("server is running")
|
||||
var ErrSuspended = errors.Sentinel("server is currently in a suspended state")
|
||||
var ErrIsRunning = errors.New("server is running")
|
||||
var ErrSuspended = errors.New("server is currently in a suspended state")
|
||||
|
||||
type crashTooFrequent struct {
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"emperror.dev/errors"
|
||||
"github.com/pterodactyl/wings/server/filesystem"
|
||||
"os"
|
||||
)
|
||||
@@ -13,12 +12,12 @@ func (s *Server) Filesystem() *filesystem.Filesystem {
|
||||
// Ensures that the data directory for the server instance exists.
|
||||
func (s *Server) EnsureDataDirectoryExists() error {
|
||||
if _, err := os.Stat(s.fs.Path()); err != nil && !os.IsNotExist(err) {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
} else if err != nil {
|
||||
// Create the server data directory because it does not currently exist
|
||||
// on the system.
|
||||
if err := os.MkdirAll(s.fs.Path(), 0700); err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err := s.fs.Chown("/"); err != nil {
|
||||
|
||||
@@ -2,7 +2,6 @@ package filesystem
|
||||
|
||||
import (
|
||||
"context"
|
||||
"emperror.dev/errors"
|
||||
"fmt"
|
||||
"github.com/karrick/godirwalk"
|
||||
"github.com/pterodactyl/wings/server/backup"
|
||||
@@ -27,7 +26,7 @@ func (fs *Filesystem) GetIncludedFiles(dir string, ignored []string) (*backup.In
|
||||
|
||||
i, err := ignore.CompileIgnoreLines(ignored...)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Walk through all of the files and directories on a server. This callback only returns
|
||||
@@ -65,7 +64,7 @@ func (fs *Filesystem) GetIncludedFiles(dir string, ignored []string) (*backup.In
|
||||
},
|
||||
})
|
||||
|
||||
return inc, errors.WithStackIf(err)
|
||||
return inc, err
|
||||
}
|
||||
|
||||
// Compresses all of the files matching the given paths in the specified directory. This function
|
||||
@@ -141,7 +140,7 @@ func (fs *Filesystem) CompressFiles(dir string, paths []string) (os.FileInfo, er
|
||||
d := path.Join(cleanedRootDir, fmt.Sprintf("archive-%s.tar.gz", strings.ReplaceAll(time.Now().Format(time.RFC3339), ":", "")))
|
||||
|
||||
if err := a.Create(d, context.Background()); err != nil {
|
||||
return nil, errors.WithStackIf(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
f, err := os.Stat(d)
|
||||
|
||||
@@ -4,9 +4,9 @@ import (
|
||||
"archive/tar"
|
||||
"archive/zip"
|
||||
"compress/gzip"
|
||||
"emperror.dev/errors"
|
||||
"fmt"
|
||||
"github.com/mholt/archiver/v3"
|
||||
"github.com/pkg/errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
@@ -47,10 +47,10 @@ func (fs *Filesystem) SpaceAvailableForDecompression(dir string, file string) (b
|
||||
return false, ErrUnknownArchiveFormat
|
||||
}
|
||||
|
||||
return false, errors.WithStackIf(err)
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, errors.WithStackIf(err)
|
||||
return true, err
|
||||
}
|
||||
|
||||
// Decompress a file in a given directory by using the archiver tool to infer the file
|
||||
@@ -60,12 +60,12 @@ func (fs *Filesystem) SpaceAvailableForDecompression(dir string, file string) (b
|
||||
func (fs *Filesystem) DecompressFile(dir string, file string) error {
|
||||
source, err := fs.SafePath(filepath.Join(dir, file))
|
||||
if err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
// Make sure the file exists basically.
|
||||
if _, err := os.Stat(source); err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
// Walk over all of the files spinning up an additional go-routine for each file we've encountered
|
||||
@@ -93,17 +93,17 @@ func (fs *Filesystem) DecompressFile(dir string, file string) error {
|
||||
|
||||
p, err := fs.SafePath(filepath.Join(dir, name))
|
||||
if err != nil {
|
||||
return errors.WrapIf(err, "failed to generate a safe path to server file")
|
||||
return errors.WithMessage(err, "failed to generate a safe path to server file")
|
||||
}
|
||||
|
||||
return errors.WrapIf(fs.Writefile(p, f), "could not extract file from archive")
|
||||
return errors.WithMessage(fs.Writefile(p, f), "could not extract file from archive")
|
||||
})
|
||||
if err != nil {
|
||||
if strings.HasPrefix(err.Error(), "format ") {
|
||||
return errors.WithStackIf(ErrUnknownArchiveFormat)
|
||||
return ErrUnknownArchiveFormat
|
||||
}
|
||||
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package filesystem
|
||||
|
||||
import (
|
||||
"emperror.dev/errors"
|
||||
"github.com/apex/log"
|
||||
"github.com/karrick/godirwalk"
|
||||
"sync"
|
||||
@@ -158,7 +157,7 @@ func (fs *Filesystem) updateCachedDiskUsage() (int64, error) {
|
||||
func (fs *Filesystem) DirectorySize(dir string) (int64, error) {
|
||||
d, err := fs.SafePath(dir)
|
||||
if err != nil {
|
||||
return 0, errors.WithStackIf(err)
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var size int64
|
||||
@@ -189,7 +188,7 @@ func (fs *Filesystem) DirectorySize(dir string) (int64, error) {
|
||||
},
|
||||
})
|
||||
|
||||
return size, errors.WithStackIf(err)
|
||||
return size, err
|
||||
}
|
||||
|
||||
// Helper function to determine if a server has space available for a file of a given size.
|
||||
@@ -202,7 +201,7 @@ func (fs *Filesystem) hasSpaceFor(size int64) error {
|
||||
|
||||
s, err := fs.DiskUsage(true)
|
||||
if err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if (s + size) > fs.MaxDisk() {
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package filesystem
|
||||
|
||||
import (
|
||||
"emperror.dev/errors"
|
||||
"fmt"
|
||||
"github.com/apex/log"
|
||||
"github.com/pkg/errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var ErrIsDirectory = errors.Sentinel("filesystem: is a directory")
|
||||
var ErrNotEnoughDiskSpace = errors.Sentinel("filesystem: not enough disk space")
|
||||
var ErrUnknownArchiveFormat = errors.Sentinel("filesystem: unknown archive format")
|
||||
var ErrIsDirectory = errors.New("filesystem: is a directory")
|
||||
var ErrNotEnoughDiskSpace = errors.New("filesystem: not enough disk space")
|
||||
var ErrUnknownArchiveFormat = errors.New("filesystem: unknown archive format")
|
||||
|
||||
type BadPathResolutionError struct {
|
||||
path string
|
||||
@@ -23,6 +23,7 @@ func (b *BadPathResolutionError) Error() string {
|
||||
if r == "" {
|
||||
r = "<empty>"
|
||||
}
|
||||
|
||||
return fmt.Sprintf("filesystem: server path [%s] resolves to a location outside the server root: %s", b.path, r)
|
||||
}
|
||||
|
||||
@@ -57,7 +58,7 @@ func (fs *Filesystem) error(err error) *log.Entry {
|
||||
// for the remainder of the directory. This is assuming an os.FileInfo struct was even returned.
|
||||
func (fs *Filesystem) handleWalkerError(err error, f os.FileInfo) error {
|
||||
if !IsBadPathResolutionError(err) {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if f != nil && f.IsDir() {
|
||||
|
||||
@@ -2,9 +2,9 @@ package filesystem
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"emperror.dev/errors"
|
||||
"github.com/gabriel-vasile/mimetype"
|
||||
"github.com/karrick/godirwalk"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/system"
|
||||
"io"
|
||||
@@ -60,27 +60,27 @@ func (fs *Filesystem) Readfile(p string, w io.Writer) error {
|
||||
}
|
||||
|
||||
if st, err := os.Stat(cleaned); err != nil {
|
||||
return errors.WithStack(err)
|
||||
return err
|
||||
} else if st.IsDir() {
|
||||
return errors.WithStack(ErrIsDirectory)
|
||||
return ErrIsDirectory
|
||||
}
|
||||
|
||||
f, err := os.Open(cleaned)
|
||||
if err != nil {
|
||||
return errors.WithStack(err)
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
_, err = bufio.NewReader(f).WriteTo(w)
|
||||
|
||||
return errors.WithStack(err)
|
||||
return err
|
||||
}
|
||||
|
||||
// Writes a file to the system. If the file does not already exist one will be created.
|
||||
func (fs *Filesystem) Writefile(p string, r io.Reader) error {
|
||||
cleaned, err := fs.SafePath(p)
|
||||
if err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
var currentSize int64
|
||||
@@ -88,19 +88,19 @@ func (fs *Filesystem) Writefile(p string, r io.Reader) error {
|
||||
// to it and an empty file. We'll then write to it later on after this completes.
|
||||
if stat, err := os.Stat(cleaned); err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(filepath.Dir(cleaned), 0755); err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err := fs.Chown(filepath.Dir(cleaned)); err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if stat.IsDir() {
|
||||
return errors.WithStack(ErrIsDirectory)
|
||||
return ErrIsDirectory
|
||||
}
|
||||
|
||||
currentSize = stat.Size()
|
||||
@@ -119,7 +119,7 @@ func (fs *Filesystem) Writefile(p string, r io.Reader) error {
|
||||
// truncate the existing file.
|
||||
file, err := o.open(cleaned, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
@@ -138,7 +138,7 @@ func (fs *Filesystem) Writefile(p string, r io.Reader) error {
|
||||
func (fs *Filesystem) CreateDirectory(name string, p string) error {
|
||||
cleaned, err := fs.SafePath(path.Join(p, name))
|
||||
if err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return os.MkdirAll(cleaned, 0755)
|
||||
@@ -148,12 +148,12 @@ func (fs *Filesystem) CreateDirectory(name string, p string) error {
|
||||
func (fs *Filesystem) Rename(from string, to string) error {
|
||||
cleanedFrom, err := fs.SafePath(from)
|
||||
if err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
cleanedTo, err := fs.SafePath(to)
|
||||
if err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
// If the target file or directory already exists the rename function will fail, so just
|
||||
@@ -171,7 +171,7 @@ func (fs *Filesystem) Rename(from string, to string) error {
|
||||
// we're not at the root directory level.
|
||||
if d != fs.Path() {
|
||||
if mkerr := os.MkdirAll(d, 0755); mkerr != nil {
|
||||
return errors.WrapIf(mkerr, "failed to create directory structure for file rename")
|
||||
return errors.WithMessage(mkerr, "failed to create directory structure for file rename")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ func (fs *Filesystem) Rename(from string, to string) error {
|
||||
func (fs *Filesystem) Chown(path string) error {
|
||||
cleaned, err := fs.SafePath(path)
|
||||
if err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if fs.isTest {
|
||||
@@ -197,7 +197,7 @@ func (fs *Filesystem) Chown(path string) error {
|
||||
|
||||
// Start by just chowning the initial path that we received.
|
||||
if err := os.Chown(cleaned, uid, gid); err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
// If this is not a directory we can now return from the function, there is nothing
|
||||
@@ -249,7 +249,7 @@ func (fs *Filesystem) findCopySuffix(dir string, name string, extension string)
|
||||
// does exist, we'll just continue to the next loop and try again.
|
||||
if _, err := fs.Stat(path.Join(dir, n)); err != nil {
|
||||
if !errors.Is(err, os.ErrNotExist) {
|
||||
return "", errors.WithStackIf(err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
break
|
||||
@@ -268,12 +268,12 @@ func (fs *Filesystem) findCopySuffix(dir string, name string, extension string)
|
||||
func (fs *Filesystem) Copy(p string) error {
|
||||
cleaned, err := fs.SafePath(p)
|
||||
if err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
s, err := os.Stat(cleaned)
|
||||
if err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
} else if s.IsDir() || !s.Mode().IsRegular() {
|
||||
// If this is a directory or not a regular file, just throw a not-exist error
|
||||
// since anything calling this function should understand what that means.
|
||||
@@ -300,7 +300,7 @@ func (fs *Filesystem) Copy(p string) error {
|
||||
|
||||
source, err := os.Open(cleaned)
|
||||
if err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
defer source.Close()
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package filesystem
|
||||
|
||||
import (
|
||||
"context"
|
||||
"emperror.dev/errors"
|
||||
"golang.org/x/sync/errgroup"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -26,7 +25,7 @@ func (fs *Filesystem) SafePath(p string) (string, error) {
|
||||
// is truly pointing to.
|
||||
ep, err := filepath.EvalSymlinks(r)
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return "", errors.WithStackIf(err)
|
||||
return "", err
|
||||
} else if os.IsNotExist(err) {
|
||||
// The requested directory doesn't exist, so at this point we need to iterate up the
|
||||
// path chain until we hit a directory that _does_ exist and can be validated.
|
||||
@@ -138,5 +137,5 @@ func (fs *Filesystem) ParallelSafePath(paths []string) ([]string, error) {
|
||||
}
|
||||
|
||||
// Block until all of the routines finish and have returned a value.
|
||||
return cleaned, errors.WithStackIf(g.Wait())
|
||||
return cleaned, g.Wait()
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package filesystem
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"emperror.dev/errors"
|
||||
. "github.com/franela/goblin"
|
||||
"github.com/pkg/errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package filesystem
|
||||
|
||||
import (
|
||||
"emperror.dev/errors"
|
||||
"encoding/json"
|
||||
"github.com/gabriel-vasile/mimetype"
|
||||
"os"
|
||||
@@ -51,14 +50,14 @@ func (fs *Filesystem) Stat(p string) (*Stat, error) {
|
||||
func (fs *Filesystem) unsafeStat(p string) (*Stat, error) {
|
||||
s, err := os.Stat(p)
|
||||
if err != nil {
|
||||
return nil, errors.WithStackIf(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var m *mimetype.MIME
|
||||
if !s.IsDir() {
|
||||
m, err = mimetype.DetectFile(p)
|
||||
if err != nil {
|
||||
return nil, errors.WithStackIf(err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,12 +4,12 @@ import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"context"
|
||||
"emperror.dev/errors"
|
||||
"github.com/apex/log"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/mount"
|
||||
"github.com/docker/docker/client"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pterodactyl/wings/api"
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/environment"
|
||||
@@ -91,7 +91,7 @@ func (s *Server) internalInstall() error {
|
||||
script, err := api.New().GetInstallationScript(s.Id())
|
||||
if err != nil {
|
||||
if !api.IsRequestError(err) {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return errors.New(err.Error())
|
||||
@@ -99,7 +99,7 @@ func (s *Server) internalInstall() error {
|
||||
|
||||
p, err := NewInstallationProcess(s, &script)
|
||||
if err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
s.Log().Info("beginning installation process for server")
|
||||
@@ -131,7 +131,7 @@ func NewInstallationProcess(s *Server, script *api.InstallationScript) (*Install
|
||||
s.installer.cancel = &cancel
|
||||
|
||||
if c, err := environment.DockerClient(); err != nil {
|
||||
return nil, errors.WithStackIf(err)
|
||||
return nil, err
|
||||
} else {
|
||||
proc.client = c
|
||||
proc.context = ctx
|
||||
@@ -194,7 +194,7 @@ func (ip *InstallationProcess) RemoveContainer() {
|
||||
})
|
||||
|
||||
if err != nil && !client.IsErrNotFound(err) {
|
||||
ip.Server.Log().WithField("error", errors.WithStackIf(err)).Warn("failed to delete server install container")
|
||||
ip.Server.Log().WithField("error", err).Warn("failed to delete server install container")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,14 +219,14 @@ func (ip *InstallationProcess) Run() error {
|
||||
}()
|
||||
|
||||
if err := ip.BeforeExecute(); err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
cid, err := ip.Execute()
|
||||
if err != nil {
|
||||
ip.RemoveContainer()
|
||||
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
// If this step fails, log a warning but don't exit out of the process. This is completely
|
||||
@@ -249,12 +249,12 @@ func (ip *InstallationProcess) writeScriptToDisk() error {
|
||||
// Make sure the temp directory root exists before trying to make a directory within it. The
|
||||
// ioutil.TempDir call expects this base to exist, it won't create it for you.
|
||||
if err := os.MkdirAll(ip.tempDir(), 0700); err != nil {
|
||||
return errors.WrapIf(err, "could not create temporary directory for install process")
|
||||
return errors.WithMessage(err, "could not create temporary directory for install process")
|
||||
}
|
||||
|
||||
f, err := os.OpenFile(filepath.Join(ip.tempDir(), "install.sh"), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
return errors.WrapIf(err, "failed to write server installation script to disk before mount")
|
||||
return errors.WithMessage(err, "failed to write server installation script to disk before mount")
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
@@ -266,7 +266,7 @@ func (ip *InstallationProcess) writeScriptToDisk() error {
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
w.Flush()
|
||||
@@ -339,7 +339,7 @@ func (ip *InstallationProcess) pullInstallationImage() error {
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -350,11 +350,11 @@ func (ip *InstallationProcess) pullInstallationImage() error {
|
||||
// manner, if either one fails the error is returned.
|
||||
func (ip *InstallationProcess) BeforeExecute() error {
|
||||
if err := ip.writeScriptToDisk(); err != nil {
|
||||
return errors.WrapIf(err, "failed to write installation script to disk")
|
||||
return errors.WithMessage(err, "failed to write installation script to disk")
|
||||
}
|
||||
|
||||
if err := ip.pullInstallationImage(); err != nil {
|
||||
return errors.WrapIf(err, "failed to pull updated installation container image for server")
|
||||
return errors.WithMessage(err, "failed to pull updated installation container image for server")
|
||||
}
|
||||
|
||||
opts := types.ContainerRemoveOptions{
|
||||
@@ -364,7 +364,7 @@ func (ip *InstallationProcess) BeforeExecute() error {
|
||||
|
||||
if err := ip.client.ContainerRemove(ip.context, ip.Server.Id()+"_installer", opts); err != nil {
|
||||
if !client.IsErrNotFound(err) {
|
||||
return errors.WrapIf(err, "failed to remove existing install container for server")
|
||||
return errors.WithMessage(err, "failed to remove existing install container for server")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,12 +390,12 @@ func (ip *InstallationProcess) AfterExecute(containerId string) error {
|
||||
})
|
||||
|
||||
if err != nil && !client.IsErrNotFound(err) {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
f, err := os.OpenFile(ip.GetLogPath(), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600)
|
||||
if err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
@@ -424,15 +424,15 @@ func (ip *InstallationProcess) AfterExecute(containerId string) error {
|
||||
| ------------------------------
|
||||
`)
|
||||
if err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err := tmpl.Execute(f, ip); err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if _, err := io.Copy(f, reader); err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -500,7 +500,7 @@ func (ip *InstallationProcess) Execute() (string, error) {
|
||||
|
||||
r, err := ip.client.ContainerCreate(ip.context, conf, hostConf, nil, ip.Server.Id()+"_installer")
|
||||
if err != nil {
|
||||
return "", errors.WithStackIf(err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
ip.Server.Log().WithField("container_id", r.ID).Info("running installation script for server in container")
|
||||
@@ -520,7 +520,7 @@ func (ip *InstallationProcess) Execute() (string, error) {
|
||||
select {
|
||||
case err := <-eChan:
|
||||
if err != nil {
|
||||
return "", errors.WithStackIf(err)
|
||||
return "", err
|
||||
}
|
||||
case <-sChan:
|
||||
}
|
||||
@@ -539,7 +539,7 @@ func (ip *InstallationProcess) StreamOutput(id string) error {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
defer reader.Close()
|
||||
@@ -552,7 +552,7 @@ func (ip *InstallationProcess) StreamOutput(id string) error {
|
||||
if err := s.Err(); err != nil {
|
||||
ip.Server.Log().WithFields(log.Fields{
|
||||
"container_id": id,
|
||||
"error": errors.WithStackIf(err),
|
||||
"error": err,
|
||||
}).Warn("error processing scanner line in installation output for server")
|
||||
}
|
||||
|
||||
@@ -567,7 +567,7 @@ func (s *Server) SyncInstallState(successful bool) error {
|
||||
err := api.New().SendInstallationStatus(s.Id(), successful)
|
||||
if err != nil {
|
||||
if !api.IsRequestError(err) {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return errors.New(err.Error())
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"emperror.dev/errors"
|
||||
"encoding/json"
|
||||
"github.com/apex/log"
|
||||
"github.com/pterodactyl/wings/api"
|
||||
@@ -77,7 +76,7 @@ func (s *Server) StartEventListeners() {
|
||||
s.Environment.SetState(environment.ProcessRunningState)
|
||||
}
|
||||
|
||||
s.Log().WithField("error", errors.WithStackIf(err)).Error("failed to terminate environment after triggering throttle")
|
||||
s.Log().WithField("error", err).Error("failed to terminate environment after triggering throttle")
|
||||
}
|
||||
}()
|
||||
}
|
||||
@@ -106,7 +105,7 @@ func (s *Server) StartEventListeners() {
|
||||
stats := func(e events.Event) {
|
||||
st := new(environment.Stats)
|
||||
if err := json.Unmarshal([]byte(e.Data), st); err != nil {
|
||||
s.Log().WithField("error", errors.WithStackIf(err)).Warn("failed to unmarshal server environment stats")
|
||||
s.Log().WithField("error", err).Warn("failed to unmarshal server environment stats")
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"emperror.dev/errors"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/apex/log"
|
||||
"github.com/creasty/defaults"
|
||||
"github.com/gammazero/workerpool"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pterodactyl/wings/api"
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/environment"
|
||||
@@ -35,7 +35,7 @@ func LoadDirectory() error {
|
||||
configs, err := api.New().GetServers()
|
||||
if err != nil {
|
||||
if !api.IsRequestError(err) {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return errors.New(err.Error())
|
||||
@@ -89,12 +89,12 @@ func LoadDirectory() error {
|
||||
func FromConfiguration(data api.ServerConfigurationResponse) (*Server, error) {
|
||||
cfg := Configuration{}
|
||||
if err := defaults.Set(&cfg); err != nil {
|
||||
return nil, errors.WrapIf(err, "failed to set struct defaults for server configuration")
|
||||
return nil, errors.WithMessage(err, "failed to set struct defaults for server configuration")
|
||||
}
|
||||
|
||||
s := new(Server)
|
||||
if err := defaults.Set(s); err != nil {
|
||||
return nil, errors.WrapIf(err, "failed to set struct defaults for server")
|
||||
return nil, errors.WithMessage(err, "failed to set struct defaults for server")
|
||||
}
|
||||
|
||||
s.cfg = cfg
|
||||
|
||||
@@ -2,7 +2,7 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"emperror.dev/errors"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/environment"
|
||||
"github.com/pterodactyl/wings/server/filesystem"
|
||||
@@ -80,13 +80,13 @@ func (s *Server) HandlePowerAction(action PowerAction, waitSeconds ...int) error
|
||||
// time than that passes an error will be propagated back up the chain and this
|
||||
// request will be aborted.
|
||||
if err := s.powerLock.Acquire(ctx, 1); err != nil {
|
||||
return errors.WrapIf(err, "could not acquire lock on power state")
|
||||
return errors.WithMessage(err, "could not acquire lock on power state")
|
||||
}
|
||||
} else {
|
||||
// If no wait duration was provided we will attempt to immediately acquire the lock
|
||||
// and bail out with a context deadline error if it is not acquired immediately.
|
||||
if ok := s.powerLock.TryAcquire(1); !ok {
|
||||
return errors.WrapIf(context.DeadlineExceeded, "could not acquire lock on power state")
|
||||
return errors.WithMessage(context.DeadlineExceeded, "could not acquire lock on power state")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -149,7 +149,7 @@ func (s *Server) HandlePowerAction(action PowerAction, waitSeconds ...int) error
|
||||
func (s *Server) onBeforeStart() error {
|
||||
s.Log().Info("syncing server configuration with panel")
|
||||
if err := s.Sync(); err != nil {
|
||||
return errors.WrapIf(err, "unable to sync server data from Panel instance")
|
||||
return errors.WithMessage(err, "unable to sync server data from Panel instance")
|
||||
}
|
||||
|
||||
// Disallow start & restart if the server is suspended. Do this check after performing a sync
|
||||
@@ -185,7 +185,7 @@ func (s *Server) onBeforeStart() error {
|
||||
s.PublishConsoleOutputFromDaemon("Ensuring file permissions are set correctly, this could take a few seconds...")
|
||||
// Ensure all of the server file permissions are set correctly before booting the process.
|
||||
if err := s.Filesystem().Chown("/"); err != nil {
|
||||
return errors.WrapIf(err, "failed to chown root server directory during pre-boot process")
|
||||
return errors.WithMessage(err, "failed to chown root server directory during pre-boot process")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@ package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"emperror.dev/errors"
|
||||
"fmt"
|
||||
"github.com/apex/log"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pterodactyl/wings/api"
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/environment"
|
||||
@@ -115,7 +115,7 @@ func (s *Server) Sync() error {
|
||||
cfg, err := api.New().GetServerConfiguration(s.Id())
|
||||
if err != nil {
|
||||
if !api.IsRequestError(err) {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err.(*api.RequestError).Status == "404" {
|
||||
@@ -131,7 +131,7 @@ func (s *Server) Sync() error {
|
||||
func (s *Server) SyncWithConfiguration(cfg api.ServerConfigurationResponse) error {
|
||||
// Update the data structure and persist it to the disk.
|
||||
if err := s.UpdateDataStructure(cfg.Settings); err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
s.Lock()
|
||||
@@ -171,7 +171,7 @@ func (s *Server) IsBootable() bool {
|
||||
func (s *Server) CreateEnvironment() error {
|
||||
// Ensure the data directory exists before getting too far through this process.
|
||||
if err := s.EnsureDataDirectoryExists(); err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return s.Environment.Create()
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"emperror.dev/errors"
|
||||
"encoding/json"
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"github.com/pterodactyl/wings/environment"
|
||||
@@ -22,14 +21,14 @@ func CachedServerStates() (map[string]string, error) {
|
||||
// Open the states file.
|
||||
f, err := os.OpenFile(config.Get().System.GetStatesPath(), os.O_RDONLY|os.O_CREATE, 0644)
|
||||
if err != nil {
|
||||
return nil, errors.WithStackIf(err)
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// Convert the json object to a map.
|
||||
states := map[string]string{}
|
||||
if err := json.NewDecoder(f).Decode(&states); err != nil && err != io.EOF {
|
||||
return nil, errors.WithStackIf(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return states, nil
|
||||
@@ -46,7 +45,7 @@ func saveServerStates() error {
|
||||
// Convert the map to a json object.
|
||||
data, err := json.Marshal(states)
|
||||
if err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
stateMutex.Lock()
|
||||
@@ -54,7 +53,7 @@ func saveServerStates() error {
|
||||
|
||||
// Write the data to the file
|
||||
if err := ioutil.WriteFile(config.Get().System.GetStatesPath(), data, 0644); err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"emperror.dev/errors"
|
||||
"encoding/json"
|
||||
"github.com/buger/jsonparser"
|
||||
"github.com/imdario/mergo"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pterodactyl/wings/environment"
|
||||
)
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
func (s *Server) UpdateDataStructure(data []byte) error {
|
||||
src := new(Configuration)
|
||||
if err := json.Unmarshal(data, src); err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
// Don't allow obviously corrupted data to pass through into this function. If the UUID
|
||||
@@ -47,7 +47,7 @@ func (s *Server) UpdateDataStructure(data []byte) error {
|
||||
// Merge the new data object that we have received with the existing server data object
|
||||
// and then save it to the disk so it is persistent.
|
||||
if err := mergo.Merge(&c, src, mergo.WithOverride); err != nil {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
|
||||
// Don't explode if we're setting CPU limits to 0. Mergo sees that as an empty value
|
||||
@@ -65,7 +65,7 @@ func (s *Server) UpdateDataStructure(data []byte) error {
|
||||
// request is going to be boolean. Allegedly.
|
||||
if v, err := jsonparser.GetBoolean(data, "container", "oom_disabled"); err != nil {
|
||||
if err != jsonparser.KeyPathNotFoundError {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
c.Build.OOMDisabled = v
|
||||
@@ -74,7 +74,7 @@ func (s *Server) UpdateDataStructure(data []byte) error {
|
||||
// Mergo also cannot handle this boolean value.
|
||||
if v, err := jsonparser.GetBoolean(data, "suspended"); err != nil {
|
||||
if err != jsonparser.KeyPathNotFoundError {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
c.Suspended = v
|
||||
@@ -82,7 +82,7 @@ func (s *Server) UpdateDataStructure(data []byte) error {
|
||||
|
||||
if v, err := jsonparser.GetBoolean(data, "skip_egg_scripts"); err != nil {
|
||||
if err != jsonparser.KeyPathNotFoundError {
|
||||
return errors.WithStackIf(err)
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
c.SkipEggScripts = v
|
||||
|
||||
Reference in New Issue
Block a user