mirror of https://github.com/borgbackup/borg.git
SyncFile/SaveFile: default binary=False, just like open()
This commit is contained in:
parent
863ab66908
commit
2e3fc9ddfc
|
@ -142,11 +142,11 @@ Chunk index: {0.total_unique_chunks:20d} {0.total_chunks:20d}"""
|
|||
config.set('cache', 'version', '1')
|
||||
config.set('cache', 'repository', self.repository.id_str)
|
||||
config.set('cache', 'manifest', '')
|
||||
with SaveFile(os.path.join(self.path, 'config'), binary=False) as fd:
|
||||
with SaveFile(os.path.join(self.path, 'config')) as fd:
|
||||
config.write(fd)
|
||||
ChunkIndex().write(os.path.join(self.path, 'chunks').encode('utf-8'))
|
||||
os.makedirs(os.path.join(self.path, 'chunks.archive.d'))
|
||||
with SaveFile(os.path.join(self.path, 'files')) as fd:
|
||||
with SaveFile(os.path.join(self.path, 'files'), binary=True) as fd:
|
||||
pass # empty file
|
||||
|
||||
def _do_open(self):
|
||||
|
@ -213,7 +213,7 @@ Chunk index: {0.total_unique_chunks:20d} {0.total_chunks:20d}"""
|
|||
if not self.txn_active:
|
||||
return
|
||||
if self.files is not None:
|
||||
with SaveFile(os.path.join(self.path, 'files')) as fd:
|
||||
with SaveFile(os.path.join(self.path, 'files'), binary=True) as fd:
|
||||
for path_hash, item in self.files.items():
|
||||
# Discard cached files with the newest mtime to avoid
|
||||
# issues with filesystem snapshots and mtime precision
|
||||
|
@ -224,7 +224,7 @@ Chunk index: {0.total_unique_chunks:20d} {0.total_chunks:20d}"""
|
|||
self.config.set('cache', 'timestamp', self.manifest.timestamp)
|
||||
self.config.set('cache', 'key_type', str(self.key.TYPE))
|
||||
self.config.set('cache', 'previous_location', self.repository._location.canonical_path())
|
||||
with SaveFile(os.path.join(self.path, 'config'), binary=False) as fd:
|
||||
with SaveFile(os.path.join(self.path, 'config')) as fd:
|
||||
self.config.write(fd)
|
||||
self.chunks.write(os.path.join(self.path, 'chunks').encode('utf-8'))
|
||||
os.rename(os.path.join(self.path, 'txn.active'),
|
||||
|
|
|
@ -471,7 +471,7 @@ class KeyfileKey(KeyfileKeyBase):
|
|||
|
||||
def save(self, target, passphrase):
|
||||
key_data = self._save(passphrase)
|
||||
with SaveFile(target, binary=False) as fd:
|
||||
with SaveFile(target) as fd:
|
||||
fd.write('%s %s\n' % (self.FILE_ID, bin_to_hex(self.repository_id)))
|
||||
fd.write(key_data)
|
||||
fd.write('\n')
|
||||
|
|
|
@ -80,10 +80,8 @@ class SyncFile:
|
|||
TODO: A Windows implementation should use CreateFile with FILE_FLAG_WRITE_THROUGH.
|
||||
"""
|
||||
|
||||
def __init__(self, path, binary=True):
|
||||
mode = 'x'
|
||||
if binary:
|
||||
mode += 'b'
|
||||
def __init__(self, path, binary=False):
|
||||
mode = 'xb' if binary else 'x'
|
||||
self.fd = open(path, mode)
|
||||
self.fileno = self.fd.fileno()
|
||||
|
||||
|
@ -122,13 +120,13 @@ class SaveFile:
|
|||
Must be used as a context manager (defining the scope of the transaction).
|
||||
|
||||
On a journaling file system the file contents are always updated
|
||||
atomically and won't become corrupted, even on pure failures or
|
||||
atomically and won't become corrupted, even on power failures or
|
||||
crashes (for caveats see SyncFile).
|
||||
"""
|
||||
|
||||
SUFFIX = '.tmp'
|
||||
|
||||
def __init__(self, path, binary=True):
|
||||
def __init__(self, path, binary=False):
|
||||
self.binary = binary
|
||||
self.path = path
|
||||
self.tmppath = self.path + self.SUFFIX
|
||||
|
|
|
@ -228,7 +228,7 @@ class SyncFile(BaseSyncFile):
|
|||
disk in the immediate future.
|
||||
"""
|
||||
|
||||
def __init__(self, path, binary=True):
|
||||
def __init__(self, path, binary=False):
|
||||
super().__init__(path, binary)
|
||||
self.offset = 0
|
||||
self.write_window = (16 * 1024 ** 2) & ~PAGE_MASK
|
||||
|
|
|
@ -160,7 +160,7 @@ class Repository:
|
|||
|
||||
def save_config(self, path, config):
|
||||
config_path = os.path.join(path, 'config')
|
||||
with SaveFile(config_path, binary=False) as fd:
|
||||
with SaveFile(config_path) as fd:
|
||||
config.write(fd)
|
||||
|
||||
def save_key(self, keydata):
|
||||
|
@ -731,7 +731,7 @@ class LoggedIO:
|
|||
if not os.path.exists(dirname):
|
||||
os.mkdir(dirname)
|
||||
sync_dir(os.path.join(self.path, 'data'))
|
||||
self._write_fd = SyncFile(self.segment_filename(self.segment))
|
||||
self._write_fd = SyncFile(self.segment_filename(self.segment), binary=True)
|
||||
self._write_fd.write(MAGIC)
|
||||
self.offset = MAGIC_LEN
|
||||
return self._write_fd
|
||||
|
|
Loading…
Reference in New Issue