From 3befc0c3a7bb50b45ac0646c2b03deee502e52f2 Mon Sep 17 00:00:00 2001 From: Marcel van der Veldt Date: Fri, 30 Aug 2024 13:54:54 +0200 Subject: [PATCH] another attempt for smb mount --- .../providers/filesystem_smb/__init__.py | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/music_assistant/server/providers/filesystem_smb/__init__.py b/music_assistant/server/providers/filesystem_smb/__init__.py index 98379e3c..09291c90 100644 --- a/music_assistant/server/providers/filesystem_smb/__init__.py +++ b/music_assistant/server/providers/filesystem_smb/__init__.py @@ -2,6 +2,7 @@ from __future__ import annotations +import os import platform from typing import TYPE_CHECKING @@ -9,7 +10,7 @@ from music_assistant.common.helpers.util import get_ip_from_host from music_assistant.common.models.config_entries import ConfigEntry, ConfigValueType from music_assistant.common.models.enums import ConfigEntryType from music_assistant.common.models.errors import LoginFailed -from music_assistant.constants import CONF_PASSWORD, CONF_USERNAME +from music_assistant.constants import CONF_PASSWORD, CONF_USERNAME, VERBOSE_LOG_LEVEL from music_assistant.server.helpers.process import check_output from music_assistant.server.providers.filesystem_local import ( CONF_ENTRY_MISSING_ALBUM_ARTIST, @@ -182,12 +183,18 @@ class SMBFileSystemProvider(LocalFileSystemProvider): ] elif platform.system() == "Linux": - options = ["rw", f'username="{username}"'] + options = ["rw"] if mount_options := str(self.config.get_value(CONF_MOUNT_OPTIONS)): options += mount_options.split(",") - if password: - options.append(f'password="{password}"') + options.append(f"username={username}") options_str = ",".join(options) + + env_vars = { + **os.environ, + } + if password: + env_vars["PASSWD"] = str(password) + mount_cmd = [ "mount", "-t", @@ -201,12 +208,15 @@ class SMBFileSystemProvider(LocalFileSystemProvider): msg = f"SMB provider is not supported on {platform.system()}" raise LoginFailed(msg) - self.logger.info("Mounting //%s/%s%s to %s", server, share, subfolder, self.base_path) - self.logger.debug( + self.logger.debug("Mounting //%s/%s%s to %s", server, share, subfolder, self.base_path) + self.logger.log( + VERBOSE_LOG_LEVEL, "Using mount command: %s", - [m.replace(str(password), "########") if password else m for m in mount_cmd], + " ".replace( + [m.replace(str(password), "########") if password else m for m in mount_cmd] + ), ) - returncode, output = await check_output(*mount_cmd) + returncode, output = await check_output(*mount_cmd, env=env_vars) if returncode != 0: msg = f"SMB mount failed with error: {output.decode()}" raise LoginFailed(msg) -- 2.34.1