pyinfra-dev / pyinfra

pyinfra turns Python code into shell commands and runs them on your servers. Execute ad-hoc commands and write declarative operations. Target SSH servers, local machine and Docker containers. Fast and scales from one server to thousands.
https://pyinfra.com
MIT License
3.91k stars 382 forks source link

files.sync is not normalizing paths when syncing from Windows to Linux #1077

Closed Renerick closed 7 months ago

Renerick commented 7 months ago

Describe the bug

When running files.sync on Windows against Linux host, backwards slashes in the paths in nested directories are not normalized

Directory structure being synced image

Outcome: image

To Reproduce

Try to sync a deeply nested directory from Windows to Linux

    ...
    files.sync(src=source, dest=temlates_destination.as_posix(), delete=True, _sudo=True)

Expected behavior

Directory structure is preserved after sync

Meta

System: Windows
      Platform: Windows-10-10.0.19045-SP0
      Release: 10
      Machine: AMD64
    pyinfra: v3.0b0
    Executable: C:\[REDACTED]\.venv\Scripts\pyinfra.exe
    Python: 3.12.2 (CPython, MSC v.1937 64 bit (AMD64))
Renerick commented 7 months ago

I created a failing test case by adding another level of nesting in windows test, here is the result

--> COMMANDS OUTPUT:
[
    "mkdir -p /home/somedir",
    "chmod 755 /home/somedir",
    "mkdir -p /home/somedir/underthat",
    "chmod 755 /home/somedir/underthat",
    "mkdir -p '/home/somedir/underthat\\evendeeper'",
    "chmod 755 '/home/somedir/underthat\\evendeeper'",
    [
        "upload",
        "\\somedir\\somefile.txt",
        "/home/somedir/somefile.txt"
    ],
    "chmod 644 /home/somedir/somefile.txt",
    [
        "upload",
        "\\somedir\\anotherfile.txt",
        "/home/somedir/anotherfile.txt"
    ],
    "chmod 644 /home/somedir/anotherfile.txt",
    [
        "upload",
        "\\somedir\\underthat\\yet-another-file.txt",
        "/home/somedir/underthat/yet-another-file.txt"
    ],
    "chmod 644 /home/somedir/underthat/yet-another-file.txt",
    [
        "upload",
        "\\somedir\\underthat\\evendeeper\\a-very-deep-file.txt",
        "/home/somedir/underthat\\evendeeper/a-very-deep-file.txt"
    ],
    "chmod 644 '/home/somedir/underthat\\evendeeper/a-very-deep-file.txt'",
    "rm -f /home/somedir/deleteme.txt"
]