clean artifact temp dir after merged chunks to one file

This commit is contained in:
fuxiaohei 2024-05-15 11:09:55 +08:00
parent db578431ea
commit 34ad0a7fb7
1 changed files with 21 additions and 0 deletions

View File

@ -12,6 +12,7 @@ import (
"fmt" "fmt"
"hash" "hash"
"io" "io"
"path"
"path/filepath" "path/filepath"
"sort" "sort"
"strings" "strings"
@ -222,6 +223,22 @@ func mergeChunksForArtifact(ctx *ArtifactContext, chunks []*chunkFileItem, st st
for _, c := range chunks { for _, c := range chunks {
if err := st.Delete(c.Path); err != nil { if err := st.Delete(c.Path); err != nil {
log.Warn("Error deleting chunk: %s, %v", c.Path, err) log.Warn("Error deleting chunk: %s, %v", c.Path, err)
} else {
log.Debug("Delete chunk:%s", c.Path)
}
}
dirName := path.Dir(chunks[0].Path)
existFiles := []string{}
st.IterateObjects(dirName, func(fpath string, obj storage.Object) error {
existFiles = append(existFiles, fpath)
return nil
})
log.Debug("Artifact temp chunks dir %s, files: %d", dirName, len(existFiles))
if len(existFiles) == 0 {
if err := st.Delete(dirName); err != nil {
log.Warn("Error deleting chunk dir: %s, %v", dirName, err)
} else {
log.Debug("Delete chunk dir:%s", dirName)
} }
} }
}() }()
@ -251,3 +268,7 @@ func mergeChunksForArtifact(ctx *ArtifactContext, chunks []*chunkFileItem, st st
return nil return nil
} }
func cleanStorageDirectory(dir string) {
}