Skip to content

Commit

Permalink
fail Create() if object already exists
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Bertschy <[email protected]>
  • Loading branch information
matthyx committed Nov 22, 2024
1 parent 2714080 commit 8b43fa4
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/registry/file/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (s *StorageImpl) writeFiles(key string, obj runtime.Object, metaOut runtime
return nil
}

// Create adds a new object at a key even when it already exists. 'ttl' is time-to-live
// Create adds a new object at a key unless it already exists. 'ttl' is time-to-live
// in seconds (and is ignored). If no error is returned and out is not nil, out will be
// set to the read value from database.
func (s *StorageImpl) Create(ctx context.Context, key string, obj, metaOut runtime.Object, _ uint64) error {
Expand All @@ -204,6 +204,10 @@ func (s *StorageImpl) Create(ctx context.Context, key string, obj, metaOut runti
s.locks.Lock(key)
defer s.locks.Unlock(key)
spanLock.End()
// check if object already exists
if _, err := s.appFs.Stat(makePayloadPath(filepath.Join(s.root, key))); err == nil {
return storage.NewKeyExistsError(key, 0)
}
// resourceVersion should not be set on create
if version, err := s.versioner.ObjectResourceVersion(obj); err == nil && version != 0 {
msg := "resourceVersion should not be set on objects to be created"
Expand Down

0 comments on commit 8b43fa4

Please sign in to comment.