Skip to content

Commit

Permalink
feat (manager): add delete data source tmp file at the end of the del…
Browse files Browse the repository at this point in the history
…etion

Ref: longhorn 3682

Signed-off-by: Jack Lin <jack.lin@suse.com>
(cherry picked from commit 455f018)
  • Loading branch information
ChanYiLin authored and innobead committed Mar 17, 2023
1 parent 58ef336 commit ff0be19
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/manager/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,15 @@ func (m *Manager) Delete(ctx context.Context, req *rpc.DeleteRequest) (resp *emp
log.Info("Backing Image Manager: prepare to delete backing image")
defer func() {
if err != nil {
log.WithError(err).Error("Backing Image Manager: failed to delete backing image, will continue to do directory cleanup anyway")
log.WithError(err).Warn("Backing Image Manager: failed to delete backing image, will continue to do directory cleanup anyway")
}
if rmDirErr := os.RemoveAll(types.GetBackingImageDirectory(m.diskPath, req.Name, req.Uuid)); rmDirErr != nil {
log.WithError(rmDirErr).Errorf("Backing Image Manager: failed to remove the backing image work directory at the end of the deletion")
log.WithError(rmDirErr).Warn("Backing Image Manager: failed to remove the backing image work directory at the end of the deletion")
}
// Delete cmd is used to remove the tmp file left on the host as well when preparing backing image file failed.
tmpFilePath := fmt.Sprintf("%s%s", types.GetDataSourceFilePath(m.diskPath, req.Name, req.Uuid), types.TmpFileSuffix)
if rmTmpFileErr := os.RemoveAll(tmpFilePath); rmTmpFileErr != nil {
log.WithError(rmTmpFileErr).Warn("Backing Image Manager: failed to remove the data source tmp file at the end of the deletion")
}
}()

Expand Down
1 change: 1 addition & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
StateStarting = State("starting")
StateInProgress = State("in-progress")
StateFailed = State("failed")
StateFailedAndCleanUp = State("failed-and-cleanup")
StateUnknown = State("unknown")
StateReady = State("ready")
StateReadyForTransfer = State("ready-for-transfer")
Expand Down

0 comments on commit ff0be19

Please sign in to comment.