소스 검색

explicitely specify binary mode to open binary files

on POSIX OSes, it doesn't make a difference, but it is cleaner and also good for portability.
Thomas Waldmann 10 년 전
부모
커밋
926454c0d8
3개의 변경된 파일5개의 추가작업 그리고 5개의 파일을 삭제
  1. 2 2
      borg/_hashindex.c
  2. 1 1
      borg/cache.py
  3. 2 2
      borg/testsuite/archiver.py

+ 2 - 2
borg/_hashindex.c

@@ -136,7 +136,7 @@ hashindex_read(const char *path)
     HashHeader header;
     HashIndex *index = NULL;
 
-    if((fd = fopen(path, "r")) == NULL) {
+    if((fd = fopen(path, "rb")) == NULL) {
         EPRINTF_PATH(path, "fopen for reading failed");
         return NULL;
     }
@@ -260,7 +260,7 @@ hashindex_write(HashIndex *index, const char *path)
     };
     int ret = 1;
 
-    if((fd = fopen(path, "w")) == NULL) {
+    if((fd = fopen(path, "wb")) == NULL) {
         EPRINTF_PATH(path, "fopen for writing failed");
         return 0;
     }

+ 1 - 1
borg/cache.py

@@ -93,7 +93,7 @@ class Cache:
         with open(os.path.join(self.path, 'config'), 'w') as fd:
             config.write(fd)
         ChunkIndex().write(os.path.join(self.path, 'chunks').encode('utf-8'))
-        with open(os.path.join(self.path, 'files'), 'w') as fd:
+        with open(os.path.join(self.path, 'files'), 'wb') as fd:
             pass  # empty file
 
     def destroy(self):

+ 2 - 2
borg/testsuite/archiver.py

@@ -400,9 +400,9 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         self.cmd('extract', '--dry-run', self.repository_location + '::test')
         self.cmd('check', self.repository_location)
         name = sorted(os.listdir(os.path.join(self.tmpdir, 'repository', 'data', '0')), reverse=True)[0]
-        with open(os.path.join(self.tmpdir, 'repository', 'data', '0', name), 'r+') as fd:
+        with open(os.path.join(self.tmpdir, 'repository', 'data', '0', name), 'r+b') as fd:
             fd.seek(100)
-            fd.write('XXXX')
+            fd.write(b'XXXX')
         self.cmd('check', self.repository_location, exit_code=1)
 
     def test_readonly_repository(self):