Import/Convert: Improve symbolic link handling to support files #1049
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
parent
d0e3ddc1b9
commit
a73ee48213
|
@ -88,7 +88,7 @@ func (c *Convert) Start(path string, force bool) (err error) {
|
||||||
return errors.New("canceled")
|
return errors.New("canceled")
|
||||||
}
|
}
|
||||||
|
|
||||||
isDir := info.IsDir()
|
isDir, _ := info.IsDirOrSymlinkToDir()
|
||||||
isSymlink := info.IsSymlink()
|
isSymlink := info.IsSymlink()
|
||||||
|
|
||||||
if skip, result := fs.SkipWalk(fileName, isDir, isSymlink, done, ignore); skip {
|
if skip, result := fs.SkipWalk(fileName, isDir, isSymlink, done, ignore); skip {
|
||||||
|
|
|
@ -130,20 +130,22 @@ func (imp *Import) Start(opt ImportOptions) fs.Done {
|
||||||
return errors.New("canceled")
|
return errors.New("canceled")
|
||||||
}
|
}
|
||||||
|
|
||||||
isDir := info.IsDir()
|
isDir, _ := info.IsDirOrSymlinkToDir()
|
||||||
isSymlink := info.IsSymlink()
|
isSymlink := info.IsSymlink()
|
||||||
|
|
||||||
if skip, result := fs.SkipWalk(fileName, isDir, isSymlink, done, ignore); skip {
|
if skip, result := fs.SkipWalk(fileName, isDir, isSymlink, done, ignore); skip {
|
||||||
if isDir && result != filepath.SkipDir {
|
if !isDir || result == filepath.SkipDir {
|
||||||
if fileName != importPath {
|
return result
|
||||||
directories = append(directories, fileName)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
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 {
|
folder := entity.NewFolder(entity.RootImport, fs.RelName(fileName, imp.conf.ImportPath()), fs.BirthTime(fileName))
|
||||||
log.Infof("import: added folder /%s", folder.Path)
|
|
||||||
}
|
if err := folder.Create(); err == nil {
|
||||||
|
log.Infof("import: added folder /%s", folder.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -158,20 +158,22 @@ func (ind *Index) Start(o IndexOptions) fs.Done {
|
||||||
|
|
||||||
// Skip directories and known files.
|
// Skip directories and known files.
|
||||||
if skip, result := fs.SkipWalk(fileName, isDir, isSymlink, done, ignore); skip {
|
if skip, result := fs.SkipWalk(fileName, isDir, isSymlink, done, ignore); skip {
|
||||||
if isDir {
|
if !isDir {
|
||||||
if result != filepath.SkipDir {
|
return result
|
||||||
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 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
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,7 +81,7 @@ func (w *Resample) Start(force bool) (err error) {
|
||||||
return errors.New("canceled")
|
return errors.New("canceled")
|
||||||
}
|
}
|
||||||
|
|
||||||
isDir := info.IsDir()
|
isDir, _ := info.IsDirOrSymlinkToDir()
|
||||||
isSymlink := info.IsSymlink()
|
isSymlink := info.IsSymlink()
|
||||||
|
|
||||||
if skip, result := fs.SkipWalk(fileName, isDir, isSymlink, done, ignore); skip {
|
if skip, result := fs.SkipWalk(fileName, isDir, isSymlink, done, ignore); skip {
|
||||||
|
|
|
@ -20,7 +20,7 @@ func SkipWalk(fileName string, isDir, isSymlink bool, done Done, ignore *IgnoreL
|
||||||
if err != nil || isIgnored || isDone || done[resolved].Exists() {
|
if err != nil || isIgnored || isDone || done[resolved].Exists() {
|
||||||
result = filepath.SkipDir
|
result = filepath.SkipDir
|
||||||
} else {
|
} else {
|
||||||
// Don't traverse symlinks if they are hidden or already done...
|
// Flag the symlink target as processed.
|
||||||
done[resolved] = Found
|
done[resolved] = Found
|
||||||
}
|
}
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
|
|
|
@ -63,7 +63,7 @@ func TestSkipWalk(t *testing.T) {
|
||||||
|
|
||||||
err := godirwalk.Walk(testPath, &godirwalk.Options{
|
err := godirwalk.Walk(testPath, &godirwalk.Options{
|
||||||
Callback: func(fileName string, info *godirwalk.Dirent) error {
|
Callback: func(fileName string, info *godirwalk.Dirent) error {
|
||||||
isDir := info.IsDir()
|
isDir, _ := info.IsDirOrSymlinkToDir()
|
||||||
isSymlink := info.IsSymlink()
|
isSymlink := info.IsSymlink()
|
||||||
|
|
||||||
if skip, result := SkipWalk(fileName, isDir, isSymlink, done, ignore); skip {
|
if skip, result := SkipWalk(fileName, isDir, isSymlink, done, ignore); skip {
|
||||||
|
|
Loading…
Reference in a new issue