Skip to content

Commit

Permalink
Merge pull request #2757 from jonemo/loader-is-builtin-path-2
Browse files Browse the repository at this point in the history
Remove symlink resolution in Loader.is_builtin_path
  • Loading branch information
jonemo authored Sep 9, 2022
2 parents 428d8c0 + e365831 commit 6d4551e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 25 deletions.
5 changes: 2 additions & 3 deletions botocore/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def load_data(self, name):
only needed to load *non* model files (such as _endpoints and
_retry). If you need to load model files, you should prefer
``load_service_model``. Use ``load_data_with_path`` to get the
file system path of the data file as second return value.
data path of the data file as second return value.
:type name: str
:param name: The data path, i.e ``ec2/2015-03-01/service-2``.
Expand Down Expand Up @@ -499,8 +499,7 @@ def is_builtin_path(self, path):
:return: Whether the given path is within the package's data directory.
"""
# normalize the path and resolve symlinks
path = os.path.realpath(os.path.abspath(path))
path = os.path.expanduser(os.path.expandvars(path))
return path.startswith(self.BUILTIN_DATA_PATH)


Expand Down
22 changes: 0 additions & 22 deletions tests/unit/test_loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@
import contextlib
import copy
import os
import sys
import tempfile

import pytest

from botocore.exceptions import DataNotFoundError, UnknownServiceError
from botocore.loaders import (
Expand Down Expand Up @@ -247,24 +243,6 @@ def test_is_builtin_path(self):
self.assertTrue(loader.is_builtin_path(path_in_builtins))
self.assertFalse(loader.is_builtin_path(path_elsewhere))

@pytest.mark.skipif(
sys.platform == 'win32',
reason=(
'os.symlink() requires developer mode or elevated permissions'
),
)
def test_is_builtin_path_with_symlink(self):
loader = Loader()
with tempfile.TemporaryDirectory() as tmp_dir:
link_to_builtins = os.path.join(tmp_dir, 'builtins')
os.symlink(
loader.BUILTIN_DATA_PATH,
link_to_builtins,
target_is_directory=True,
)
path_in_builtins = os.path.join(link_to_builtins, "foo.txt")
assert loader.is_builtin_path(path_in_builtins)


class TestMergeExtras(BaseEnvVar):
def setUp(self):
Expand Down

0 comments on commit 6d4551e

Please sign in to comment.