Replace error handling package with emperror; add better reporting for errors escaping server root
This commit is contained in:
@@ -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.WithStack(err)
|
||||
return errors.WithStackIf(err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
@@ -58,7 +58,7 @@ func (a *Archive) Create(dst string, ctx context.Context) error {
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return errors.WithStack(ctx.Err())
|
||||
return errors.WithStackIf(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.WithStack(err)
|
||||
return errors.WithStackIf(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -91,7 +91,7 @@ func (a *Archive) addToArchive(p string, w *tar.Writer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.WithStack(err)
|
||||
return errors.WithStackIf(err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
@@ -102,7 +102,7 @@ func (a *Archive) addToArchive(p string, w *tar.Writer) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
return errors.WithStack(err)
|
||||
return errors.WithStackIf(err)
|
||||
}
|
||||
|
||||
header := &tar.Header{
|
||||
@@ -120,12 +120,12 @@ func (a *Archive) addToArchive(p string, w *tar.Writer) error {
|
||||
defer a.Unlock()
|
||||
|
||||
if err := w.WriteHeader(header); err != nil {
|
||||
return errors.WithStack(err)
|
||||
return errors.WithStackIf(err)
|
||||
}
|
||||
|
||||
buf := make([]byte, 4*1024)
|
||||
if _, err := io.CopyBuffer(w, f, buf); err != nil {
|
||||
return errors.WithStack(err)
|
||||
return errors.WithStackIf(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@@ -2,9 +2,9 @@ package backup
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"emperror.dev/errors"
|
||||
"encoding/hex"
|
||||
"github.com/apex/log"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pterodactyl/wings/api"
|
||||
"github.com/pterodactyl/wings/config"
|
||||
"io"
|
||||
@@ -87,7 +87,7 @@ func (b *Backup) Path() string {
|
||||
func (b *Backup) Size() (int64, error) {
|
||||
st, err := os.Stat(b.Path())
|
||||
if err != nil {
|
||||
return 0, errors.WithStack(err)
|
||||
return 0, errors.WithStackIf(err)
|
||||
}
|
||||
|
||||
return st.Size(), nil
|
||||
@@ -99,7 +99,7 @@ func (b *Backup) Checksum() ([]byte, error) {
|
||||
|
||||
f, err := os.Open(b.Path())
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
return nil, errors.WithStackIf(err)
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package backup
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/pkg/errors"
|
||||
"emperror.dev/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.WithStack(err)
|
||||
return nil, nil, errors.WithStackIf(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.WithStack(err)
|
||||
return nil, errors.WithStackIf(err)
|
||||
}
|
||||
|
||||
return b.Details(), nil
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package backup
|
||||
|
||||
import (
|
||||
"emperror.dev/errors"
|
||||
"fmt"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type Request struct {
|
||||
|
||||
@@ -3,9 +3,9 @@ package backup
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"emperror.dev/errors"
|
||||
"fmt"
|
||||
"github.com/apex/log"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pterodactyl/wings/api"
|
||||
"io"
|
||||
"net/http"
|
||||
@@ -31,17 +31,17 @@ func (s *S3Backup) Generate(included *IncludedFiles, prefix string) (*ArchiveDet
|
||||
}
|
||||
|
||||
if err := a.Create(s.Path(), context.Background()); err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
return nil, errors.WithStackIf(err)
|
||||
}
|
||||
|
||||
rc, err := os.Open(s.Path())
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
return nil, errors.WithStackIf(err)
|
||||
}
|
||||
defer rc.Close()
|
||||
|
||||
if err := s.generateRemoteRequest(rc); err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
return nil, errors.WithStackIf(err)
|
||||
}
|
||||
|
||||
return s.Details(), err
|
||||
|
||||
Reference in New Issue
Block a user