From a6f6f102395726c97516947eb0221f5e06f6f6cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 5 Jan 2024 11:23:49 +0100 Subject: [PATCH] Fix #104263: Error performing BAT pack in Windows with shared storage Replace calls to `Path.absolute()` and `Path.resolve()` with `bpathlib.make_absolute(path)`. The replaced functions can transform drive letters on Windows to UNC notation. Either all of Flamenco + BAT should be using UNC notation, or drive letters, but mixing those will cause errors. --- addon/flamenco/bat/cache.py | 3 ++- addon/flamenco/job_submission.py | 4 ++-- addon/flamenco/operators.py | 15 +++++++++------ addon/flamenco/projects.py | 4 +++- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/addon/flamenco/bat/cache.py b/addon/flamenco/bat/cache.py index 04d6361f..29fd4ec8 100644 --- a/addon/flamenco/bat/cache.py +++ b/addon/flamenco/bat/cache.py @@ -29,6 +29,7 @@ from collections import deque from pathlib import Path from . import time_tracker +from .submodules import bpathlib CACHE_ROOT = Path().home() / ".cache/shaman-client/shasums" MAX_CACHE_FILES_AGE_SECS = 3600 * 24 * 60 # 60 days @@ -93,7 +94,7 @@ def _cache_path(filepath: Path) -> Path: """Compute the cache file for the given file path.""" fs_encoding = sys.getfilesystemencoding() - filepath = filepath.absolute() + filepath = bpathlib.make_absolute(filepath) # Reverse the directory, because most variation is in the last bytes. rev_dir = str(filepath.parent)[::-1] diff --git a/addon/flamenco/job_submission.py b/addon/flamenco/job_submission.py index cb40a5c2..dad16a9f 100644 --- a/addon/flamenco/job_submission.py +++ b/addon/flamenco/job_submission.py @@ -131,10 +131,10 @@ def is_file_inside_job_storage(context: bpy.types.Context, blendfile: Path) -> b the job storage dir is accessible by the workers already. """ - blendfile = blendfile.absolute().resolve() + blendfile = bpathlib.make_absolute(blendfile) prefs = preferences.get(context) - job_storage = Path(prefs.job_storage).absolute().resolve() + job_storage = bpathlib.make_absolute(Path(prefs.job_storage)) log.info("Checking whether the file is already inside the job storage") log.info(" file : %s", blendfile) diff --git a/addon/flamenco/operators.py b/addon/flamenco/operators.py index 05de077d..0d94effc 100644 --- a/addon/flamenco/operators.py +++ b/addon/flamenco/operators.py @@ -383,7 +383,11 @@ class FLAMENCO_OT_submit_job(FlamencoOpMixin, bpy.types.Operator): self.log.info( "File is not already in job storage location, copying it there" ) - self.blendfile_on_farm = self._bat_pack_filesystem(context, blendfile) + try: + self.blendfile_on_farm = self._bat_pack_filesystem(context, blendfile) + except FileNotFoundError: + self._quit(context) + return {"CANCELLED"} context.window_manager.modal_handler_add(self) wm = context.window_manager @@ -403,12 +407,11 @@ class FLAMENCO_OT_submit_job(FlamencoOpMixin, bpy.types.Operator): # Get project path from addon preferences. prefs = preferences.get(context) project_path: Path = prefs.project_root() - try: - project_path = Path(bpy.path.abspath(str(project_path))).resolve() - except FileNotFoundError: - # Path.resolve() will raise a FileNotFoundError if the project path doesn't exist. + project_path = bpathlib.make_absolute(Path(bpy.path.abspath(str(project_path)))) + + if not project_path.exists(): self.report({"ERROR"}, "Project path %s does not exist" % project_path) - raise # TODO: handle this properly. + raise FileNotFoundError() # Determine where the blend file will be stored. unique_dir = "%s-%s" % ( diff --git a/addon/flamenco/projects.py b/addon/flamenco/projects.py index 1a090c39..fb551b5e 100644 --- a/addon/flamenco/projects.py +++ b/addon/flamenco/projects.py @@ -5,6 +5,8 @@ from pathlib import Path from typing import Callable, TypeAlias import dataclasses +from .bat.submodules import bpathlib + def for_blendfile(blendfile: Path, strategy: str) -> Path: """Return what is considered to be the project directory containing the given file. @@ -43,7 +45,7 @@ def _finder_subversion(blendfile: Path) -> Path: def _search_path_marker(blendfile: Path, marker_path: str) -> Path: """Go up the directory hierarchy until a file or directory 'marker_path' is found.""" - blendfile_dir = blendfile.absolute().parent + blendfile_dir = bpathlib.make_absolute(blendfile).parent directory = blendfile_dir while True: