Skip to content

Commit 6be40c6

Browse files
committed
Add underRepair for allocation
1 parent 8ca74e0 commit 6be40c6

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

zboxcore/sdk/allocation.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
var (
2727
noBLOBBERS = errors.New("No Blobbers set in this allocation")
2828
notInitialized = common.NewError("sdk_not_initialized", "Please call InitStorageSDK Init and use GetAllocation to get the allocation object")
29+
underRepair = common.NewError("allocaton_under_repair", "Allocation is under repair, Please try again later")
2930
)
3031

3132
type MetaOperation struct {
@@ -83,12 +84,21 @@ type Allocation struct {
8384
mutex *sync.Mutex
8485
downloadProgressMap map[string]*DownloadRequest
8586
initialized bool
87+
underRepair bool
88+
}
89+
90+
func (a *Allocation) UnderRepair() bool {
91+
return a.underRepair
8692
}
8793

8894
func (a *Allocation) GetStats() *AllocationStats {
8995
return a.Stats
9096
}
9197

98+
func (a *Allocation) UpdateRepairStatus(value bool) {
99+
a.underRepair = value
100+
}
101+
92102
func (a *Allocation) InitAllocation() {
93103
// if a.uploadChan != nil {
94104
// close(a.uploadChan)
@@ -173,6 +183,9 @@ func (a *Allocation) uploadOrUpdateFile(localpath string, remotepath string, sta
173183
if !a.isInitialized() {
174184
return notInitialized
175185
}
186+
if a.UnderRepair() {
187+
return underRepair
188+
}
176189
fileInfo, err := os.Stat(localpath)
177190
if err != nil {
178191
return fmt.Errorf("Local file error: %s", err.Error())
@@ -236,6 +249,9 @@ func (a *Allocation) downloadFile(localPath string, remotePath string, contentMo
236249
if !a.isInitialized() {
237250
return notInitialized
238251
}
252+
if a.UnderRepair() {
253+
return underRepair
254+
}
239255
if stat, err := os.Stat(localPath); err == nil {
240256
if !stat.IsDir() {
241257
return fmt.Errorf("Local path is not a directory '%s'", localPath)
@@ -437,6 +453,9 @@ func (a *Allocation) DeleteFile(path string) error {
437453
if !a.isInitialized() {
438454
return notInitialized
439455
}
456+
if a.UnderRepair() {
457+
return underRepair
458+
}
440459
if len(path) == 0 {
441460
return common.NewError("invalid_path", "Invalid path for the list")
442461
}
@@ -577,6 +596,9 @@ func (a *Allocation) downloadFromAuthTicket(localPath string, authTicket string,
577596
if !a.isInitialized() {
578597
return notInitialized
579598
}
599+
if a.UnderRepair() {
600+
return underRepair
601+
}
580602
sEnc, err := base64.StdEncoding.DecodeString(authTicket)
581603
if err != nil {
582604
return common.NewError("auth_ticket_decode_error", "Error decoding the auth ticket."+err.Error())

0 commit comments

Comments
 (0)