Improved path handling

This commit fixes a bunch of issues at the same time, as they are all
related to path handling:

- `pathlib.Path.resolve()` or `.absolute()` are replaced by
  `bpathlib.make_absolute()`. The latter does NOT follow symlinks and does
  NOT network mounts from a drive letter to UNC notation. This also has
  advantages on non-Windows sytems, as it allows BAT-packing a directory
  structure with symlinked files (such as a Shaman checkout).
- Better handling of drive letters, and of paths that cross drive
  boundaries.
- Better testing of Windows-specific cases when running the tests on
  Windows, and of POSIX-specific cases on other platforms.

Thanks to @wisaac for starting this patch in D6676.

Thanks to @jbakker for pointing out the drive letter issue. This fixes
T70655.
This commit is contained in:
Sybren A. Stüvel
2020-03-17 17:15:19 +01:00
parent 3fa4389658
commit e4bf2e8e35
12 changed files with 367 additions and 67 deletions
+2 -2
View File
@@ -27,7 +27,7 @@ import sys
import time
import typing
from blender_asset_tracer import trace
from blender_asset_tracer import trace, bpathlib
from . import common
log = logging.getLogger(__name__)
@@ -106,7 +106,7 @@ def report_text(bpath, *, include_sha256: bool, show_timing: bool):
last_reported_bfile = filepath
for assetpath in usage.files():
assetpath = assetpath.resolve()
assetpath = bpathlib.make_absolute(assetpath)
if assetpath in reported_assets:
log.debug('Already reported %s', assetpath)
continue
+4 -4
View File
@@ -24,7 +24,7 @@ import sys
import typing
import blender_asset_tracer.pack.transfer
from blender_asset_tracer import pack
from blender_asset_tracer import pack, bpathlib
log = logging.getLogger(__name__)
@@ -168,15 +168,15 @@ def paths_from_cli(args) -> typing.Tuple[pathlib.Path, pathlib.Path, str]:
if bpath.is_dir():
log.critical('%s is a directory, should be a blend file')
sys.exit(3)
bpath = bpath.absolute().resolve()
bpath = bpathlib.make_absolute(bpath)
tpath = args.target
if args.project is None:
ppath = bpath.absolute().parent.resolve()
ppath = bpathlib.make_absolute(bpath).parent
log.warning('No project path given, using %s', ppath)
else:
ppath = args.project.absolute().resolve()
ppath = bpathlib.make_absolute(args.project)
if not ppath.exists():
log.critical('Project directory %s does not exist', ppath)