Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion distribution/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (c *Client) PullModel(ctx context.Context, reference string, progressWriter
return fmt.Errorf("reading model from registry: %w", err)
}

//Check for supported type
// Check for supported type
if err := checkCompat(remoteModel); err != nil {
return err
}
Expand Down Expand Up @@ -308,6 +308,15 @@ func (c *Client) PushModel(ctx context.Context, tag string, progressWriter io.Wr
return nil
}

func (c *Client) ResetStore() error {
c.log.Infoln("Resetting store")
if err := c.store.Reset(); err != nil {
c.log.Errorln("Failed to reset store:", err)
return fmt.Errorf("resetting store: %w", err)
}
return nil
}

func checkCompat(image types.ModelArtifact) error {
manifest, err := image.Manifest()
if err != nil {
Expand Down
20 changes: 20 additions & 0 deletions internal/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"io"
"os"
"path/filepath"

v1 "github.com/google/go-containerregistry/pkg/v1"
)
Expand Down Expand Up @@ -42,6 +43,25 @@ func New(opts Options) (*LocalStore, error) {
return store, nil
}

// Reset clears all contents of the store directory and reinitializes the store.
// It removes all files and subdirectories within the store's root path, but preserves the root directory itself.
// This allows the method to work correctly when the store directory is a mounted volume (e.g., in Docker CE).
func (s *LocalStore) Reset() error {
entries, err := os.ReadDir(s.rootPath)
if err != nil {
return fmt.Errorf("reading store directory: %w", err)
}

for _, entry := range entries {
entryPath := filepath.Join(s.rootPath, entry.Name())
if err := os.RemoveAll(entryPath); err != nil {
return fmt.Errorf("removing %s: %w", entryPath, err)
}
}

return s.initialize()
}

// initialize creates the store directory structure if it doesn't exist
func (s *LocalStore) initialize() error {
// Check if layout.json exists, create if not
Expand Down
Loading