github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/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.scannerConfiguration.BoostCpuLimit(t.logger) 16 t.disableScannerFunc(true) 17 defer t.disableScannerFunc(false) 18 t.rwLock.Lock() 19 defer t.rwLock.Unlock() 20 t.logger.Printf("Cleanup(): %d objects\n", len(request.Hashes)) 21 if t.fetchInProgress { 22 t.logger.Println("Error: fetch in progress") 23 return errors.New("fetch in progress") 24 } 25 if t.updateInProgress { 26 t.logger.Println("Error: update progress") 27 return errors.New("update in progress") 28 } 29 for _, hash := range request.Hashes { 30 pathname := path.Join(t.objectsDir, objectcache.HashToFilename(hash)) 31 err := fsutil.ForceRemove(pathname) 32 if err == nil { 33 t.logger.Printf("Deleted: %s\n", pathname) 34 } else { 35 t.logger.Println(err) 36 } 37 } 38 return nil 39 }