Treat symlinks to directories like directories

This allows symlinking to create additional subalbums.

Closes: #431
This commit is contained in:
Marco Herrn
2021-07-15 16:16:05 +02:00
parent 2e4f83abbf
commit 0129cb7703
4 changed files with 125 additions and 2 deletions

View File

@@ -181,7 +181,13 @@ func findMediaForAlbum(album *models.Album, cache *scanner_cache.AlbumScannerCac
for _, item := range dirContent {
photoPath := path.Join(album.Path, item.Name())
if !item.IsDir() && cache.IsPathMedia(photoPath) {
isDirSymlink, err := utils.IsDirSymlink(photoPath)
if err != nil {
log.Printf("Cannot detect whether %s is symlink to a directory. Pretending it is not", photoPath)
isDirSymlink = false
}
if !item.IsDir() && !isDirSymlink && cache.IsPathMedia(photoPath) {
// Match file against ignore data
if albumIgnore.MatchesPath(item.Name()) {
log.Printf("File %s ignored\n", item.Name())

View File

@@ -11,6 +11,7 @@ import (
"github.com/photoview/photoview/api/graphql/models"
"github.com/photoview/photoview/api/scanner/scanner_cache"
"github.com/photoview/photoview/api/scanner/scanner_utils"
"github.com/photoview/photoview/api/utils"
"github.com/pkg/errors"
ignore "github.com/sabhiram/go-gitignore"
"gorm.io/gorm"
@@ -198,7 +199,13 @@ func findAlbumsForUser(db *gorm.DB, user *models.User, album_cache *scanner_cach
continue
}
if item.IsDir() && directoryContainsPhotos(subalbumPath, album_cache, albumIgnore) {
isDirSymlink, err := utils.IsDirSymlink(subalbumPath)
if err != nil {
scanErrors = append(scanErrors, errors.Wrapf(err, "could not check for symlink target of %s", subalbumPath))
continue
}
if (item.IsDir() || isDirSymlink) && directoryContainsPhotos(subalbumPath, album_cache, albumIgnore) {
scanQueue.PushBack(scanInfo{
path: subalbumPath,
parent: album,