Import/Convert: Improve symbolic link handling to support files #1049

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer 2022-07-07 19:54:22 +02:00
parent d0e3ddc1b9
commit a73ee48213
6 changed files with 29 additions and 25 deletions

View file

@ -88,7 +88,7 @@ func (c *Convert) Start(path string, force bool) (err error) {
return errors.New("canceled")
}
isDir := info.IsDir()
isDir, _ := info.IsDirOrSymlinkToDir()
isSymlink := info.IsSymlink()
if skip, result := fs.SkipWalk(fileName, isDir, isSymlink, done, ignore); skip {

View file

@ -130,20 +130,22 @@ func (imp *Import) Start(opt ImportOptions) fs.Done {
return errors.New("canceled")
}
isDir := info.IsDir()
isDir, _ := info.IsDirOrSymlinkToDir()
isSymlink := info.IsSymlink()
if skip, result := fs.SkipWalk(fileName, isDir, isSymlink, done, ignore); skip {
if isDir && result != filepath.SkipDir {
if fileName != importPath {
directories = append(directories, fileName)
}
if !isDir || result == filepath.SkipDir {
return result
}
folder := entity.NewFolder(entity.RootImport, fs.RelName(fileName, imp.conf.ImportPath()), fs.BirthTime(fileName))
if fileName != importPath {
directories = append(directories, fileName)
}
if err := folder.Create(); err == nil {
log.Infof("import: added folder /%s", folder.Path)
}
folder := entity.NewFolder(entity.RootImport, fs.RelName(fileName, imp.conf.ImportPath()), fs.BirthTime(fileName))
if err := folder.Create(); err == nil {
log.Infof("import: added folder /%s", folder.Path)
}
return result

View file

@ -158,20 +158,22 @@ func (ind *Index) Start(o IndexOptions) fs.Done {
// Skip directories and known files.
if skip, result := fs.SkipWalk(fileName, isDir, isSymlink, done, ignore); skip {
if isDir {
if result != filepath.SkipDir {
folder := entity.NewFolder(entity.RootOriginals, relName, fs.BirthTime(fileName))
if err := folder.Create(); err == nil {
log.Infof("index: added folder /%s", folder.Path)
}
}
event.Publish("index.folder", event.Data{
"filePath": relName,
})
if !isDir {
return result
}
if result != filepath.SkipDir {
folder := entity.NewFolder(entity.RootOriginals, relName, fs.BirthTime(fileName))
if err := folder.Create(); err == nil {
log.Infof("index: added folder /%s", folder.Path)
}
}
event.Publish("index.folder", event.Data{
"filePath": relName,
})
return result
}

View file

@ -81,7 +81,7 @@ func (w *Resample) Start(force bool) (err error) {
return errors.New("canceled")
}
isDir := info.IsDir()
isDir, _ := info.IsDirOrSymlinkToDir()
isSymlink := info.IsSymlink()
if skip, result := fs.SkipWalk(fileName, isDir, isSymlink, done, ignore); skip {

View file

@ -20,7 +20,7 @@ func SkipWalk(fileName string, isDir, isSymlink bool, done Done, ignore *IgnoreL
if err != nil || isIgnored || isDone || done[resolved].Exists() {
result = filepath.SkipDir
} else {
// Don't traverse symlinks if they are hidden or already done...
// Flag the symlink target as processed.
done[resolved] = Found
}
} else if err != nil {

View file

@ -63,7 +63,7 @@ func TestSkipWalk(t *testing.T) {
err := godirwalk.Walk(testPath, &godirwalk.Options{
Callback: func(fileName string, info *godirwalk.Dirent) error {
isDir := info.IsDir()
isDir, _ := info.IsDirOrSymlinkToDir()
isSymlink := info.IsSymlink()
if skip, result := SkipWalk(fileName, isDir, isSymlink, done, ignore); skip {