Merge branch 'develop' of https://github.com/pterodactyl/wings into develop
This commit is contained in:
		
						commit
						522c6c17e4
					
				| 
						 | 
					@ -63,7 +63,7 @@ type Configuration struct {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// AllowedMounts is a list of allowed host-system mount points.
 | 
						// AllowedMounts is a list of allowed host-system mount points.
 | 
				
			||||||
	// This is required to have the "Server Mounts" feature work properly.
 | 
						// This is required to have the "Server Mounts" feature work properly.
 | 
				
			||||||
	AllowedMounts []string `json:"allowed_mounts" yaml:"allowed_mounts"`
 | 
						AllowedMounts []string `json:"-" yaml:"allowed_mounts"`
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// AllowedOrigins is a list of allowed request origins.
 | 
						// AllowedOrigins is a list of allowed request origins.
 | 
				
			||||||
	// The Panel URL is automatically allowed, this is only needed for adding
 | 
						// The Panel URL is automatically allowed, this is only needed for adding
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -364,7 +364,7 @@ func (e *Environment) ensureImageExists(image string) error {
 | 
				
			||||||
				log.WithFields(log.Fields{
 | 
									log.WithFields(log.Fields{
 | 
				
			||||||
					"image":        image,
 | 
										"image":        image,
 | 
				
			||||||
					"container_id": e.Id,
 | 
										"container_id": e.Id,
 | 
				
			||||||
					"error":        errors.New(err.Error()),
 | 
										"err":          err.Error(),
 | 
				
			||||||
				}).Warn("unable to pull requested image from remote source, however the image exists locally")
 | 
									}).Warn("unable to pull requested image from remote source, however the image exists locally")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				// Okay, we found a matching container image, in that case just go ahead and return
 | 
									// Okay, we found a matching container image, in that case just go ahead and return
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -341,6 +341,16 @@ func postServerDecompressFiles(c *gin.Context) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	hasSpace, err := s.Filesystem.SpaceAvailableForDecompression(data.RootPath, data.File)
 | 
						hasSpace, err := s.Filesystem.SpaceAvailableForDecompression(data.RootPath, data.File)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
 | 
							// Handle an unknown format error.
 | 
				
			||||||
 | 
							if errors.Is(err, server.ErrUnknownArchiveFormat) {
 | 
				
			||||||
 | 
								s.Log().WithField("error", err).Warn("failed to decompress file due to unknown format")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
								c.AbortWithStatusJSON(http.StatusBadRequest, gin.H{
 | 
				
			||||||
 | 
									"error": "unknown archive format",
 | 
				
			||||||
 | 
								})
 | 
				
			||||||
 | 
								return
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		TrackedServerError(err, s).AbortWithServerError(c)
 | 
							TrackedServerError(err, s).AbortWithServerError(c)
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -600,7 +600,15 @@ func (fs *Filesystem) Copy(p string) error {
 | 
				
			||||||
	base := filepath.Base(cleaned)
 | 
						base := filepath.Base(cleaned)
 | 
				
			||||||
	relative := strings.TrimSuffix(strings.TrimPrefix(cleaned, fs.Path()), base)
 | 
						relative := strings.TrimSuffix(strings.TrimPrefix(cleaned, fs.Path()), base)
 | 
				
			||||||
	extension := filepath.Ext(base)
 | 
						extension := filepath.Ext(base)
 | 
				
			||||||
	name := strings.TrimSuffix(base, filepath.Ext(base))
 | 
						name := strings.TrimSuffix(base, extension)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Ensure that ".tar" is also counted as apart of the file extension.
 | 
				
			||||||
 | 
						// There might be a better way to handle this for other double file extensions,
 | 
				
			||||||
 | 
						// but this is a good workaround for now.
 | 
				
			||||||
 | 
						if strings.HasSuffix(name, ".tar") {
 | 
				
			||||||
 | 
							extension = ".tar" + extension
 | 
				
			||||||
 | 
							name = strings.TrimSuffix(name, ".tar")
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Begin looping up to 50 times to try and create a unique copy file name. This will take
 | 
						// Begin looping up to 50 times to try and create a unique copy file name. This will take
 | 
				
			||||||
	// an input of "file.txt" and generate "file copy.txt". If that name is already taken, it will
 | 
						// an input of "file.txt" and generate "file copy.txt". If that name is already taken, it will
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,9 +10,12 @@ import (
 | 
				
			||||||
	"os"
 | 
						"os"
 | 
				
			||||||
	"path/filepath"
 | 
						"path/filepath"
 | 
				
			||||||
	"reflect"
 | 
						"reflect"
 | 
				
			||||||
 | 
						"strings"
 | 
				
			||||||
	"sync/atomic"
 | 
						"sync/atomic"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					var ErrUnknownArchiveFormat = errors.New("filesystem: unknown archive format")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Look through a given archive and determine if decompressing it would put the server over
 | 
					// Look through a given archive and determine if decompressing it would put the server over
 | 
				
			||||||
// its allocated disk space limit.
 | 
					// its allocated disk space limit.
 | 
				
			||||||
func (fs *Filesystem) SpaceAvailableForDecompression(dir string, file string) (bool, error) {
 | 
					func (fs *Filesystem) SpaceAvailableForDecompression(dir string, file string) (bool, error) {
 | 
				
			||||||
| 
						 | 
					@ -41,8 +44,15 @@ func (fs *Filesystem) SpaceAvailableForDecompression(dir string, file string) (b
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return nil
 | 
							return nil
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							if strings.HasPrefix(err.Error(), "format ") {
 | 
				
			||||||
 | 
								return false, errors.WithStack(ErrUnknownArchiveFormat)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return err == nil, errors.WithStack(err)
 | 
							return false, errors.WithStack(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return true, errors.WithStack(err)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Decompress a file in a given directory by using the archiver tool to infer the file
 | 
					// Decompress a file in a given directory by using the archiver tool to infer the file
 | 
				
			||||||
| 
						 | 
					@ -63,7 +73,7 @@ func (fs *Filesystem) DecompressFile(dir string, file string) error {
 | 
				
			||||||
	// Walk over all of the files spinning up an additional go-routine for each file we've encountered
 | 
						// Walk over all of the files spinning up an additional go-routine for each file we've encountered
 | 
				
			||||||
	// and then extract that file from the archive and write it to the disk. If any part of this process
 | 
						// and then extract that file from the archive and write it to the disk. If any part of this process
 | 
				
			||||||
	// encounters an error the entire process will be stopped.
 | 
						// encounters an error the entire process will be stopped.
 | 
				
			||||||
	return archiver.Walk(source, func(f archiver.File) error {
 | 
						err = archiver.Walk(source, func(f archiver.File) error {
 | 
				
			||||||
		// Don't waste time with directories, we don't need to create them if they have no contents, and
 | 
							// Don't waste time with directories, we don't need to create them if they have no contents, and
 | 
				
			||||||
		// we will ensure the directory exists when opening the file for writing anyways.
 | 
							// we will ensure the directory exists when opening the file for writing anyways.
 | 
				
			||||||
		if f.IsDir() {
 | 
							if f.IsDir() {
 | 
				
			||||||
| 
						 | 
					@ -90,4 +100,13 @@ func (fs *Filesystem) DecompressFile(dir string, file string) error {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return errors.Wrap(fs.Writefile(p, f), "could not extract file from archive")
 | 
							return errors.Wrap(fs.Writefile(p, f), "could not extract file from archive")
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							if strings.HasPrefix(err.Error(), "format ") {
 | 
				
			||||||
 | 
								return errors.WithStack(ErrUnknownArchiveFormat)
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							return errors.WithStack(err)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user