2
0
Эх сурвалжийг харах

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.
Rayyan Ansari 2 жил өмнө
parent
commit
66a407ff9f

+ 1 - 1
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

+ 2 - 2
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):

+ 2 - 2
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)
 

+ 1 - 1
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