github.com/Cloud-Foundations/Dominator@v0.3.4/lib/objectserver/filesystem/check.go (about) 1 package filesystem 2 3 import ( 4 "fmt" 5 "os" 6 "path" 7 8 "github.com/Cloud-Foundations/Dominator/lib/hash" 9 "github.com/Cloud-Foundations/Dominator/lib/objectcache" 10 ) 11 12 func (objSrv *ObjectServer) checkObjects(hashes []hash.Hash) ([]uint64, error) { 13 sizesList := make([]uint64, len(hashes)) 14 for index, hash := range hashes { 15 var err error 16 sizesList[index], err = objSrv.checkObject(hash) 17 if err != nil { 18 return nil, err 19 } 20 } 21 return sizesList, nil 22 } 23 24 func (objSrv *ObjectServer) checkObject(hashVal hash.Hash) (uint64, error) { 25 objSrv.rwLock.RLock() 26 object, ok := objSrv.objects[hashVal] 27 objSrv.rwLock.RUnlock() 28 if ok { 29 return object.size, nil 30 } 31 filename := path.Join(objSrv.BaseDirectory, 32 objectcache.HashToFilename(hashVal)) 33 fi, err := os.Lstat(filename) 34 if err != nil { 35 return 0, nil 36 } 37 if fi.Mode().IsRegular() { 38 if fi.Size() < 1 { 39 return 0, fmt.Errorf("zero length file: %s", filename) 40 } 41 return uint64(fi.Size()), nil 42 } 43 return 0, nil 44 }