pw_software_update: Fix bugs in update_bundle.py
No-Docs-Update-Reason: bug fix
Change-Id: I97370b61d49bc51eba6c8e4dcb1430ff4440cad1
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/61300
Reviewed-by: Joe Ethier <jethier@google.com>
Commit-Queue: Ali Zhang <alizhang@google.com>
diff --git a/pw_software_update/py/pw_software_update/update_bundle.py b/pw_software_update/py/pw_software_update/update_bundle.py
index ae6887d..e99f89d 100644
--- a/pw_software_update/py/pw_software_update/update_bundle.py
+++ b/pw_software_update/py/pw_software_update/update_bundle.py
@@ -50,11 +50,15 @@
if not tuf_repo.is_dir():
raise ValueError('TUF repository must be a directory.')
target_payloads = {}
- for path in tuf_repo.glob('*'):
+ for path in tuf_repo.glob('**/*'):
+ if path.is_dir():
+ continue
+
rel_path = path.relative_to(tuf_repo)
if rel_path in exclude:
continue
- target_file_name = str(rel_path)
+
+ target_file_name = str(rel_path.as_posix())
if remap_paths:
if rel_path in remap_paths:
target_file_name = remap_paths[rel_path]
@@ -107,15 +111,17 @@
'--out',
type=Path,
help='Output path for serialized UpdateBundle')
- parser.add_argument('-e'
+ parser.add_argument('-e',
'--exclude',
type=Path,
nargs='+',
+ default=tuple(),
help='Exclude a path from the TUF repository')
parser.add_argument('-r',
'--remap',
type=str,
nargs='+',
+ default=tuple(),
help='Remap a path to a custom target file name')
return parser.parse_args()
diff --git a/pw_software_update/py/update_bundle_test.py b/pw_software_update/py/update_bundle_test.py
index 8954117..9b47e3c 100644
--- a/pw_software_update/py/update_bundle_test.py
+++ b/pw_software_update/py/update_bundle_test.py
@@ -33,13 +33,14 @@
(temp_root / 'foo.bin').write_bytes(foo_bytes)
(temp_root / 'bar.bin').write_bytes(bar_bytes)
(temp_root / 'baz.bin').write_bytes(baz_bytes)
- (temp_root / 'qux.exe').write_bytes(qux_bytes)
+ (temp_root / 'subdir').mkdir()
+ (temp_root / 'subdir' / 'qux.exe').write_bytes(qux_bytes)
bundle = update_bundle.gen_unsigned_update_bundle(temp_root)
self.assertEqual(foo_bytes, bundle.target_payloads['foo.bin'])
self.assertEqual(bar_bytes, bundle.target_payloads['bar.bin'])
self.assertEqual(baz_bytes, bundle.target_payloads['baz.bin'])
- self.assertEqual(qux_bytes, bundle.target_payloads['qux.exe'])
+ self.assertEqual(qux_bytes, bundle.target_payloads['subdir/qux.exe'])
def test_excludes(self):
"""Checks that excludes are excluded from update bundles."""