src/services/repairs.go
BeforeProposed
+21−4
11package services
22
3import "archivefixity/src/models"
3import (
4 "archivefixity/src/models"
5 "sort"
6)
47
8// Plans describe copy operations; the service never writes to an archive.
59func Plan(locations, healthy []string, copies int) ([]models.Copy,int) {
6 // TODO: propose safe copies and remaining shortfall.
10 repairs:=[]models.Copy{}
711 needed:=copies-len(healthy)
8 if needed<0 { needed=0 }
9 return []models.Copy{},needed
12 if needed<=0 { return repairs,0 }
13 if len(healthy)==0 { return repairs,needed }
14 sources:=append([]string{},healthy...)
15 sort.Strings(sources)
16 destinations:=append([]string{},locations...)
17 sort.Strings(destinations)
18 good:=map[string]bool{}
19 for _, location:=range healthy { good[location]=true }
20 for _, location:=range destinations {
21 if needed==0 { break }
22 if good[location] { continue }
23 repairs=append(repairs,models.Copy{From:sources[0],To:location})
24 needed--
25 }
26 return repairs,needed
1027}