diff --git a/simple_backup/simple_backup.py b/simple_backup/simple_backup.py index ed11a74..60bae52 100755 --- a/simple_backup/simple_backup.py +++ b/simple_backup/simple_backup.py @@ -881,13 +881,16 @@ def _expand_inputs(inputs: list[str], user: str | None = None) -> list[str]: continue if user is not None: - i_ex = glob(_expand_home(i, user)) + path = _expand_home(i, user) else: - i_ex = glob(i) + path = i if i.startswith('~'): logger.warning('Cannot expand \'~\'. No user specified') + # An existing path is used as is, so names with glob characters (e.g. 'Photos [2020]') still work + i_ex = [path] if os.path.lexists(path) else glob(path) + if len(i_ex) == 0: logger.warning( 'No file or directory matching input %s. Skipping...', i) diff --git a/tests/test_config.py b/tests/test_config.py index 1cd4491..193ae52 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -45,6 +45,13 @@ def test_expand_inputs_glob(tmp_path: Path) -> None: assert sorted(result) == [f'{tmp_path}/a.txt', f'{tmp_path}/b.txt'] +def test_expand_inputs_glob_characters_in_name(tmp_path: Path) -> None: + (tmp_path / 'Photos [2020]').mkdir() + (tmp_path / 'Photos 2').mkdir() + + assert sb._expand_inputs([f'{tmp_path}/Photos [2020]'], USER) == [f'{tmp_path}/Photos [2020]'] + + def test_expand_inputs_no_match(tmp_path: Path, caplog: pytest.LogCaptureFixture) -> None: assert sb._expand_inputs([f'{tmp_path}/missing'], USER) == [] assert 'No file or directory matching input' in caplog.text