Skip to content

Commit

Permalink
Fix file manager to create zips properly on root, wait for zip to finish
Browse files Browse the repository at this point in the history
  • Loading branch information
LordRalex committed May 20, 2024
1 parent 04a367e commit 90f1c18
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
19 changes: 12 additions & 7 deletions client/frontend/src/components/server/Files.vue
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ async function createFile() {
const file = { name: newItemName.value, size: 0, isFile: true }
createFileOpen.value = false
newItemName.value = ''
openFile(file)
refresh()
await openFile(file)
await refresh()
}
async function createFolder() {
Expand All @@ -164,8 +164,8 @@ async function createFolder() {
const folder = { name: newItemName.value, isFile: false }
createFolderOpen.value = false
newItemName.value = ''
openFile(folder)
refresh()
await openFile(folder)
await refresh()
}
const archiveExtensions = [
Expand Down Expand Up @@ -211,8 +211,13 @@ async function makeArchiveName(fileName) {
async function archiveCurrentDirectory() {
loading.value = true
try {
const lastPathEntry = currentPath.value[currentPath.value.length - 1].name
props.server.archiveFile(
const item = currentPath.value[currentPath.value.length - 1];
let lastPathEntry = props.server.id
if (item !== undefined) {
lastPathEntry = currentPath.value[currentPath.value.length - 1].name
}
await props.server.archiveFile(
await makeArchiveName(lastPathEntry),
`${getCurrentPath()}`
)
Expand All @@ -227,7 +232,7 @@ async function archiveCurrentDirectory() {
async function archive(file) {
loading.value = true
try {
props.server.archiveFile(
await props.server.archiveFile(
await makeArchiveName(file.name),
`${getCurrentPath()}/${file.name}`
)
Expand Down
14 changes: 14 additions & 0 deletions compression.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,20 @@ func Extract(fs FileServer, sourceFile, targetPath, filter string, skipRoot bool
return archiver.Walk(sourceFile, walker(fs, targetPath, filter, skipRoot))
}

func Compress(fs FileServer, targetFile string, files []string) error {
if fs != nil {
p := fs.Prefix()

targetFile = filepath.Join(p, targetFile)

for k, v := range files {
files[k] = filepath.Join(p, v)
}
}

return archiver.Archive(files, targetFile)
}

func walker(fs FileServer, targetPath, filter string, skipRoot bool) archiver.WalkFunc {
return func(file archiver.File) (err error) {
path := getCompressedItemName(file)
Expand Down
4 changes: 2 additions & 2 deletions servers/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,10 +596,10 @@ func (p *Server) GetItem(name string) (*FileData, error) {

func (p *Server) ArchiveItems(files []string, destination string) error {
// This may technically error out in other cases
if _, err := os.Stat(destination); !os.IsNotExist(err) {
if _, err := os.Stat(destination); err != nil && !os.IsNotExist(err) {
return pufferpanel.ErrFileExists
}
return archiver.Archive(files, destination)
return pufferpanel.Compress(p.GetFileServer(), destination, files)
}

func (p *Server) Extract(source, destination string) error {
Expand Down

0 comments on commit 90f1c18

Please sign in to comment.