Browse Source

Add --restrict-library option

master
Trevor Slocum 3 years ago
parent
commit
6c70ef3ffb
  1. 2
      CHANGELOG
  2. 10
      gui.go
  3. 26
      main.go

2
CHANGELOG

@ -1,6 +1,6 @@
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

10
gui.go

@ -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)

26
main.go

@ -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 == "" {

Loading…
Cancel
Save