summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rwxr-xr-xtools/fat16copy.py11
-rw-r--r--tools/releasetools/blockimgdiff.py28
2 files changed, 24 insertions, 15 deletions
diff --git a/tools/fat16copy.py b/tools/fat16copy.py
index af8bd838cc..c20930a475 100755
--- a/tools/fat16copy.py
+++ b/tools/fat16copy.py
@@ -234,11 +234,16 @@ class fat_dir(object):
data.seek(0)
data_file.write(data.read())
- def new_subdirectory(self, name):
+ def open_subdirectory(self, name):
"""
- Create a new subdirectory of this directory with the given name.
+ Open a subdirectory of this directory with the given name. If the
+ subdirectory doesn't exist, a new one is created instead.
Returns a fat_dir().
"""
+ for dent in self.dentries:
+ if dent.longname == name:
+ return dent.open_directory()
+
chunk = self.backing.fs.allocate(1)
(shortname, ext) = self.make_short_name(name)
new_dentry = self.add_dentry(ATTRIBUTE_SUBDIRECTORY, shortname,
@@ -751,7 +756,7 @@ def add_item(directory, item):
base = os.path.basename(item)
if len(base) == 0:
base = os.path.basename(item[:-1])
- sub = directory.new_subdirectory(base)
+ sub = directory.open_subdirectory(base)
for next_item in sorted(os.listdir(item)):
add_item(sub, os.path.join(item, next_item))
else:
diff --git a/tools/releasetools/blockimgdiff.py b/tools/releasetools/blockimgdiff.py
index 433a010819..1edf5b2a6d 100644
--- a/tools/releasetools/blockimgdiff.py
+++ b/tools/releasetools/blockimgdiff.py
@@ -635,7 +635,7 @@ class BlockImageDiff(object):
stash_map = {}
# Create the map between a stash and its def/use points. For example, for a
- # given stash of (raw_id, sr), stashes[raw_id] = (sr, def_cmd, use_cmd).
+ # given stash of (raw_id, sr), stash_map[raw_id] = (sr, def_cmd, use_cmd).
for xf in self.transfers:
# Command xf defines (stores) all the stashes in stash_before.
for stash_raw_id, sr in xf.stash_before:
@@ -672,20 +672,10 @@ class BlockImageDiff(object):
# Check the post-command stashed_blocks.
stashed_blocks_after = stashed_blocks
if self.version == 2:
- assert stash_raw_id not in stashes
- if free_stash_ids:
- sid = heapq.heappop(free_stash_ids)
- else:
- sid = next_stash_id
- next_stash_id += 1
- stashes[stash_raw_id] = sid
stashed_blocks_after += sr.size()
else:
sh = self.HashBlocks(self.src, sr)
- if sh in stashes:
- stashes[sh] += 1
- else:
- stashes[sh] = 1
+ if sh not in stashes:
stashed_blocks_after += sr.size()
if stashed_blocks_after > max_allowed:
@@ -695,6 +685,20 @@ class BlockImageDiff(object):
replaced_cmds.append(use_cmd)
print("%10d %9s %s" % (sr.size(), "explicit", use_cmd))
else:
+ # Update the stashes map.
+ if self.version == 2:
+ assert stash_raw_id not in stashes
+ if free_stash_ids:
+ sid = heapq.heappop(free_stash_ids)
+ else:
+ sid = next_stash_id
+ next_stash_id += 1
+ stashes[stash_raw_id] = sid
+ else:
+ if sh in stashes:
+ stashes[sh] += 1
+ else:
+ stashes[sh] = 1
stashed_blocks = stashed_blocks_after
# "move" and "diff" may introduce implicit stashes in BBOTA v3. Prior to