|
14 | 14 | from ...constants import zeros |
15 | 15 | from ...manifest import Manifest |
16 | 16 | from ...platform import is_win32 |
| 17 | +from ...platformflags import is_msystem |
17 | 18 | from ...repository import Repository |
18 | 19 | from ...helpers import CommandError, BackupPermissionError |
19 | 20 | from .. import has_lchflags, has_mknod |
@@ -150,6 +151,45 @@ def test_archived_paths(archivers, request): |
150 | 151 | assert expected_paths == sorted([json.loads(line)["path"] for line in archive_list.splitlines() if line]) |
151 | 152 |
|
152 | 153 |
|
| 154 | +@pytest.mark.skipif(not is_msystem, reason="only for msystem") |
| 155 | +def test_create_msys2_path_translation_warning(archivers, request, monkeypatch): |
| 156 | + archiver = request.getfixturevalue(archivers) |
| 157 | + cmd(archiver, "repo-create", RK_ENCRYPTION) |
| 158 | + create_regular_file(archiver.input_path, "test") |
| 159 | + |
| 160 | + # When MSYS2 path translation is active (variables NOT set), a warning should be emitted. |
| 161 | + monkeypatch.delenv("MSYS2_ARG_CONV_EXCL", raising=False) |
| 162 | + monkeypatch.delenv("MSYS2_ENV_CONV_EXCL", raising=False) |
| 163 | + output = cmd(archiver, "create", "test1", "input", fork=True) |
| 164 | + assert "MSYS2 path translation is active." in output |
| 165 | + |
| 166 | + # When the variables ARE set, the warning should not be emitted, |
| 167 | + # and /tmp should be archived properly without being translated to msys64/tmp. |
| 168 | + monkeypatch.setenv("MSYS2_ARG_CONV_EXCL", "*") |
| 169 | + monkeypatch.setenv("MSYS2_ENV_CONV_EXCL", "*") |
| 170 | + |
| 171 | + # We must create a real /tmp directory to avoid file not found errors, |
| 172 | + # since we will pass '/tmp' directly to Borg |
| 173 | + tmp_path = os.path.abspath("/tmp") |
| 174 | + os.makedirs(tmp_path, exist_ok=True) |
| 175 | + test_filepath = os.path.join(tmp_path, "borg_msys2_test_file") |
| 176 | + with open(test_filepath, "w") as f: |
| 177 | + f.write("test") |
| 178 | + |
| 179 | + try: |
| 180 | + output2 = cmd(archiver, "create", "test2", "/tmp", fork=True) |
| 181 | + assert "MSYS2 path translation is active." not in output2 |
| 182 | + |
| 183 | + archive_list = cmd(archiver, "list", "test2", "--json-lines") |
| 184 | + paths = [json.loads(line)["path"] for line in archive_list.splitlines() if line] |
| 185 | + |
| 186 | + # Verify that msys64 is not present and paths start with tmp/ |
| 187 | + assert not any("msys64" in p for p in paths) |
| 188 | + assert any(p.startswith("tmp/borg_msys2_test_file") for p in paths) |
| 189 | + finally: |
| 190 | + os.unlink(test_filepath) |
| 191 | + |
| 192 | + |
153 | 193 | @requires_hardlinks |
154 | 194 | def test_create_duplicate_root(archivers, request): |
155 | 195 | archiver = request.getfixturevalue(archivers) |
|
0 commit comments