Skip to content

Commit

Permalink
Delete obsolete files in target directory
Browse files Browse the repository at this point in the history
  • Loading branch information
coufalja committed Mar 3, 2019
1 parent af035d0 commit a07f822
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/upload/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,15 @@ 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)
if _, err := os.Lstat(src); err == nil {
src, _ = filepath.Abs(src)
}
dst := path.Join(u.name, file.Name)
filesToKeep[dst] = true

source, err := os.Open(src)
if err != nil {
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit a07f822

Please sign in to comment.