mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-25 01:06:50 +00:00
Merge pull request #3167 from ThomasWaldmann/security-use-savefile
cache: use SaveFile for more safety, fixes #3158
This commit is contained in:
commit
ac0ad9adf0
1 changed files with 6 additions and 6 deletions
|
@ -85,11 +85,11 @@ def save(self, manifest, key):
|
|||
logger.debug('security: current location %s', current_location)
|
||||
logger.debug('security: key type %s', str(key.TYPE))
|
||||
logger.debug('security: manifest timestamp %s', manifest.timestamp)
|
||||
with open(self.location_file, 'w') as fd:
|
||||
with SaveFile(self.location_file) as fd:
|
||||
fd.write(current_location)
|
||||
with open(self.key_type_file, 'w') as fd:
|
||||
with SaveFile(self.key_type_file) as fd:
|
||||
fd.write(str(key.TYPE))
|
||||
with open(self.manifest_ts_file, 'w') as fd:
|
||||
with SaveFile(self.manifest_ts_file) as fd:
|
||||
fd.write(manifest.timestamp)
|
||||
|
||||
def assert_location_matches(self, cache_config=None):
|
||||
|
@ -119,7 +119,7 @@ def assert_location_matches(self, cache_config=None):
|
|||
raise Cache.RepositoryAccessAborted()
|
||||
# adapt on-disk config immediately if the new location was accepted
|
||||
logger.debug('security: updating location stored in cache and security dir')
|
||||
with open(self.location_file, 'w') as fd:
|
||||
with SaveFile(self.location_file) as fd:
|
||||
fd.write(repository_location)
|
||||
if cache_config:
|
||||
cache_config.save()
|
||||
|
@ -470,7 +470,7 @@ def create(self):
|
|||
self.cache_config.create()
|
||||
ChunkIndex().write(os.path.join(self.path, 'chunks'))
|
||||
os.makedirs(os.path.join(self.path, 'chunks.archive.d'))
|
||||
with SaveFile(os.path.join(self.path, 'files'), binary=True) as fd:
|
||||
with SaveFile(os.path.join(self.path, 'files'), binary=True):
|
||||
pass # empty file
|
||||
|
||||
def _do_open(self):
|
||||
|
@ -844,7 +844,7 @@ def wipe_cache(self):
|
|||
shutil.rmtree(os.path.join(self.path, 'chunks.archive.d'))
|
||||
os.makedirs(os.path.join(self.path, 'chunks.archive.d'))
|
||||
self.chunks = ChunkIndex()
|
||||
with open(os.path.join(self.path, 'files'), 'wb'):
|
||||
with SaveFile(os.path.join(self.path, 'files'), binary=True):
|
||||
pass # empty file
|
||||
self.cache_config.manifest_id = ''
|
||||
self.cache_config._config.set('cache', 'manifest', '')
|
||||
|
|
Loading…
Reference in a new issue