mirror of
https://github.com/distribution/distribution.git
synced 2025-06-24 14:33:44 +00:00
Changes:
Append a UUID to ensure uniqueness Join delete error Signed-off-by: Oded Porat <onporat@gmail.com>
This commit is contained in:
parent
a5a6f1ba3d
commit
dde1e49f23
@ -15,6 +15,7 @@ import (
|
|||||||
storagedriver "github.com/distribution/distribution/v3/registry/storage/driver"
|
storagedriver "github.com/distribution/distribution/v3/registry/storage/driver"
|
||||||
"github.com/distribution/distribution/v3/registry/storage/driver/base"
|
"github.com/distribution/distribution/v3/registry/storage/driver/base"
|
||||||
"github.com/distribution/distribution/v3/registry/storage/driver/factory"
|
"github.com/distribution/distribution/v3/registry/storage/driver/factory"
|
||||||
|
"github.com/google/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -134,7 +135,7 @@ func (d *driver) GetContent(ctx context.Context, path string) ([]byte, error) {
|
|||||||
|
|
||||||
// PutContent stores the []byte content at a location designated by "path".
|
// PutContent stores the []byte content at a location designated by "path".
|
||||||
func (d *driver) PutContent(ctx context.Context, subPath string, contents []byte) error {
|
func (d *driver) PutContent(ctx context.Context, subPath string, contents []byte) error {
|
||||||
tempPath := subPath + ".tmp"
|
tempPath := fmt.Sprintf("%s.%s.tmp", subPath, uuid.NewString())
|
||||||
|
|
||||||
// Write to a temporary file to prevent partial writes.
|
// Write to a temporary file to prevent partial writes.
|
||||||
writer, err := d.Writer(ctx, tempPath, false)
|
writer, err := d.Writer(ctx, tempPath, false)
|
||||||
@ -149,8 +150,8 @@ func (d *driver) PutContent(ctx context.Context, subPath string, contents []byte
|
|||||||
return errors.Join(err, cErr)
|
return errors.Join(err, cErr)
|
||||||
}
|
}
|
||||||
// Attempt to clean up the temporary file on error.
|
// Attempt to clean up the temporary file on error.
|
||||||
_ = d.Delete(ctx, tempPath)
|
dErr := d.Delete(ctx, tempPath)
|
||||||
return err
|
return errors.Join(err, dErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := writer.Commit(ctx); err != nil {
|
if err := writer.Commit(ctx); err != nil {
|
||||||
@ -160,8 +161,8 @@ func (d *driver) PutContent(ctx context.Context, subPath string, contents []byte
|
|||||||
// Atomically replace the target file with the temporary file.
|
// Atomically replace the target file with the temporary file.
|
||||||
if err := d.Move(ctx, tempPath, subPath); err != nil {
|
if err := d.Move(ctx, tempPath, subPath); err != nil {
|
||||||
// Clean up the temporary file if rename fails.
|
// Clean up the temporary file if rename fails.
|
||||||
_ = d.Delete(ctx, tempPath)
|
dErr := d.Delete(ctx, tempPath)
|
||||||
return err
|
return errors.Join(err, dErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user