github.com/Cloud-Foundations/Dominator@v0.3.4/lib/filesystem/scanner/getObject.go (about) 1 package scanner 2 3 import ( 4 "fmt" 5 "io" 6 "os" 7 "path" 8 9 "github.com/Cloud-Foundations/Dominator/lib/hash" 10 ) 11 12 func (fs *FileSystem) getObject(hashVal hash.Hash) ( 13 uint64, io.ReadCloser, error) { 14 inodes, ok := fs.HashToInodesTable()[hashVal] 15 if !ok { 16 return 0, nil, fmt.Errorf("object not found: %v\n", hashVal) 17 } 18 filename := path.Join(fs.rootDirectoryName, 19 fs.InodeToFilenamesTable()[inodes[0]][0]) 20 file, err := os.Open(filename) 21 if err != nil { 22 return 0, nil, err 23 } 24 fi, err := file.Stat() 25 if err != nil { 26 file.Close() 27 return 0, nil, err 28 } 29 return uint64(fi.Size()), file, nil 30 }