1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-26 01:37:20 +00:00

Merge pull request #3167 from ThomasWaldmann/security-use-savefile

cache: use SaveFile for more safety, fixes #3158
This commit is contained in:
TW 2017-10-15 01:24:36 +02:00 committed by GitHub
commit ac0ad9adf0

View file

@ -85,11 +85,11 @@ def save(self, manifest, key):
logger.debug('security: current location %s', current_location) logger.debug('security: current location %s', current_location)
logger.debug('security: key type %s', str(key.TYPE)) logger.debug('security: key type %s', str(key.TYPE))
logger.debug('security: manifest timestamp %s', manifest.timestamp) 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) 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)) 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) fd.write(manifest.timestamp)
def assert_location_matches(self, cache_config=None): def assert_location_matches(self, cache_config=None):
@ -119,7 +119,7 @@ def assert_location_matches(self, cache_config=None):
raise Cache.RepositoryAccessAborted() raise Cache.RepositoryAccessAborted()
# adapt on-disk config immediately if the new location was accepted # adapt on-disk config immediately if the new location was accepted
logger.debug('security: updating location stored in cache and security dir') 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) fd.write(repository_location)
if cache_config: if cache_config:
cache_config.save() cache_config.save()
@ -470,7 +470,7 @@ def create(self):
self.cache_config.create() self.cache_config.create()
ChunkIndex().write(os.path.join(self.path, 'chunks')) ChunkIndex().write(os.path.join(self.path, 'chunks'))
os.makedirs(os.path.join(self.path, 'chunks.archive.d')) 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 pass # empty file
def _do_open(self): def _do_open(self):
@ -844,7 +844,7 @@ def wipe_cache(self):
shutil.rmtree(os.path.join(self.path, 'chunks.archive.d')) shutil.rmtree(os.path.join(self.path, 'chunks.archive.d'))
os.makedirs(os.path.join(self.path, 'chunks.archive.d')) os.makedirs(os.path.join(self.path, 'chunks.archive.d'))
self.chunks = ChunkIndex() 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 pass # empty file
self.cache_config.manifest_id = '' self.cache_config.manifest_id = ''
self.cache_config._config.set('cache', 'manifest', '') self.cache_config._config.set('cache', 'manifest', '')