github.com/Cloud-Foundations/Dominator@v0.3.4/sub/rpcd/cleanup.go (about) 1 package rpcd 2 3 import ( 4 "errors" 5 "path" 6 7 "github.com/Cloud-Foundations/Dominator/lib/fsutil" 8 "github.com/Cloud-Foundations/Dominator/lib/objectcache" 9 "github.com/Cloud-Foundations/Dominator/lib/srpc" 10 "github.com/Cloud-Foundations/Dominator/proto/sub" 11 ) 12 13 func (t *rpcType) Cleanup(conn *srpc.Conn, request sub.CleanupRequest, 14 reply *sub.CleanupResponse) error { 15 defer t.params.ScannerConfiguration.BoostCpuLimit(t.params.Logger) 16 t.params.DisableScannerFunction(true) 17 defer t.params.DisableScannerFunction(false) 18 t.rwLock.Lock() 19 defer t.rwLock.Unlock() 20 t.params.Logger.Printf("Cleanup(): %d objects\n", len(request.Hashes)) 21 if t.fetchInProgress { 22 t.params.Logger.Println("Error: fetch in progress") 23 return errors.New("fetch in progress") 24 } 25 if t.updateInProgress { 26 t.params.Logger.Println("Error: update progress") 27 return errors.New("update in progress") 28 } 29 for _, hash := range request.Hashes { 30 pathname := path.Join(t.config.ObjectsDirectoryName, 31 objectcache.HashToFilename(hash)) 32 var err error 33 t.params.WorkdirGoroutine.Run(func() { 34 err = fsutil.ForceRemove(pathname) 35 }) 36 if err == nil { 37 t.params.Logger.Printf("Deleted: %s\n", pathname) 38 } else { 39 t.params.Logger.Println(err) 40 } 41 } 42 t.disruptionCancel() 43 return nil 44 }