From 66a407ff9ff5bcb8c90eede3fd453f2c047e5ca7 Mon Sep 17 00:00:00 2001 From: Rayyan Ansari Date: Tue, 13 Dec 2022 17:38:15 +0000 Subject: [PATCH] Use \n for the {NL} format specifier \n is automatically converted on write to the platform-dependent os.linesep. Using os.linesep instead of \n means that on Windows, the line ending becomes "\r\r\n". Also switches mentions of {LF} to {NL} in code and docs. --- docs/usage/tar.rst | 2 +- src/borg/helpers/parseformat.py | 4 ++-- src/borg/testsuite/archiver/check_cmd.py | 4 ++-- src/borg/testsuite/archiver/corruption.py | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/usage/tar.rst b/docs/usage/tar.rst index 63a3aff0..05070c50 100644 --- a/docs/usage/tar.rst +++ b/docs/usage/tar.rst @@ -34,7 +34,7 @@ Outputs a script that copies all archives from repo1 to repo2: :: - for A T in `borg list --format='{archive} {time:%Y-%m-%dT%H:%M:%S}{LF}'` + for A T in `borg list --format='{archive} {time:%Y-%m-%dT%H:%M:%S}{NL}'` do echo "borg -r repo1 export-tar --tar-format=BORG $A - | borg -r repo2 import-tar --timestamp=$T $A -" done diff --git a/src/borg/helpers/parseformat.py b/src/borg/helpers/parseformat.py index f28d23dd..68643193 100644 --- a/src/borg/helpers/parseformat.py +++ b/src/borg/helpers/parseformat.py @@ -593,8 +593,8 @@ class BaseFormatter: "TAB": "\t", "CR": "\r", "NUL": "\0", - "NEWLINE": os.linesep, - "NL": os.linesep, + "NEWLINE": "\n", + "NL": "\n", # \n is automatically converted to os.linesep on write } def get_item_data(self, item): diff --git a/src/borg/testsuite/archiver/check_cmd.py b/src/borg/testsuite/archiver/check_cmd.py index 61936460..b7f74247 100644 --- a/src/borg/testsuite/archiver/check_cmd.py +++ b/src/borg/testsuite/archiver/check_cmd.py @@ -71,7 +71,7 @@ class ArchiverCheckTestCase(ArchiverTestCaseBase): self.assert_in("New missing file chunk detected", output) self.cmd(f"--repo={self.repository_location}", "check", exit_code=0) output = self.cmd( - f"--repo={self.repository_location}", "list", "archive1", "--format={health}#{path}{LF}", exit_code=0 + f"--repo={self.repository_location}", "list", "archive1", "--format={health}#{path}{NL}", exit_code=0 ) self.assert_in("broken#", output) # check that the file in the old archives has now a different chunk list without the killed chunk @@ -104,7 +104,7 @@ class ArchiverCheckTestCase(ArchiverTestCaseBase): self.fail("should not happen") # list is also all-healthy again output = self.cmd( - f"--repo={self.repository_location}", "list", "archive1", "--format={health}#{path}{LF}", exit_code=0 + f"--repo={self.repository_location}", "list", "archive1", "--format={health}#{path}{NL}", exit_code=0 ) self.assert_not_in("broken#", output) diff --git a/src/borg/testsuite/archiver/corruption.py b/src/borg/testsuite/archiver/corruption.py index 3ee42999..ef933eab 100644 --- a/src/borg/testsuite/archiver/corruption.py +++ b/src/borg/testsuite/archiver/corruption.py @@ -60,7 +60,7 @@ class ArchiverCorruptionTestCase(ArchiverTestCaseBase): def test_chunks_archive(self): self.cmd(f"--repo={self.repository_location}", "create", "test1", "input") # Find ID of test1 so we can corrupt it later :) - target_id = self.cmd(f"--repo={self.repository_location}", "rlist", "--format={id}{LF}").strip() + target_id = self.cmd(f"--repo={self.repository_location}", "rlist", "--format={id}{NL}").strip() self.cmd(f"--repo={self.repository_location}", "create", "test2", "input") # Force cache sync, creating archive chunks of test1 and test2 in chunks.archive.d