From a07f82258917635bf9e9f4a16da3324c1f5b2f74 Mon Sep 17 00:00:00 2001 From: "jakub.coufal" Date: Sun, 3 Mar 2019 16:29:38 +0100 Subject: [PATCH] Delete obsolete files in target directory --- pkg/upload/upload.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/upload/upload.go b/pkg/upload/upload.go index ce8e31e..15db758 100644 --- a/pkg/upload/upload.go +++ b/pkg/upload/upload.go @@ -474,6 +474,7 @@ func newFolderUploader(o UploaderOptions) (Uploader, error) { } func (u *folderUploader) Upload(commitID string, iter FileIter) error { + filesToKeep := make(map[string]bool) err := iter.ForEach(func(file *object.File) error { if filterFile(file, u.includes, u.excludes) { src := path.Join(u.sourcePath, file.Name) @@ -481,6 +482,7 @@ func (u *folderUploader) Upload(commitID string, iter FileIter) error { src, _ = filepath.Abs(src) } dst := path.Join(u.name, file.Name) + filesToKeep[dst] = true source, err := os.Open(src) if err != nil { @@ -518,6 +520,16 @@ func (u *folderUploader) Upload(commitID string, iter FileIter) error { return nil }) + err = filepath.Walk(u.name, func(path string, info os.FileInfo, err error) error { + if _, exists := filesToKeep[path]; !info.IsDir() && !exists { + err := os.Remove(path) + if err != nil { + return err + } + } + return nil + }) + return err }