From 0187dae8ff812359aa23e9b7c5bc9b52d39acf8e Mon Sep 17 00:00:00 2001 From: Roland Date: Tue, 2 Nov 2021 11:59:57 -0600 Subject: [PATCH] is_relative_to is from 3.9. --- nginx.conf | 4 +++- wrolpi/media_path.py | 2 +- wrolpi/test/test_media_path.py | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/nginx.conf b/nginx.conf index d2752e1f..f7ab5e91 100644 --- a/nginx.conf +++ b/nginx.conf @@ -1,3 +1,5 @@ +user www-data; + events { } @@ -46,7 +48,7 @@ http { autoindex on; autoindex_exact_size off; - alias /opt/media; + alias /media/wrolpi; } } diff --git a/wrolpi/media_path.py b/wrolpi/media_path.py index c7ec0330..31209c90 100644 --- a/wrolpi/media_path.py +++ b/wrolpi/media_path.py @@ -29,7 +29,7 @@ class MediaPath: if not path.is_absolute(): # Assume the path is relative to the media directory. path = get_media_directory() / path - elif not path.is_relative_to(get_media_directory()): + elif not str(path).startswith(str(get_media_directory())): # Absolute paths must be within the media directory. raise ValueError(f'Path {path} must be in {get_media_directory()}') diff --git a/wrolpi/test/test_media_path.py b/wrolpi/test/test_media_path.py index b698c31a..1feda096 100644 --- a/wrolpi/test/test_media_path.py +++ b/wrolpi/test/test_media_path.py @@ -37,3 +37,6 @@ class TestMediaPath(unittest.TestCase): # Absolute paths must be in media directory. d = MediaPath(f'{self.test_dir.name}/foo') self.assertEqual(d._path, pathlib.Path(f'{self.test_dir.name}/foo')) + + # Error is raised when the path is not in the media path. + self.assertRaises(ValueError, MediaPath, '/tmp/foo')