Skip to content

Commit 3c858c2

Browse files
committed
archiver: warn about MSYS2 path translation, fixes #9339
This adds a runtime warning when running under MSYS2/Git Bash without the necessary environment variables to disable automatic path translation. The documentation is also updated to explain this behavior and how to mitigate it.
1 parent e43800b commit 3c858c2

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

docs/installation.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,29 @@ Install the dependencies with the provided script::
328328

329329
./scripts/msys2-install-deps
330330

331+
.. _msys2_path_translation:
332+
333+
MSYS2 Path Translation
334+
++++++++++++++++++++++
335+
336+
When running Borg within an MSYS2 (including Git Bash) environment, the shell
337+
automatically translates POSIX-style paths (like ``/tmp`` or ``/c/Users``) to
338+
Windows paths (like ``C:\msys64\tmp`` or ``C:\Users``) before they reach the
339+
Borg process.
340+
341+
This behavior can result in absolute Windows paths being stored in your backups,
342+
which may not be what you intended if you use POSIX paths for portability.
343+
344+
To disable this automatic translation for Borg, you can use environment variables
345+
to exclude everything from conversion. Similarly, MSYS2 also translates
346+
environment variables that look like paths. To disable this generally for Borg,
347+
set both variables::
348+
349+
export MSYS2_ARG_CONV_EXCL="*"
350+
export MSYS2_ENV_CONV_EXCL="*"
351+
352+
For more details, see the `MSYS2 documentation on filesystem paths <https://www.msys2.org/docs/filesystem-paths/>`__.
353+
331354
Windows 10's Linux Subsystem
332355
++++++++++++++++++++++++++++
333356

src/borg/archiver/__init__.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,14 @@ def parse_args(self, args=None):
455455
return args
456456

457457
def prerun_checks(self, logger, is_serve):
458-
458+
if not is_serve:
459+
if sys.platform == "win32" and "MSYSTEM" in os.environ:
460+
if "MSYS2_ARG_CONV_EXCL" not in os.environ or "MSYS2_ENV_CONV_EXCL" not in os.environ:
461+
logger.warning(
462+
"MSYS2 path translation is active. This can cause POSIX paths to be mangled into "
463+
"Windows paths in archives. Consider setting MSYS2_ARG_CONV_EXCL='*' and "
464+
"MSYS2_ENV_CONV_EXCL='*'. See https://www.msys2.org/docs/filesystem-paths/ for details."
465+
)
459466
selftest(logger)
460467

461468
def _setup_implied_logging(self, args):

0 commit comments

Comments
 (0)