Handle filenames with special characters #131
This commit is contained in:
parent
bdb24d2600
commit
31d5f30637
@ -380,6 +380,11 @@ func (i *Indexer) IndexAll() map[string]bool {
|
|||||||
indexed := make(map[string]bool)
|
indexed := make(map[string]bool)
|
||||||
|
|
||||||
err := filepath.Walk(i.originalsPath(), func(filename string, fileInfo os.FileInfo, err error) error {
|
err := filepath.Walk(i.originalsPath(), func(filename string, fileInfo os.FileInfo, err error) error {
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
log.Printf("Could not index file %s due to an unexpected error: %s", filename, err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
if err != nil || indexed[filename] {
|
if err != nil || indexed[filename] {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"sort"
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -269,7 +270,8 @@ func (m *MediaFile) EditedFilename() string {
|
|||||||
// RelatedFiles returns files which are related to this file.
|
// RelatedFiles returns files which are related to this file.
|
||||||
func (m *MediaFile) RelatedFiles() (result MediaFiles, mainFile *MediaFile, err error) {
|
func (m *MediaFile) RelatedFiles() (result MediaFiles, mainFile *MediaFile, err error) {
|
||||||
baseFilename := m.DirectoryBasename()
|
baseFilename := m.DirectoryBasename()
|
||||||
|
// escape any meta characters in the file name
|
||||||
|
baseFilename = regexp.QuoteMeta(baseFilename)
|
||||||
matches, err := filepath.Glob(baseFilename + "*")
|
matches, err := filepath.Glob(baseFilename + "*")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user