Fix Some Bugs
parent
1f3c5b9530
commit
722d97bd9d
|
@ -26,13 +26,17 @@ from tempfile import mkstemp
|
|||
import threading
|
||||
from collections import deque, OrderedDict
|
||||
from hashlib import sha1
|
||||
|
||||
import common
|
||||
from rangelib import RangeSet
|
||||
|
||||
__all__ = ["EmptyImage", "DataImage", "BlockImageDiff"]
|
||||
|
||||
|
||||
class Settings(object):
|
||||
# Stash size cannot exceed cache_size * threshold.
|
||||
cache_size = None
|
||||
stash_threshold = 0.8
|
||||
|
||||
|
||||
def compute_patch(src, tgt, imgdiff=False):
|
||||
srcfd, srcfile = mkstemp(prefix="src-")
|
||||
tgtfd, tgtfile = mkstemp(prefix="tgt-")
|
||||
|
@ -327,7 +331,7 @@ class BlockImageDiff(object):
|
|||
self.ImproveVertexSequence()
|
||||
|
||||
# Ensure the runtime stash size is under the limit.
|
||||
if self.version >= 2 and common.OPTIONS.cache_size is not None:
|
||||
if self.version >= 2 and Settings.cache_size is not None:
|
||||
self.ReviseStashSize()
|
||||
|
||||
# Double-check our work.
|
||||
|
@ -551,14 +555,14 @@ class BlockImageDiff(object):
|
|||
out.append("".join(free_string))
|
||||
stashed_blocks -= free_size
|
||||
|
||||
if self.version >= 2 and common.OPTIONS.cache_size is not None:
|
||||
if self.version >= 2 and Settings.cache_size is not None:
|
||||
# Sanity check: abort if we're going to need more stash space than
|
||||
# the allowed size (cache_size * threshold). There are two purposes
|
||||
# of having a threshold here. a) Part of the cache may have been
|
||||
# occupied by some recovery logs. b) It will buy us some time to deal
|
||||
# with the oversize issue.
|
||||
cache_size = common.OPTIONS.cache_size
|
||||
stash_threshold = common.OPTIONS.stash_threshold
|
||||
cache_size = Settings.cache_size
|
||||
stash_threshold = Settings.stash_threshold
|
||||
max_allowed = cache_size * stash_threshold
|
||||
assert max_stashed_blocks * self.tgt.blocksize < max_allowed, \
|
||||
'Stash size %d (%d * %d) exceeds the limit %d (%d * %.2f)' % (
|
||||
|
@ -608,7 +612,7 @@ class BlockImageDiff(object):
|
|||
|
||||
if self.version >= 2:
|
||||
self._max_stashed_size = max_stashed_blocks * self.tgt.blocksize
|
||||
OPTIONS = common.OPTIONS
|
||||
OPTIONS = Settings
|
||||
if OPTIONS.cache_size is not None:
|
||||
max_allowed = OPTIONS.cache_size * OPTIONS.stash_threshold
|
||||
print("max stashed blocks: %d (%d bytes), "
|
||||
|
@ -636,8 +640,8 @@ class BlockImageDiff(object):
|
|||
|
||||
# Compute the maximum blocks available for stash based on /cache size and
|
||||
# the threshold.
|
||||
cache_size = common.OPTIONS.cache_size
|
||||
stash_threshold = common.OPTIONS.stash_threshold
|
||||
cache_size = Settings.cache_size
|
||||
stash_threshold = Settings.stash_threshold
|
||||
max_allowed = cache_size * stash_threshold / self.tgt.blocksize
|
||||
|
||||
stashed_blocks = 0
|
||||
|
@ -1129,7 +1133,7 @@ class BlockImageDiff(object):
|
|||
return
|
||||
|
||||
pieces = 0
|
||||
cache_size = common.OPTIONS.cache_size
|
||||
cache_size = Settings.cache_size
|
||||
split_threshold = 0.125
|
||||
max_blocks_per_transfer = int(cache_size * split_threshold /
|
||||
self.tgt.blocksize)
|
||||
|
|
40
common.py
40
common.py
|
@ -1,40 +0,0 @@
|
|||
import sys
|
||||
|
||||
import blockimgdiff
|
||||
|
||||
|
||||
class Options(object):
|
||||
def __init__(self):
|
||||
platform_search_path = {
|
||||
"linux2": "out/host/linux-x86",
|
||||
"darwin": "out/host/darwin-x86",
|
||||
}
|
||||
|
||||
self.search_path = platform_search_path.get(sys.platform, None)
|
||||
self.signapk_path = "framework/signapk.jar" # Relative to search_path
|
||||
self.signapk_shared_library_path = "lib64" # Relative to search_path
|
||||
self.extra_signapk_args = []
|
||||
self.java_path = "java" # Use the one on the path by default.
|
||||
self.java_args = ["-Xmx2048m"] # The default JVM args.
|
||||
self.public_key_suffix = ".x509.pem"
|
||||
self.private_key_suffix = ".pk8"
|
||||
# use otatools built boot_signer by default
|
||||
self.boot_signer_path = "boot_signer"
|
||||
self.boot_signer_args = []
|
||||
self.verity_signer_path = None
|
||||
self.verity_signer_args = []
|
||||
self.verbose = False
|
||||
self.tempfiles = []
|
||||
self.device_specific = None
|
||||
self.extras = {}
|
||||
self.info_dict = None
|
||||
self.source_info_dict = None
|
||||
self.target_info_dict = None
|
||||
self.worker_threads = None
|
||||
# Stash size cannot exceed cache_size * threshold.
|
||||
self.cache_size = None
|
||||
self.stash_threshold = 0.8
|
||||
|
||||
|
||||
OPTIONS = Options()
|
||||
DataImage = blockimgdiff.DataImage
|
3
utils.py
3
utils.py
|
@ -7,13 +7,14 @@ from os.path import exists
|
|||
import os, errno, tempfile
|
||||
from shutil import move, rmtree
|
||||
|
||||
import common
|
||||
|
||||
import blockimgdiff
|
||||
import sparse_img
|
||||
from threading import Thread
|
||||
from random import randint, choice
|
||||
from Crypto.Cipher import AES
|
||||
from Crypto.Util.Padding import pad
|
||||
DataImage = blockimgdiff.DataImage
|
||||
# -----
|
||||
# ====================================================
|
||||
# FUNCTION: sdat2img img2sdat
|
||||
|
|
Loading…
Reference in New Issue