Workaround for Windows failing on glob patterns in path.resolve()

Windows fails with an OSError when `somepath.resolve()` is called and
`somepath` contains a glob pattern. As a workaround, we now `resolve()`
the parent directory, and put the filename at its end. This only works
when the glob pattern is in the filename, which is the case for BAT-
generated globs.
This commit is contained in:
Sybren A. Stüvel 2019-01-02 15:04:54 +01:00
parent d222fea960
commit 20d7ea08cc

View File

@ -149,10 +149,17 @@ class BlockUsage:
if self._abspath is None: if self._abspath is None:
bpath = self.block.bfile.abspath(self.asset_path) bpath = self.block.bfile.abspath(self.asset_path)
as_path = pathlib.Path(bpath.to_path()) as_path = pathlib.Path(bpath.to_path())
# Windows cannot resolve() a path that has a glob pattern in it.
# Since globs are generally only on the filename part, we take that off,
# resolve() the parent directory, then put the filename back.
try: try:
self._abspath = as_path.resolve() abs_parent = as_path.parent.resolve()
except FileNotFoundError: except FileNotFoundError:
self._abspath = as_path self._abspath = as_path
else:
self._abspath = abs_parent / as_path.name
log.info('Resolving %s rel to %s -> %s', log.info('Resolving %s rel to %s -> %s',
self.asset_path, self.block.bfile.filepath, self._abspath) self.asset_path, self.block.bfile.filepath, self._abspath)
else: else: