From ae46add8ef9b671e80bbaf8e3189bf036b5f660e Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Wed, 15 Jul 2020 19:24:13 -0700 Subject: [PATCH] Remove unnecessary logic --- server/filesystem.go | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/server/filesystem.go b/server/filesystem.go index 50285cc..d20adb0 100644 --- a/server/filesystem.go +++ b/server/filesystem.go @@ -744,24 +744,15 @@ func (fs *Filesystem) CompressFiles(dir string, paths []string) (os.FileInfo, er return a.Create(d, context.Background()) } -// DecompressFile decompresses an archive. -func (fs *Filesystem) DecompressFile(dir, file string) error { - // Clean the directory path where the contents of archive will be extracted to. - safeBasePath, err := fs.SafePath(dir) +// Decompress a file in a given directory by using the archiver tool to infer the file +// type and go from there. +func (fs *Filesystem) DecompressFile(dir string, file string) error { + source, err := fs.SafePath(filepath.Join(dir, file)) if err != nil { - return err + return errors.WithStack(err) } - // Clean the full path to the archive which will be unarchived. - safeArchivePath, err := fs.SafePath(filepath.Join(safeBasePath, file)) - if err != nil { - return err - } + dest := strings.TrimSuffix(source, filepath.Base(source)) - // Decompress the archive using it's extension to determine the algorithm. - if err := archiver.Unarchive(safeArchivePath, safeBasePath); err != nil { - return err - } - - return nil + return archiver.Unarchive(source, dest) }