From 34ad0a7fb7a4c6149bedf3b45e0feb2677d79c17 Mon Sep 17 00:00:00 2001 From: fuxiaohei Date: Wed, 15 May 2024 11:09:55 +0800 Subject: [PATCH] clean artifact temp dir after merged chunks to one file --- routers/api/actions/artifacts_chunks.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/routers/api/actions/artifacts_chunks.go b/routers/api/actions/artifacts_chunks.go index 3a81724b3a..4fd6f10484 100644 --- a/routers/api/actions/artifacts_chunks.go +++ b/routers/api/actions/artifacts_chunks.go @@ -12,6 +12,7 @@ import ( "fmt" "hash" "io" + "path" "path/filepath" "sort" "strings" @@ -222,6 +223,22 @@ func mergeChunksForArtifact(ctx *ArtifactContext, chunks []*chunkFileItem, st st for _, c := range chunks { if err := st.Delete(c.Path); err != nil { 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 } + +func cleanStorageDirectory(dir string) { + +}