Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly normalise paths on Windows #7676

Merged
merged 2 commits into from
Jul 6, 2023

Conversation

RayyanAnsari
Copy link
Contributor

Fixes #7666

@codecov-commenter
Copy link

codecov-commenter commented Jun 25, 2023

Codecov Report

Merging #7676 (7e0cdd7) into master (3495144) will decrease coverage by 0.12%.
The diff coverage is 33.33%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

@@            Coverage Diff             @@
##           master    #7676      +/-   ##
==========================================
- Coverage   83.87%   83.76%   -0.12%     
==========================================
  Files          66       66              
  Lines       11873    11897      +24     
  Branches     2149     2155       +6     
==========================================
+ Hits         9958     9965       +7     
- Misses       1346     1359      +13     
- Partials      569      573       +4     
Impacted Files Coverage Δ
src/borg/helpers/fs.py 83.27% <33.33%> (-1.26%) ⬇️

... and 5 files with indirect coverage changes

Comment on lines 248 to 249
if is_win32:
path = os.path.splitdrive(path)[1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what i already wondered: is borg already getting paths with slashes (and not backslashes)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added some logging, it looks like it is:

$ pytest -s -k "test_archived_paths and not remote and not binary"
=========================================================================================== test session starts ============================================================================================
platform win32 -- Python 3.10.9, pytest-7.2.0, pluggy-1.0.0
benchmark: 4.0.0 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
Tests enabled: root, hardlinks, modes
Tests disabled: BSD flags, fuse2, fuse3, symlinks, atime/mtime
rootdir: C:/msys64/home/Rayyan/borg, configfile: setup.cfg
plugins: benchmark-4.0.0, cov-4.0.0, forked-1.4.0, xdist-3.1.0
collected 1746 items / 1745 deselected / 1 selected

src/borg/testsuite/archiver/create_cmd.py
self.cmd output START
self.cmd output END


self.cmd output START
remove_dotdot_prefixes path =  input
remove_dotdot_prefixes path =  input/test
remove_dotdot_prefixes path =  C:/Users/Rayyan/AppData/Local/Temp/tmpz08pkzkq/input/test
self.cmd output END


self.cmd output START
input
input/test
Users/Rayyan/AppData/Local/Temp/tmpz08pkzkq/input/test
self.cmd output END


self.cmd output START
{"flags": 0, "gid": 0, "group": "root", "healthy": true, "hlid": "", "mode": "drwxrwxrwx", "mtime": "2023-06-25T21:38:16.244628+01:00", "path": "input", "size": 0, "target": "", "type": "d", "uid": 0, "user": "root"}
{"flags": 0, "gid": 0, "group": "root", "healthy": true, "hlid": "", "mode": "-rw-rw-rw-", "mtime": "2023-06-25T21:38:16.244628+01:00", "path": "input/test", "size": 0, "target": "", "type": "-", "uid": 0, "user": "root"}
{"flags": 0, "gid": 0, "group": "root", "healthy": true, "hlid": "", "mode": "-rw-rw-rw-", "mtime": "2023-06-25T21:38:16.244628+01:00", "path": "Users/Rayyan/AppData/Local/Temp/tmpz08pkzkq/input/test", "size": 0, "target": "", "type": "-", "uid": 0, "user": "root"}
self.cmd output END

.

==================================================================================== 1 passed, 1745 deselected in 1.63s ==================================================================================== 

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know where exactly the usual backslashes on windows are transformed to slashes?

Copy link
Contributor Author

@RayyanAnsari RayyanAnsari Jun 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just tested making an archive manually with borg.exe, looks like the paths are still backslashes...
strange. will look into this more.

could be that the test is passing it a forward slash path but at the terminal it's getting passed a backward slash path

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

appears to work fine now but i don't know if posixpath.normpath is needed in other places as well

@ams-tschoening
Copy link

There was a discussion on the mailing list about not taking drive letters into account on Windows, which prevents using files of multiple drives in the same archive. That feels a bit strange, especially as some softwares like Cygwin simply use the drive letter character as part of some path and Borg might do the same. The following is an example:

C:\windows\system32\something
D:\windows\foobar

vs.

C/windows/system32/something
D/windows/foobar

@ThomasWaldmann
Copy link
Member

@ams-tschoening makes sense.

Just one thing might complicate this a bit:
guess we don't always have drive letters, so we would only include them if they were part of the recursion root?

E.g.

borg create ARCHIVE c:\windows Documents

would we back up this like?:

c/windows/...
...
Documents/example.doc
...

@ams-tschoening
Copy link

ams-tschoening commented Jun 27, 2023

c/windows/...
...
Documents/example.doc
...

In my opinion yes and should be in-line with what Borg documents about paths in other OS as well: They are used as is. If one wants relative paths, one needs to cd into parents (Documents), otherwise the whole path prefix is used (C:\Windows). Borg doesn't calculate some path prefix for other relative paths on other OS as well, so don't need to here. The only question is if to remove C:\ and make things special this way, which doesn't seem necessary. The only special thing here is that C:\ should become part of the path using non-Windows syntax as C/[...] and making paths behave mostly the same this way across different OS.

tschoening@tschoening-nb MINGW64 ~/Documents
$ pwd
/c/Users/tschoening/Documents

@ThomasWaldmann
Copy link
Member

Note: lower case "c" on mingw64 (not uppercase).

@ams-tschoening
Copy link

Note: lower case "c" on mingw64 (not uppercase).

Should you care about that? Borg doesn't normalize upper-lower case in any other path or does it on Windows? In my opinion things should be forwarded 1:1.

@RayyanAnsari
Copy link
Contributor Author

There was a discussion on the mailing list about not taking drive letters into account on Windows, which prevents using files of multiple drives in the same archive. That feels a bit strange, especially as some softwares like Cygwin simply use the drive letter character as part of some path and Borg might do the same. The following is an example:

Do you have a link to this discussion?

@ams-tschoening
Copy link

https://mail.python.org/pipermail/borgbackup/2023q2/002269.html

An answer is missing, because I've sent privately by accident first.

@RayyanAnsari RayyanAnsari force-pushed the paths-win branch 2 times, most recently from e327a24 to ebbf8b0 Compare July 2, 2023 21:59
src/borg/helpers/fs.py Outdated Show resolved Hide resolved
src/borg/helpers/fs.py Outdated Show resolved Hide resolved
Copy link
Member

@ThomasWaldmann ThomasWaldmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@RayyanAnsari RayyanAnsari marked this pull request as ready for review July 4, 2023 22:21
@RayyanAnsari
Copy link
Contributor Author

anything stopping this from being merged?

@ThomasWaldmann
Copy link
Member

No. :)

@ThomasWaldmann ThomasWaldmann merged commit cfbfe24 into borgbackup:master Jul 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

correctly normalize archived paths (windows)
4 participants