mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 19:01:39 -04:00
is_relative_to is from 3.9.
This commit is contained in:
parent
c6b55b47b5
commit
0187dae8ff
3 changed files with 7 additions and 2 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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()}')
|
||||
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue