Skip to content

Commit

Permalink
Added setting to follow symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
spl0k committed Jul 6, 2019
1 parent 25ca4d0 commit f3a12c7
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 7 deletions.
3 changes: 3 additions & 0 deletions config.sample
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
; Optional, restrict scanner to these extensions. Default: none
;scanner_extensions = mp3 ogg

; Should the scanner follow symbolic links? Default: no
follow_symlinks = no

[webapp]
; Optional cache directory. Default: /tmp/supysonic
cache_dir = /var/supysonic/cache
Expand Down
7 changes: 7 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
[base]
; A database URI. See the 'schema' folder for schema creation scripts
Expand All @@ -71,6 +75,9 @@ database_uri = sqlite:////var/supysonic/supysonic.db

; Optional, restrict scanner to these extensions. Default: none
scanner_extensions = mp3 ogg

; Should the scanner follow symbolic links? Default: no
follow_symlinks = no
```

## `[webapp]` section
Expand Down
1 change: 1 addition & 0 deletions supysonic/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def __folder_scan_foreground(self, folders, force):
scanner = Scanner(
force=force,
extensions=extensions,
follow_symlinks=self.__config.BASE["follow_symlinks"],
progress=TimedProgressDisplay(self.stdout),
on_folder_start=self.__unwatch_folder,
on_folder_end=self.__watch_folder,
Expand Down
1 change: 1 addition & 0 deletions supysonic/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class DefaultConfig(object):
BASE = {
"database_uri": "sqlite:///" + os.path.join(tempdir, "supysonic.db"),
"scanner_extensions": None,
"follow_symlinks": False,
}
WEBAPP = {
"cache_dir": tempdir,
Expand Down
1 change: 1 addition & 0 deletions supysonic/daemon/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def start_scan(self, folders=[], force=False):
self.__scanner = Scanner(
force=force,
extensions=extensions,
follow_symlinks=self.__config.BASE["follow_symlinks"],
on_folder_start=self.__unwatch,
on_folder_end=self.__watch,
)
Expand Down
4 changes: 0 additions & 4 deletions supysonic/frontend/folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,13 @@
#
# 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 pony.orm import ObjectNotFound

from ..daemon.client import DaemonClient
from ..daemon.exceptions import DaemonUnavailableError
from ..db import Folder
from ..managers.folder import FolderManager
from ..scanner import Scanner

from . import admin_only, frontend

Expand Down
5 changes: 3 additions & 2 deletions supysonic/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def __init__(
self,
force=False,
extensions=None,
follow_symlinks=False,
progress=None,
on_folder_start=None,
on_folder_end=None,
Expand All @@ -71,6 +72,7 @@ def __init__(

self.__force = force
self.__extensions = extensions
self.__follow_symlinks = follow_symlinks

self.__progress = progress
self.__on_folder_start = on_folder_start
Expand Down Expand Up @@ -131,8 +133,7 @@ def __scan_folder(self, folder):
for entry in scandir(path):
if entry.name.startswith("."):
continue
# TODO add config setting to allow following symlinks
if entry.is_symlink():
if entry.is_symlink() and not self.__follow_symlinks:
continue
elif entry.is_dir():
to_scan.append(entry.path)
Expand Down
2 changes: 1 addition & 1 deletion tests/base/test_scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __temporary_track_copy(self):
yield tf

def __scan(self, force=False):
self.scanner = Scanner(force)
self.scanner = Scanner(force=force)
self.scanner.queue_folder("folder")
self.scanner.run()

Expand Down

0 comments on commit f3a12c7

Please sign in to comment.