github.com/filecoin-project/bacalhau@v0.3.23-0.20230228154132-45c989550ace/pkg/verifier/results/results.go (about) 1 package results 2 3 import ( 4 "fmt" 5 "os" 6 7 "github.com/filecoin-project/bacalhau/pkg/storage/util" 8 "github.com/rs/zerolog/log" 9 ) 10 11 type Results struct { 12 // where do we copy the results from jobs temporarily? 13 ResultsDir string 14 } 15 16 func NewResults() (*Results, error) { 17 dir, err := os.MkdirTemp("", "bacalhau-results") 18 if err != nil { 19 return nil, err 20 } 21 return &Results{ 22 ResultsDir: dir, 23 }, nil 24 } 25 26 func (results *Results) GetShardResultsDir(jobID string, shardIndex int) string { 27 return fmt.Sprintf("%s/%s/%d", results.ResultsDir, jobID, shardIndex) 28 } 29 30 func (results *Results) EnsureShardResultsDir(jobID string, shardIndex int) (string, error) { 31 dir := results.GetShardResultsDir(jobID, shardIndex) 32 err := os.MkdirAll(dir, util.OS_ALL_RWX) 33 if err != nil { 34 return "", fmt.Errorf("error creating results dir %s: %w", dir, err) 35 } 36 info, err := os.Stat(dir) 37 if err != nil { 38 return "", fmt.Errorf("error getting results dir %s info: %w", dir, err) 39 } 40 log.Trace().Msgf("Created job results dir (%s). Permissions: %s", dir, info.Mode()) 41 return dir, err 42 } 43 44 func (results *Results) Close() error { 45 return os.RemoveAll(results.ResultsDir) 46 }