-
Notifications
You must be signed in to change notification settings - Fork 0
/
fakelib.go
83 lines (71 loc) · 1.98 KB
/
fakelib.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"flag"
"fmt"
"io"
"log"
"os"
"os/signal"
"github.com/joshkunz/fakelib/filesystem"
"github.com/joshkunz/fakelib/library"
)
var (
librarySize = flag.Int("library_size", 1000, "Number of songs to include in the library")
minPathLength = flag.Int("min_path_length", 3, "The minimum number of non-separator bytes in the generated paths")
tracksPerAlbum = flag.Int("tracks_per_album", 10, "Max number of tracks in each album")
albumsPerArtist = flag.Int("albums_per_artist", 3, "Max number of albums for each artist")
)
func main() {
flag.Parse()
if len(flag.Args()) < 1 {
log.Fatalf("usage: %s golden.mp3 mount/", os.Args[0])
}
if *minPathLength < 3 {
log.Fatalf("--min_path_length must be at least 3")
}
var goldenPath, mountDir string
if len(flag.Args()) < 2 {
mountDir = flag.Arg(0)
} else {
goldenPath, mountDir = flag.Arg(0), flag.Arg(1)
}
var golden io.ReadSeeker
if goldenPath != "" {
var err error
golden, err = os.Open(goldenPath)
if err != nil {
log.Fatalf("failed to open golden file %q: %v", goldenPath, err)
}
defer golden.(*os.File).Close()
} else {
golden = library.EmbeddedGoldMP3()
}
lib, err := library.New(golden)
if err != nil {
log.Fatalf("failed to load golden file %q: %v", goldenPath, err)
}
lib.Tracks = *librarySize
lib.Tagger = library.RepeatedLetters{
TracksPerAlbum: *tracksPerAlbum,
AlbumsPerArtist: *albumsPerArtist,
MinComponentLength: *minPathLength / 3,
}.Tag
if _, err := os.Stat(mountDir); os.IsNotExist(err) {
os.Mkdir(mountDir, 0755)
} else if err != nil {
log.Fatalf("failed to stat %q: %v", mountDir, err)
}
server, err := filesystem.Mount(lib, mountDir, nil)
if err != nil {
log.Fatal(err)
}
fmt.Printf("filesystem mounted at %q\n", mountDir)
// Wait for our process to be interrupted.
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt)
<-c
if err := server.Unmount(); err != nil {
log.Fatal(err)
}
fmt.Printf("filesystem unmounted from %q\n", mountDir)
}