1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-11-10 04:02:17 +00:00

Added setting to follow symlinks

#48, #146
This commit is contained in:
Alban Féron 2019-07-06 17:04:08 +02:00
parent 25ca4d0dac
commit f3a12c78b4
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165
8 changed files with 17 additions and 7 deletions

View File

@ -8,6 +8,9 @@
; Optional, restrict scanner to these extensions. Default: none ; Optional, restrict scanner to these extensions. Default: none
;scanner_extensions = mp3 ogg ;scanner_extensions = mp3 ogg
; Should the scanner follow symbolic links? Default: no
follow_symlinks = no
[webapp] [webapp]
; Optional cache directory. Default: /tmp/supysonic ; Optional cache directory. Default: /tmp/supysonic
cache_dir = /var/supysonic/cache cache_dir = /var/supysonic/cache

View File

@ -61,6 +61,10 @@ restricted to. Useful if you have multiple audio formats in your library but
only want to serve some. If left empty, the scanner will try to read every file only want to serve some. If left empty, the scanner will try to read every file
it finds. it finds.
`follow_symlinks`: if set to `yes`, allows the scanner to follow symbolic links.
Disabled by default, enable it only if you trust your file system as nothing is
done to handle broken links or loops.
```ini ```ini
[base] [base]
; A database URI. See the 'schema' folder for schema creation scripts ; A database URI. See the 'schema' folder for schema creation scripts
@ -71,6 +75,9 @@ database_uri = sqlite:////var/supysonic/supysonic.db
; Optional, restrict scanner to these extensions. Default: none ; Optional, restrict scanner to these extensions. Default: none
scanner_extensions = mp3 ogg scanner_extensions = mp3 ogg
; Should the scanner follow symbolic links? Default: no
follow_symlinks = no
``` ```
## `[webapp]` section ## `[webapp]` section

View File

@ -251,6 +251,7 @@ class SupysonicCLI(cmd.Cmd):
scanner = Scanner( scanner = Scanner(
force=force, force=force,
extensions=extensions, extensions=extensions,
follow_symlinks=self.__config.BASE["follow_symlinks"],
progress=TimedProgressDisplay(self.stdout), progress=TimedProgressDisplay(self.stdout),
on_folder_start=self.__unwatch_folder, on_folder_start=self.__unwatch_folder,
on_folder_end=self.__watch_folder, on_folder_end=self.__watch_folder,

View File

@ -30,6 +30,7 @@ class DefaultConfig(object):
BASE = { BASE = {
"database_uri": "sqlite:///" + os.path.join(tempdir, "supysonic.db"), "database_uri": "sqlite:///" + os.path.join(tempdir, "supysonic.db"),
"scanner_extensions": None, "scanner_extensions": None,
"follow_symlinks": False,
} }
WEBAPP = { WEBAPP = {
"cache_dir": tempdir, "cache_dir": tempdir,

View File

@ -82,6 +82,7 @@ class Daemon(object):
self.__scanner = Scanner( self.__scanner = Scanner(
force=force, force=force,
extensions=extensions, extensions=extensions,
follow_symlinks=self.__config.BASE["follow_symlinks"],
on_folder_start=self.__unwatch, on_folder_start=self.__unwatch,
on_folder_end=self.__watch, on_folder_end=self.__watch,
) )

View File

@ -7,9 +7,6 @@
# #
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
import os.path
import uuid
from flask import current_app, flash, redirect, render_template, request, url_for from flask import current_app, flash, redirect, render_template, request, url_for
from pony.orm import ObjectNotFound from pony.orm import ObjectNotFound
@ -17,7 +14,6 @@ from ..daemon.client import DaemonClient
from ..daemon.exceptions import DaemonUnavailableError from ..daemon.exceptions import DaemonUnavailableError
from ..db import Folder from ..db import Folder
from ..managers.folder import FolderManager from ..managers.folder import FolderManager
from ..scanner import Scanner
from . import admin_only, frontend from . import admin_only, frontend

View File

@ -59,6 +59,7 @@ class Scanner(Thread):
self, self,
force=False, force=False,
extensions=None, extensions=None,
follow_symlinks=False,
progress=None, progress=None,
on_folder_start=None, on_folder_start=None,
on_folder_end=None, on_folder_end=None,
@ -71,6 +72,7 @@ class Scanner(Thread):
self.__force = force self.__force = force
self.__extensions = extensions self.__extensions = extensions
self.__follow_symlinks = follow_symlinks
self.__progress = progress self.__progress = progress
self.__on_folder_start = on_folder_start self.__on_folder_start = on_folder_start
@ -131,8 +133,7 @@ class Scanner(Thread):
for entry in scandir(path): for entry in scandir(path):
if entry.name.startswith("."): if entry.name.startswith("."):
continue continue
# TODO add config setting to allow following symlinks if entry.is_symlink() and not self.__follow_symlinks:
if entry.is_symlink():
continue continue
elif entry.is_dir(): elif entry.is_dir():
to_scan.append(entry.path) to_scan.append(entry.path)

View File

@ -45,7 +45,7 @@ class ScannerTestCase(unittest.TestCase):
yield tf yield tf
def __scan(self, force=False): def __scan(self, force=False):
self.scanner = Scanner(force) self.scanner = Scanner(force=force)
self.scanner.queue_folder("folder") self.scanner.queue_folder("folder")
self.scanner.run() self.scanner.run()