Skip to content

borg2: borg create fails if a file name contains a backslash on Linux #9406

@TheNewHEROBRINEX

Description

@TheNewHEROBRINEX

If borg create encounters a file whose name contains a backslash character (\), it will immediately crash because of this assertion.
I think maybe that assertion was meant to be Windows-only since on Windows file names cannot contain backslashes?
Example:

$ mkdir test
$ touch 'test/test\file.txt'
$ borg create -r test-repo -v --list test test/
Creating archive at "test-repo"
Local Exception

Error:

AssertionError: 

If reporting bugs, please include the following:

Traceback (most recent call last):
  File "/home/luca/Desktop/borg/src/borg/archiver/__init__.py", line 666, in main
    exit_code = archiver.run(args)
  File "/home/luca/Desktop/borg/src/borg/archiver/__init__.py", line 543, in run
    rc = func(args)
  File "/home/luca/Desktop/borg/src/borg/archiver/_common.py", line 145, in wrapper
    return method(self, args, repository=repository, **kwargs)
  File "/home/luca/Desktop/borg/src/borg/archiver/create_cmd.py", line 276, in do_create
    create_inner(archive, cache, fso)
    ~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^
  File "/home/luca/Desktop/borg/src/borg/archiver/create_cmd.py", line 170, in create_inner
    self._rec_walk(
    ~~~~~~~~~~~~~~^
        path=path,
        ^^^^^^^^^^
    ...<12 lines>...
        strip_prefix=strip_prefix,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/luca/Desktop/borg/src/borg/archiver/create_cmd.py", line 536, in _rec_walk
    self._rec_walk(
    ~~~~~~~~~~~~~~^
        path=normpath,
        ^^^^^^^^^^^^^^
    ...<12 lines>...
        strip_prefix=strip_prefix,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/luca/Desktop/borg/src/borg/archiver/create_cmd.py", line 470, in _rec_walk
    status = self._process_any(
        path=path,
    ...<7 lines>...
        strip_prefix=strip_prefix,
    )
  File "/home/luca/Desktop/borg/src/borg/archiver/create_cmd.py", line 292, in _process_any
    return fso.process_file(
           ~~~~~~~~~~~~~~~~^
        path=path,
        ^^^^^^^^^^
    ...<5 lines>...
        strip_prefix=strip_prefix,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/luca/Desktop/borg/src/borg/archive.py", line 1403, in process_file
    with self.create_helper(path, st, None, strip_prefix=strip_prefix) as (
         ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/contextlib.py", line 141, in __enter__
    return next(self.gen)
  File "/home/luca/Desktop/borg/src/borg/archive.py", line 1272, in create_helper
    sanitized_path = remove_dotdot_prefixes(path)
  File "/home/luca/Desktop/borg/src/borg/helpers/fs.py", line 331, in remove_dotdot_prefixes
    assert "\\" not in path
           ^^^^^^^^^^^^^^^^
AssertionError

Platform: Linux luca-HP-Laptop-15s-fq4xxx 6.11.0-26-generic #26-Ubuntu SMP PREEMPT_DYNAMIC Sat Apr 12 11:25:41 UTC 2025 x86_64
Linux: Unknown Linux  
Borg: 2.0.0b21.dev148+g3e15918b8  Python: CPython 3.13.3 msgpack: 1.1.2 fuse: None [mfusepy,pyfuse3,llfuse]
PID: 8393  CWD: /home/luca/Desktop/borg
sys.argv: ['/home/luca/Desktop/borg/borg-env/bin/borg', 'create', '-r', 'test-repo', '-v', '--list', 'test', 'test/']
SSH_ORIGINAL_COMMAND: None

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions