wings/server/transfer/archive.go
Matthew Penner d1c0ca5260
server(filesystem): rebuild everything imaginable
This wonderfully large commit replaces basically everything under the
`server/filesystem` package, re-implementing essentially everything.

This is related to
https://github.com/pterodactyl/wings/security/advisories/GHSA-494h-9924-xww9

If any vulnerabilities related to symlinks persist after this commit, I
will be very upset.

Signed-off-by: Matthew Penner <me@matthewp.io>
2024-03-13 12:27:29 -06:00

53 lines
1.4 KiB
Go

package transfer
import (
"context"
"fmt"
"io"
"github.com/pterodactyl/wings/internal/progress"
"github.com/pterodactyl/wings/server/filesystem"
)
// Archive returns an archive that can be used to stream the contents of the
// contents of a server.
func (t *Transfer) Archive() (*Archive, error) {
if t.archive == nil {
// Get the disk usage of the server (used to calculate the progress of the archive process)
rawSize, err := t.Server.Filesystem().DiskUsage(true)
if err != nil {
return nil, fmt.Errorf("transfer: failed to get server disk usage: %w", err)
}
// Create a new archive instance and assign it to the transfer.
t.archive = NewArchive(t, uint64(rawSize))
}
return t.archive, nil
}
// Archive represents an archive used to transfer the contents of a server.
type Archive struct {
archive *filesystem.Archive
}
// NewArchive returns a new archive associated with the given transfer.
func NewArchive(t *Transfer, size uint64) *Archive {
return &Archive{
archive: &filesystem.Archive{
Filesystem: t.Server.Filesystem(),
Progress: progress.NewProgress(size),
},
}
}
// Stream returns a reader that can be used to stream the contents of the archive.
func (a *Archive) Stream(ctx context.Context, w io.Writer) error {
return a.archive.Stream(ctx, w)
}
// Progress returns the current progress of the archive.
func (a *Archive) Progress() *progress.Progress {
return a.archive.Progress
}