Skip to content

Commit f203dcf

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 f203dcf

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,8 @@ jobs:
612612

613613
env:
614614
PY_COLORS: 1
615+
MSYS2_ARG_CONV_EXCL: "*"
616+
MSYS2_ENV_CONV_EXCL: "*"
615617

616618
defaults:
617619
run:

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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
from ..helpers import ErrorIgnoringTextIOWrapper
4747
from ..helpers import msgpack
4848
from ..helpers import sig_int
49+
from ..platformflags import is_win32, is_msystem
4950
from ..remote import RemoteRepository
5051
from ..selftest import selftest
5152
except BaseException:
@@ -455,7 +456,14 @@ def parse_args(self, args=None):
455456
return args
456457

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

461469
def _setup_implied_logging(self, args):

src/borg/platformflags.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Use these flags instead of sys.platform.startswith('<os>') or try/except.
55
"""
66

7+
import os
78
import sys
89

910
is_win32 = sys.platform.startswith("win32")
@@ -15,3 +16,6 @@
1516
is_openbsd = sys.platform.startswith("openbsd")
1617
is_darwin = sys.platform.startswith("darwin")
1718
is_haiku = sys.platform.startswith("haiku")
19+
20+
# MSYS2/Git Bash (on Windows)
21+
is_msystem = "MSYSTEM" in os.environ

0 commit comments

Comments
 (0)