func addMp3(ds *dataset.Dataset, filename string) { id3, err := id3go.Open(filename) if err != nil { log.Fatalf("Failed to read id3 data from %s: %s\n", filename, err) } defer id3.Close() mp3_file, err := os.Open(filename) if err != nil { log.Fatalf("Failed to open %s: %s\n", filename, err) } defer mp3_file.Close() new_song := SongDef{ Title: id3.Title(), Artist: id3.Artist(), Album: id3.Album(), Year: id3.Year(), Mp3: types.NewBlob(bufio.NewReader(mp3_file)), }.New() songs := readSongsFromDataset(ds).Append(new_song) if _, err := ds.Commit(songs); err == nil { fmt.Println("Successfully committed", filename) printSong(new_song) } else { log.Fatalf("Failed to commit: %s, error: %s\n", filename, err) } }
func generate(packageName, in, out, outDir string, written map[string]bool, parsed pkg.Parsed, localPkgs refSet, pkgDS dataset.Dataset) dataset.Dataset { // Generate code for all p's deps first. deps := generateDepCode(packageName, outDir, written, parsed.Package, localPkgs, pkgDS.Store()) generateAndEmit(getBareFileName(in), out, written, deps, parsed) // Since we're just building up a set of refs to all the packages in pkgDS, simply retrying is the logical response to commit failure. err := datas.ErrOptimisticLockFailed for ; err == datas.ErrOptimisticLockFailed; pkgDS, err = pkgDS.Commit(buildSetOfRefOfPackage(parsed, deps, pkgDS)) { } return pkgDS }