mirror of
https://github.com/docker/compose.git
synced 2025-07-23 13:45:00 +02:00
Do not allow changing default context
Signed-off-by: Christopher Crone <christopher.crone@docker.com>
This commit is contained in:
parent
96907f13e1
commit
ad8a16a922
@ -36,9 +36,15 @@ import (
|
|||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/docker/api/errdefs"
|
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|
||||||
|
"github.com/docker/api/errdefs"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// DefaultContextName is an automatically generated local context
|
||||||
|
DefaultContextName = "default"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -187,6 +193,9 @@ func (s *store) GetType(meta *Metadata) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *store) Create(name string, data TypedContext) error {
|
func (s *store) Create(name string, data TypedContext) error {
|
||||||
|
if name == DefaultContextName {
|
||||||
|
return errors.Wrap(errdefs.ErrAlreadyExists, objectName(name))
|
||||||
|
}
|
||||||
dir := contextdirOf(name)
|
dir := contextdirOf(name)
|
||||||
metaDir := filepath.Join(s.root, contextsDir, metadataDir, dir)
|
metaDir := filepath.Join(s.root, contextsDir, metadataDir, dir)
|
||||||
if _, err := os.Stat(metaDir); !os.IsNotExist(err) {
|
if _, err := os.Stat(metaDir); !os.IsNotExist(err) {
|
||||||
@ -242,6 +251,9 @@ func (s *store) List() ([]*Metadata, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *store) Remove(name string) error {
|
func (s *store) Remove(name string) error {
|
||||||
|
if name == DefaultContextName {
|
||||||
|
return errors.Wrap(errdefs.ErrForbidden, objectName(name))
|
||||||
|
}
|
||||||
dir := filepath.Join(s.root, contextsDir, metadataDir, contextdirOf(name))
|
dir := filepath.Join(s.root, contextsDir, metadataDir, contextdirOf(name))
|
||||||
// Check if directory exists because os.RemoveAll returns nil if it doesn't
|
// Check if directory exists because os.RemoveAll returns nil if it doesn't
|
||||||
if _, err := os.Stat(dir); os.IsNotExist(err) {
|
if _, err := os.Stat(dir); os.IsNotExist(err) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user