mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix(hostman): recycle local disk file when rebuilding root
This commit is contained in:
@@ -71,7 +71,7 @@ func AddDiskHandler(prefix string, app *appsrv.Application) {
|
||||
|
||||
app.AddHandler("POST",
|
||||
fmt.Sprintf("%s/%s/<storageId>/<action>/<diskId>", prefix, keyWord),
|
||||
auth.Authenticate(perfomrDiskActions))
|
||||
auth.Authenticate(performDiskActions))
|
||||
app.AddHandler("GET",
|
||||
fmt.Sprintf("%s/%s/<storageId>/<diskId>/status", prefix, keyWord),
|
||||
auth.Authenticate(getDiskStatus))
|
||||
@@ -206,7 +206,7 @@ func saveToGlance(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
hostutils.ResponseOk(ctx, w)
|
||||
}
|
||||
|
||||
func perfomrDiskActions(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
func performDiskActions(ctx context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
params, _, body := appsrv.FetchEnv(ctx, w, r)
|
||||
if body == nil {
|
||||
body = jsonutils.NewDict()
|
||||
@@ -230,7 +230,8 @@ func perfomrDiskActions(ctx context.Context, w http.ResponseWriter, r *http.Requ
|
||||
var disk storageman.IDisk
|
||||
var err error
|
||||
|
||||
if action != "create" {
|
||||
rebuild, _ := body.Bool("disk", "rebuild")
|
||||
if action != "create" || rebuild {
|
||||
disk, err = storage.GetDiskById(diskId)
|
||||
if err != nil {
|
||||
hostutils.Response(ctx, w, httperrors.NewGeneralError(errors.Wrapf(err, "GetDiskById(%s)", diskId)))
|
||||
|
||||
@@ -192,10 +192,13 @@ func (s *SLocalStorage) DeleteDiskfile(diskpath string) error {
|
||||
destFile = fmt.Sprintf("%s.%d", path.Base(diskpath), time.Now().Unix())
|
||||
)
|
||||
if err := procutils.NewCommand("mkdir", "-p", destDir).Run(); err != nil {
|
||||
log.Errorf("Fail to mkdir %s for recycle: %s", destDir, err)
|
||||
return err
|
||||
}
|
||||
log.Infof("Move deleted disk file %s to recycle %s", diskpath, destDir)
|
||||
return procutils.NewCommand("mv", "-f", diskpath, path.Join(destDir, destFile)).Run()
|
||||
} else {
|
||||
log.Infof("Delete disk file %s immediately", diskpath)
|
||||
return procutils.NewCommand("rm", "-rf", diskpath).Run()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user