Commit 1d51f656 authored by Trevor Slocum's avatar Trevor Slocum

Follow symbolic links

parent f6ba3f5f
Pipeline #149200092 passed with stages
in 2 minutes and 34 seconds
......@@ -2,6 +2,7 @@
- Add scrollbar to lists
- Add --disable-mouse option
- Center playing entry in queue
- Follow symbolic links
0.1.6:
- Add mouse support to queue
......
......@@ -190,7 +190,7 @@ func nextTrack() {
queueNext()
entry := selectedQueueEntry()
audioFile, err := openFile(entry.Path, entry.Metadata)
audioFile, err := openFile(entry.RealPath, entry.Metadata)
if err != nil {
statusText = err.Error()
go func() {
......
......@@ -14,10 +14,10 @@ require (
github.com/mewkiz/pkg v0.0.0-20200411195739-f6b5e26764c3 // indirect
github.com/pkg/errors v0.9.1 // indirect
gitlab.com/tslocum/cbind v0.1.1
gitlab.com/tslocum/cview v1.4.7-0.20200520223619-698a0adf93dd
gitlab.com/tslocum/cview v1.4.7-0.20200525044034-961c23145cae
golang.org/x/exp v0.0.0-20200513190911-00229845015e // indirect
golang.org/x/image v0.0.0-20200430140353-33d19683fad8 // indirect
golang.org/x/mobile v0.0.0-20200329125638-4c31acba0007 // indirect
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 // indirect
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect
gopkg.in/yaml.v2 v2.3.0
)
......@@ -59,6 +59,8 @@ gitlab.com/tslocum/cbind v0.1.1 h1:JXXtxMWHgWLvoF+QkrvcNvOQ59juy7OE1RhT7hZfdt0=
gitlab.com/tslocum/cbind v0.1.1/go.mod h1:rX7vkl0pUSg/yy427MmD1FZAf99S7WwpUlxF/qTpPqk=
gitlab.com/tslocum/cview v1.4.7-0.20200520223619-698a0adf93dd h1:XbQrX2nkpZ50i0m0o+qf+zajtA9Z2ohOZNuaCCU8Ayk=
gitlab.com/tslocum/cview v1.4.7-0.20200520223619-698a0adf93dd/go.mod h1:PW2Ucec7oTYOfK4N+hqm/CKEN9B1PBidq5YJ3ZaeknU=
gitlab.com/tslocum/cview v1.4.7-0.20200525044034-961c23145cae h1:Q+q83u8BI8N908q1ogBQrK3j2k6/ILRHmpivc8LKl3k=
gitlab.com/tslocum/cview v1.4.7-0.20200525044034-961c23145cae/go.mod h1:87HOuFUfgmyY0zfg+7qKg6jyN9gI/znsa/KE2ZZHDSs=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
......@@ -98,8 +100,8 @@ golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9 h1:YTzHMGlqJu67/uEo1lBv0n3wBXhXNeUbB1XfN2vmTm0=
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 h1:DYfZAGf2WMFjMxbgTjaC+2HC7NkNAQs+6Q8b9WEB/F4=
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200523222454-059865788121 h1:rITEj+UZHYC927n8GT97eC3zrpzXdb/voyeOuVKS46o=
golang.org/x/sys v0.0.0-20200523222454-059865788121/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
......
......@@ -157,7 +157,7 @@ func browseFolder(browse string) {
autoSelect := -1
var entryPath string
for i, entry := range mainFiles {
if !entry.File.IsDir() {
if !entry.File.IsDir() && entry.File.Mode()&os.ModeSymlink == 0 {
continue
}
......@@ -240,7 +240,7 @@ func updateMain() {
for _, entry := range mainFiles {
//length = ""
if entry.File.IsDir() {
if entry.File.IsDir() || entry.File.Mode()&os.ModeSymlink != 0 {
line = strings.TrimSpace(entry.File.Name()) + "/"
} else {
line = entry.String()
......
package main
import (
"os"
"path"
"time"
......@@ -57,12 +58,12 @@ func listSelect(cursor int) {
}
entry := mainFiles[cursor-1]
if entry.File.IsDir() {
browseFolder(entry.Path)
if entry.File.IsDir() || entry.File.Mode()&os.ModeSymlink != 0 {
browseFolder(entry.RealPath)
return
}
audioFile, err := openFile(entry.Path, entry.Metadata)
audioFile, err := openFile(entry.RealPath, entry.Metadata)
if err != nil {
statusText = err.Error()
go func() {
......@@ -84,11 +85,11 @@ func queueSelect(cursor int) {
}
entry := queueFiles[cursor]
if entry.File.IsDir() {
if entry.File.IsDir() || entry.File.Mode()&os.ModeSymlink != 0 {
return
}
audioFile, err := openFile(entry.Path, entry.Metadata)
audioFile, err := openFile(entry.RealPath, entry.Metadata)
if err != nil {
statusText = err.Error()
go func() {
......@@ -113,8 +114,8 @@ func listQueue() {
entry := selectedMainEntry()
if entry == nil {
return
} else if entry.File.IsDir() {
scanFiles := scanFolderRecursively(entry.Path)
} else if entry.File.IsDir() || entry.File.Mode()&os.ModeSymlink != 0 {
scanFiles := scanFolderRecursively(entry.RealPath)
queueLock.Lock()
queueFiles = append(queueFiles, scanFiles...)
......
......@@ -54,6 +54,7 @@ func readMetadata(f *os.File) *metadata {
type libraryEntry struct {
File os.FileInfo
Path string
RealPath string
Metadata *metadata
}
......@@ -78,11 +79,25 @@ func scanFolder(scanPath string) []*libraryEntry {
var entries []*libraryEntry
for _, fileInfo := range files {
p := path.Join(scanPath, fileInfo.Name())
var r string
b := path.Base(fileInfo.Name())
if fileInfo.IsDir() {
if fileInfo.Mode()&os.ModeSymlink != 0 {
r, err = os.Readlink(p)
if err != nil {
continue
}
if !path.IsAbs(r) {
r = path.Join(scanPath, r)
}
} else {
r = p
}
b := path.Base(p)
if fileInfo.IsDir() || fileInfo.Mode()&os.ModeSymlink != 0 {
if b != "" && (b[0] != '.' || showHiddenFolders) {
entries = append(entries, &libraryEntry{File: fileInfo, Path: p, Metadata: &metadata{Title: strings.TrimSpace(fileInfo.Name())}})
entries = append(entries, &libraryEntry{File: fileInfo, Path: p, RealPath: r, Metadata: &metadata{Title: strings.TrimSpace(fileInfo.Name())}})
}
continue
......@@ -90,19 +105,21 @@ func scanFolder(scanPath string) []*libraryEntry {
continue
}
f, err := os.Open(p)
f, err := os.Open(r)
if err != nil {
continue
}
metadata := readMetadata(f)
f.Close()
entries = append(entries, &libraryEntry{File: fileInfo, Path: p, Metadata: metadata})
entries = append(entries, &libraryEntry{File: fileInfo, Path: p, RealPath: r, Metadata: metadata})
}
sort.Slice(entries, func(i, j int) bool {
if entries[i].File.IsDir() != entries[j].File.IsDir() {
return entries[i].File.IsDir()
iDir := entries[i].File.IsDir() || entries[i].File.Mode()&os.ModeSymlink != 0
jDir := entries[j].File.IsDir() || entries[j].File.Mode()&os.ModeSymlink != 0
if iDir != jDir {
return iDir
}
if entries[i].Metadata.Album != "" && strings.ToLower(entries[i].Metadata.Album) == strings.ToLower(entries[j].Metadata.Album) && (entries[i].Metadata.Track > 0 || entries[j].Metadata.Track > 0) {
......@@ -120,14 +137,14 @@ func scanFolderRecursively(path string) []*libraryEntry {
scanFiles := scanFolder(path)
for _, entry := range scanFiles {
if !entry.File.IsDir() {
if !entry.File.IsDir() && entry.File.Mode()&os.ModeSymlink == 0 {
continue
}
entries = append(entries, scanFolderRecursively(entry.Path)...)
entries = append(entries, scanFolderRecursively(entry.RealPath)...)
}
for _, entry := range scanFiles {
if entry.File.IsDir() {
if entry.File.IsDir() || entry.File.Mode()&os.ModeSymlink != 0 {
continue
}
......
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