Backend: Fix import / index bugs

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-01-04 07:56:56 +01:00
parent 1ef1efe628
commit e27835fb21
4 changed files with 32 additions and 11 deletions

View file

@ -47,19 +47,21 @@ func StartImport(router *gin.RouterGroup, conf *config.Config) {
start := time.Now() start := time.Now()
path := conf.ImportPath() path := conf.ImportPath()
if subPath = c.Param("path"); subPath != "" { if subPath = c.Param("path"); subPath != "" && subPath != "/" {
subPath = strings.Replace(subPath, ".", "", -1) subPath = strings.Replace(subPath, ".", "", -1)
log.Debugf("import sub path: %s", subPath) log.Debugf("import sub path: %s", subPath)
path = path + subPath path = path + subPath
} }
path = filepath.Clean(path)
event.Info(fmt.Sprintf("importing photos from \"%s\"", filepath.Base(path))) event.Info(fmt.Sprintf("importing photos from \"%s\"", filepath.Base(path)))
initImport(conf) initImport(conf)
imp.Start(path) imp.Start(path)
if subPath != "" && util.DirectoryIsEmpty(path) { if subPath != "" && path != conf.ImportPath() && util.DirectoryIsEmpty(path) {
if err := os.Remove(path); err != nil { if err := os.Remove(path); err != nil {
log.Errorf("import: could not deleted empty directory \"%s\": %s", path, err) log.Errorf("import: could not deleted empty directory \"%s\": %s", path, err)
} else { } else {

View file

@ -114,17 +114,17 @@ func (c *Config) LogFilename() string {
// OriginalsPath returns the originals. // OriginalsPath returns the originals.
func (c *Config) OriginalsPath() string { func (c *Config) OriginalsPath() string {
return c.config.OriginalsPath return filepath.Clean(c.config.OriginalsPath)
} }
// ImportPath returns the import directory. // ImportPath returns the import directory.
func (c *Config) ImportPath() string { func (c *Config) ImportPath() string {
return c.config.ImportPath return filepath.Clean(c.config.ImportPath)
} }
// ExportPath returns the export directory. // ExportPath returns the export directory.
func (c *Config) ExportPath() string { func (c *Config) ExportPath() string {
return c.config.ExportPath return filepath.Clean(c.config.ExportPath)
} }
// SipsBin returns the sips binary file name. // SipsBin returns the sips binary file name.

View file

@ -102,6 +102,7 @@ func (imp *Import) Start(importPath string) {
if filename != importPath { if filename != importPath {
directories = append(directories, filename) directories = append(directories, filename)
} }
return nil return nil
} }
@ -114,13 +115,13 @@ func (imp *Import) Start(importPath string) {
return nil return nil
} }
mediaFile, err := NewMediaFile(filename) mf, err := NewMediaFile(filename)
if err != nil || !mediaFile.IsPhoto() { if err != nil || !mf.IsPhoto() {
return nil return nil
} }
related, err := mediaFile.RelatedFiles() related, err := mf.RelatedFiles()
if err != nil { if err != nil {
event.Error(fmt.Sprintf("import: %s", err.Error())) event.Error(fmt.Sprintf("import: %s", err.Error()))
@ -128,10 +129,19 @@ func (imp *Import) Start(importPath string) {
return nil return nil
} }
var files MediaFiles
for _, f := range related.files { for _, f := range related.files {
if done[f.Filename()] { continue }
files = append(files, f)
done[f.Filename()] = true done[f.Filename()] = true
} }
done[mf.Filename()] = true
related.files = files
jobs <- ImportJob{ jobs <- ImportJob{
related: related, related: related,
opt: options, opt: options,

View file

@ -103,13 +103,13 @@ func (ind *Index) Start(options IndexOptions) map[string]bool {
return nil return nil
} }
mediaFile, err := NewMediaFile(filename) mf, err := NewMediaFile(filename)
if err != nil || !mediaFile.IsPhoto() { if err != nil || !mf.IsPhoto() {
return nil return nil
} }
related, err := mediaFile.RelatedFiles() related, err := mf.RelatedFiles()
if err != nil { if err != nil {
log.Warnf("index: %s", err.Error()) log.Warnf("index: %s", err.Error())
@ -117,10 +117,19 @@ func (ind *Index) Start(options IndexOptions) map[string]bool {
return nil return nil
} }
var files MediaFiles
for _, f := range related.files { for _, f := range related.files {
if done[f.Filename()] { continue }
files = append(files, f)
done[f.Filename()] = true done[f.Filename()] = true
} }
done[mf.Filename()] = true
related.files = files
jobs <- IndexJob{ jobs <- IndexJob{
related: related, related: related,
opt: options, opt: options,