Skip to content

Commit

Permalink
cleanup tmp directories when the repository is closed
Browse files Browse the repository at this point in the history
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
  • Loading branch information
Adphi committed Oct 2, 2023
1 parent ecbe81a commit 6593283
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 6 additions & 1 deletion pkg/packages/rpm/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (p *provider) repositoryConfig(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
_ = repo
defer repo.Close()
scheme := "http"
if r.TLS != nil {
scheme = "https"
Expand All @@ -79,6 +79,7 @@ func (p *provider) repositoryKey(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer repo.Close()
rc, err := repo.Open(ctx, RepositoryPublicKey)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand Down Expand Up @@ -108,6 +109,7 @@ func (p *provider) uploadPackage(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer repo.Close()
pkg, err := NewPackage(reader, size, repo.Key())
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
Expand All @@ -133,6 +135,7 @@ func (p *provider) downloadPackage(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer repo.Close()
if err := repo.ServeFile(w, r, file); err != nil {
if errors.Is(err, os.ErrNotExist) {
http.Error(w, err.Error(), http.StatusNotFound)
Expand All @@ -152,6 +155,7 @@ func (p *provider) deletePackage(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer repo.Close()
if err := repo.Delete(ctx, file); err != nil {
if errors.Is(err, os.ErrNotExist) {
http.Error(w, err.Error(), http.StatusNotFound)
Expand All @@ -171,6 +175,7 @@ func (p *provider) repositoryFile(w http.ResponseWriter, r *http.Request) {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer repo.Close()
if err := repo.ServeFile(w, r, file); err != nil {
if errors.Is(err, os.ErrNotExist) {
http.Error(w, err.Error(), http.StatusNotFound)
Expand Down
2 changes: 1 addition & 1 deletion pkg/repository/oci_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ func (s *storage[T, U]) Key() string {
}

func (s *storage[T, U]) Close() error {
return nil
return os.RemoveAll(s.tmp)
}

func (s *storage[T, U]) updateIndex(ctx context.Context, store *file.Store, m ocispec.Manifest, pkgs []T, layers []ocispec.Descriptor) error {
Expand Down

0 comments on commit 6593283

Please sign in to comment.