Commit 6c70ef3f authored by Trevor Slocum's avatar Trevor Slocum

Add --restrict-library option

parent c0dd5445
Pipeline #111789489 passed with stage
in 1 minute and 20 seconds
0.1.3:
- Allow keybindings to be configured
- Add --fd option
- Add --fd and --restrict-library options
0.1.2:
- Allow audio buffer size to be configured
......
......@@ -92,6 +92,16 @@ func browseFolder(browse string) {
mainBufferAutoFocus = ""
return
}
if !strings.HasPrefix(browse, restrictLibrary) {
statusText = "failed to browse folder: permission denied"
go func() {
time.Sleep(5 * time.Second)
statusText = ""
go app.QueueUpdateDraw(updateMain)
}()
go app.QueueUpdateDraw(updateMain)
return
}
placeCursorAtTop := mainBufferCursor == 0
mainBufferFiles = scanFolder(browse)
......
......@@ -34,6 +34,7 @@ var (
cpuProfile string
streamFdInt int
streamFd *os.File
restrictLibrary string
done = make(chan bool)
)
......@@ -48,6 +49,7 @@ func main() {
flag.StringVar(&configPath, "config", "", "path to configuration file")
flag.BoolVar(&printVersionInfo, "version", false, "print version information and exit")
flag.IntVar(&streamFdInt, "fd", -1, "stream audio to file descriptor")
flag.StringVar(&restrictLibrary, "restrict-library", "", "restrict library to path")
flag.DurationVar(&bufferSize, "buffer-size", defaultBufferSize, "audio buffer size")
flag.StringVar(&debugAddress, "debug-address", "", "address to serve debug info")
flag.StringVar(&cpuProfile, "cpu-profile", "", "path to save CPU profiling")
......@@ -58,6 +60,14 @@ func main() {
return
}
if restrictLibrary != "" {
var err error
restrictLibrary, err = filepath.Abs(restrictLibrary)
if err != nil {
log.Fatalf("failed to restrict library to %s: %s", restrictLibrary, err)
}
}
if debugAddress != "" {
go func() {
log.Fatal(http.ListenAndServe(debugAddress, nil))
......@@ -113,14 +123,18 @@ func main() {
startPath := strings.Join(flag.Args(), " ")
if startPath == "" {
wd, err := os.Getwd()
if err != nil || wd == "" {
homeDir, err := os.UserHomeDir()
if err == nil && homeDir != "" {
startPath = homeDir
if restrictLibrary == "" {
wd, err := os.Getwd()
if err != nil || wd == "" {
homeDir, err := os.UserHomeDir()
if err == nil && homeDir != "" {
startPath = homeDir
}
} else {
startPath = wd
}
} else {
startPath = wd
startPath = restrictLibrary
}
}
if startPath == "" {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment