summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Alex Deymo <deymo@google.com> 2017-01-31 15:23:29 -0800
committer Alex Deymo <deymo@google.com> 2017-02-13 16:00:07 +0000
commit9a535b51884fe52be29925e00cc4032230ad9d66 (patch)
tree70d2c1babcd500a5908531fcec36f505159ddd13
parentb99df8d27dc07e5df971a2d06d49416e421c7ae9 (diff)
fat16copy: Allow to copy files to an existing directory.
This patch re-uses existing directories when copying directories, allowing to copy files to a directory previously created. Bug: 34811400 Test: fat16copy.py fat.bin a/b/foo; fat16copy.py fat.bin c/d/foo (cherry-picked from 0af24a27a8d0dc7e1782f36a5a9963021ff8b3f6) Change-Id: I283184da18f3c4951d6c84aafa4185074791acd2
-rwxr-xr-xtools/fat16copy.py11
1 files changed, 8 insertions, 3 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: