diff options
-rw-r--r-- | libpod/reset.go | 37 | ||||
-rw-r--r-- | pkg/api/handlers/compat/images_search.go | 16 |
2 files changed, 45 insertions, 8 deletions
diff --git a/libpod/reset.go b/libpod/reset.go index 6d2842723..24efeed40 100644 --- a/libpod/reset.go +++ b/libpod/reset.go @@ -77,18 +77,35 @@ func (r *Runtime) Reset(ctx context.Context) error { } } + xdgRuntimeDir := filepath.Clean(os.Getenv("XDG_RUNTIME_DIR")) _, prevError := r.store.Shutdown(true) - if err := os.RemoveAll(r.store.GraphRoot()); err != nil { + graphRoot := filepath.Clean(r.store.GraphRoot()) + if graphRoot == xdgRuntimeDir { if prevError != nil { logrus.Error(prevError) } - prevError = err + prevError = errors.Errorf("failed to remove runtime graph root dir %s, since it is the same as XDG_RUNTIME_DIR", graphRoot) + } else { + if err := os.RemoveAll(graphRoot); err != nil { + if prevError != nil { + logrus.Error(prevError) + } + prevError = err + } } - if err := os.RemoveAll(r.store.RunRoot()); err != nil { + runRoot := filepath.Clean(r.store.RunRoot()) + if runRoot == xdgRuntimeDir { if prevError != nil { logrus.Error(prevError) } - prevError = err + prevError = errors.Errorf("failed to remove runtime root dir %s, since it is the same as XDG_RUNTIME_DIR", runRoot) + } else { + if err := os.RemoveAll(runRoot); err != nil { + if prevError != nil { + logrus.Error(prevError) + } + prevError = err + } } runtimeDir, err := util.GetRuntimeDir() if err != nil { @@ -98,13 +115,19 @@ func (r *Runtime) Reset(ctx context.Context) error { if tempDir == runtimeDir { tempDir = filepath.Join(tempDir, "containers") } - if err := os.RemoveAll(tempDir); err != nil { + if filepath.Clean(tempDir) == xdgRuntimeDir { if prevError != nil { logrus.Error(prevError) } - prevError = err + prevError = errors.Errorf("failed to remove runtime tmpdir %s, since it is the same as XDG_RUNTIME_DIR", tempDir) + } else { + if err := os.RemoveAll(tempDir); err != nil { + if prevError != nil { + logrus.Error(prevError) + } + prevError = err + } } - if storageConfPath, err := storage.DefaultConfigFile(rootless.IsRootless()); err == nil { if _, err = os.Stat(storageConfPath); err == nil { fmt.Printf("A storage.conf file exists at %s\n", storageConfPath) diff --git a/pkg/api/handlers/compat/images_search.go b/pkg/api/handlers/compat/images_search.go index b3ceae3ee..6808cdad5 100644 --- a/pkg/api/handlers/compat/images_search.go +++ b/pkg/api/handlers/compat/images_search.go @@ -8,6 +8,7 @@ import ( "github.com/containers/podman/v2/libpod/image" "github.com/containers/podman/v2/pkg/api/handlers/utils" "github.com/containers/podman/v2/pkg/auth" + "github.com/docker/docker/api/types/registry" "github.com/gorilla/schema" "github.com/pkg/errors" ) @@ -77,5 +78,18 @@ func SearchImages(w http.ResponseWriter, r *http.Request) { utils.BadRequest(w, "term", query.Term, err) return } - utils.WriteResponse(w, http.StatusOK, results) + + compatResults := make([]registry.SearchResult, 0, len(results)) + for _, result := range results { + compatResult := registry.SearchResult{ + Name: result.Name, + Description: result.Description, + StarCount: result.Stars, + IsAutomated: result.Automated == "[OK]", + IsOfficial: result.Official == "[OK]", + } + compatResults = append(compatResults, compatResult) + } + + utils.WriteResponse(w, http.StatusOK, compatResults) } |