mirror of
https://github.com/harness/drone.git
synced 2025-05-04 01:30:43 +08:00
fix: [CODE-3307]: remove invalid file from repo if copy from sharedrepo fails (#3515)
* remove invalid file from repo if copy from sharedrepo fails
This commit is contained in:
parent
f5b49c6bab
commit
b347c0f347
@ -946,7 +946,7 @@ func (r *SharedRepo) MoveObjects(ctx context.Context) error {
|
|||||||
|
|
||||||
// Try to copy the file
|
// Try to copy the file
|
||||||
|
|
||||||
copyError := func() error {
|
errCopy := func() error {
|
||||||
srcFile, err := os.Open(f.fullPath)
|
srcFile, err := os.Open(f.fullPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to open source file: %w", err)
|
return fmt.Errorf("failed to open source file: %w", err)
|
||||||
@ -966,17 +966,25 @@ func (r *SharedRepo) MoveObjects(ctx context.Context) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}()
|
}()
|
||||||
if copyError != nil {
|
if errCopy != nil {
|
||||||
log.Ctx(ctx).Err(copyError).
|
// Make sure that an invalid or incomplete file does not remain in the repository if copying fails.
|
||||||
|
errRemove := os.Remove(dstPath)
|
||||||
|
if os.IsNotExist(errRemove) {
|
||||||
|
errRemove = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Ctx(ctx).Err(errCopy).
|
||||||
Str("object", f.relPath).
|
Str("object", f.relPath).
|
||||||
Str("renameErr", errRename.Error()).
|
Str("errRename", errRename.Error()).
|
||||||
|
Str("errRemove", errRemove.Error()).
|
||||||
Msg("failed to move or copy git object")
|
Msg("failed to move or copy git object")
|
||||||
return fmt.Errorf("failed to move or copy git object: %w", copyError)
|
|
||||||
|
return fmt.Errorf("failed to move or copy git object: %w", errCopy)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Ctx(ctx).Warn().
|
log.Ctx(ctx).Warn().
|
||||||
Str("object", f.relPath).
|
Str("object", f.relPath).
|
||||||
Str("renameErr", errRename.Error()).
|
Str("errRename", errRename.Error()).
|
||||||
Msg("copied git object")
|
Msg("copied git object")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user