mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-25 09:19:31 +00:00
Code cleanup and minor performance boost.
This commit is contained in:
parent
46c6793979
commit
514ab1f386
1 changed files with 10 additions and 36 deletions
|
@ -1,11 +1,12 @@
|
||||||
from __future__ import with_statement
|
from __future__ import with_statement
|
||||||
from ConfigParser import RawConfigParser
|
from ConfigParser import RawConfigParser
|
||||||
import fcntl
|
import fcntl
|
||||||
|
from itertools import izip_longest
|
||||||
import msgpack
|
import msgpack
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
|
||||||
from .helpers import get_cache_dir
|
from .helpers import get_cache_dir, Manifest
|
||||||
from .hashindex import ChunkIndex
|
from .hashindex import ChunkIndex
|
||||||
|
|
||||||
|
|
||||||
|
@ -122,26 +123,12 @@ def rollback(self):
|
||||||
def sync(self):
|
def sync(self):
|
||||||
"""Initializes cache by fetching and reading all archive indicies
|
"""Initializes cache by fetching and reading all archive indicies
|
||||||
"""
|
"""
|
||||||
def cb(chunk, error, id):
|
def add(id, size, csize):
|
||||||
assert not error
|
|
||||||
data = self.key.decrypt(id, chunk)
|
|
||||||
try:
|
try:
|
||||||
count, size, csize = self.chunks[id]
|
count, size, csize = self.chunks[id]
|
||||||
self.chunks[id] = count + 1, size, csize
|
self.chunks[id] = count + 1, size, csize
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.chunks[id] = 1, len(data), len(chunk)
|
self.chunks[id] = 1, size, csize
|
||||||
unpacker.feed(data)
|
|
||||||
for item in unpacker:
|
|
||||||
try:
|
|
||||||
for id, size, csize in item['chunks']:
|
|
||||||
try:
|
|
||||||
count, size, csize = self.chunks[id]
|
|
||||||
self.chunks[id] = count + 1, size, csize
|
|
||||||
except KeyError:
|
|
||||||
self.chunks[id] = 1, size, csize
|
|
||||||
pass
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
self.begin_txn()
|
self.begin_txn()
|
||||||
print 'Initializing cache...'
|
print 'Initializing cache...'
|
||||||
self.chunks.clear()
|
self.chunks.clear()
|
||||||
|
@ -150,30 +137,17 @@ def cb(chunk, error, id):
|
||||||
id = info['id']
|
id = info['id']
|
||||||
cdata = self.store.get(id)
|
cdata = self.store.get(id)
|
||||||
data = self.key.decrypt(id, cdata)
|
data = self.key.decrypt(id, cdata)
|
||||||
try:
|
add(id, len(data), len(cdata))
|
||||||
count, size, csize = self.chunks[id]
|
|
||||||
self.chunks[id] = count + 1, size, csize
|
|
||||||
except KeyError:
|
|
||||||
self.chunks[id] = 1, len(data), len(cdata)
|
|
||||||
archive = msgpack.unpackb(data)
|
archive = msgpack.unpackb(data)
|
||||||
print 'Analyzing archive:', archive['name']
|
print 'Analyzing archive:', archive['name']
|
||||||
for id in archive['items']:
|
for id, chunk in izip_longest(archive['items'], self.store.get_many(archive['items'])):
|
||||||
chunk = self.store.get(id)
|
data = self.key.decrypt(id, chunk)
|
||||||
try:
|
add(id, len(data), len(chunk))
|
||||||
count, size, csize = self.chunks[id]
|
unpacker.feed(data)
|
||||||
self.chunks[id] = count + 1, size, csize
|
|
||||||
except KeyError:
|
|
||||||
self.chunks[id] = 1, len(data), len(chunk)
|
|
||||||
unpacker.feed(self.key.decrypt(id, chunk))
|
|
||||||
for item in unpacker:
|
for item in unpacker:
|
||||||
try:
|
try:
|
||||||
for id, size, csize in item['chunks']:
|
for id, size, csize in item['chunks']:
|
||||||
try:
|
add(id, size, csize)
|
||||||
count, size, csize = self.chunks[id]
|
|
||||||
self.chunks[id] = count + 1, size, csize
|
|
||||||
except KeyError:
|
|
||||||
self.chunks[id] = 1, size, csize
|
|
||||||
pass
|
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue