Skip to content

Commit

Permalink
Fix directory paths configured by the config loader.
Browse files Browse the repository at this point in the history
Home paths provided in the -h parameter or SLIVKA_HOME were used
as is without resolving symlinks. On the other hand, os.getcwd
and paths to input and output files were formed with os.realpath
which resolved all symlinks.
It was actually a problem with an api code converting paths to
ids in a hacky way, but changing all paths to real paths works too.
Fix #129
  • Loading branch information
warownia1 committed Apr 5, 2024
1 parent 88fd567 commit 5b2edee
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
12 changes: 11 additions & 1 deletion slivka/conf/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,21 @@ class ImproperlyConfigured(Exception):
pass


compatible_config_ver = ['0.3', '0.8', '0.8.0', '0.8.1', '0.8.2', '0.8.3']
compatible_config_ver = [
"0.3",
"0.8",
"0.8.0",
"0.8.1",
"0.8.2",
"0.8.3",
"0.8.4",
"0.8.5",
]


def load_settings_0_3(config, home=None) -> 'SlivkaSettings':
home = home or os.getenv('SLIVKA_HOME', os.getcwd())
home = os.path.realpath(home)
if config['version'] not in compatible_config_ver:
raise ImproperlyConfigured("Expected config version 0.8")
config = flatten_mapping(config)
Expand Down
2 changes: 1 addition & 1 deletion slivka/server/forms/file_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def _del_file(self):
def save_as(self, path, fp=None):
"""
Saves the file at the specified location. If ``fp`` is specified it
will be used to write the content. Otherwise, a new file at ``path``
will be used as a write destination. Otherwise, a new file at ``path``
will be created.
:param path: Path to the destination file
Expand Down
28 changes: 28 additions & 0 deletions test/conf/loaders.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import os
from unittest import mock

import pytest
import yaml

import slivka.conf.loaders
from slivka.compat.resources import open_text


@pytest.fixture
def dict_config():
with open_text('test', 'resources/minimal_project/settings.yaml') as stream:
return yaml.safe_load(stream)


def test_conf_directory_real_path(tmp_path, dict_config):
real_home = tmp_path / "real-slivka"
os.mkdir(real_home)
home = tmp_path / "slivka"
os.symlink(real_home, home, target_is_directory=True)
with mock.patch.dict(os.environ, SLIVKA_HOME=str(home)):
conf = slivka.conf.loaders.load_settings_0_3(dict_config)
assert conf.directory.home == str(real_home)
assert conf.directory.jobs == str(real_home / 'jobs')
assert conf.directory.uploads == str(real_home / 'uploads')
assert conf.directory.logs == str(real_home / 'log')
assert conf.directory.services == str(real_home)

0 comments on commit 5b2edee

Please sign in to comment.