Skip to content

Commit

Permalink
Merge branch 'fix/fatfsparse_construct' into 'master'
Browse files Browse the repository at this point in the history
fix(fatfsgen): Fix incompatibility with the latest version of construct

Closes IDFCI-1915

See merge request espressif/esp-idf!28374
  • Loading branch information
dobairoland committed Jan 17, 2024
2 parents ab72811 + d4d3e83 commit 9940087
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion components/fatfs/fatfsparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def remove_wear_levelling_if_exists(fs_: bytes) -> bytes:
boot_sector__.parse_boot_sector(fs_)
if boot_sector__.boot_sector_state.size == len(fs_):
return fs_
except UnicodeDecodeError:
except (UnicodeDecodeError, construct.core.StringError):
pass
plain_fs: bytes = remove_wl(fs_)
return plain_fs
Expand Down
50 changes: 25 additions & 25 deletions components/fatfs/test_fatfsgen/test_fatfsparse.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python
# SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
# SPDX-FileCopyrightText: 2021-2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0

import os
Expand Down Expand Up @@ -32,13 +32,13 @@ def tearDown(self) -> None:
@staticmethod
def test_gen_parse() -> None:
run([
'python',
sys.executable,
f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}',
'output_data/tst_str'
], stderr=STDOUT)

run(['python', '../fatfsgen.py', 'output_data/tst_str'], stderr=STDOUT)
run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
run([sys.executable, '../fatfsgen.py', 'output_data/tst_str'], stderr=STDOUT)
run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)

assert set(os.listdir('Espressif')) == {'TEST', 'TESTFILE'}
with open('Espressif/TESTFILE', 'rb') as in_:
Expand All @@ -59,7 +59,7 @@ def test_file_chaining() -> None:
fatfs.write_content(path_from_root=['WRITEF.TXT'], content=4096 * b'a' + b'a')
fatfs.write_filesystem('fatfs_image.img')

run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
with open('Espressif/WRITEF.TXT', 'rb') as in_:
assert in_.read() == 4097 * b'a'

Expand All @@ -74,7 +74,7 @@ def test_full_two_sectors_folder() -> None:
fatfs.write_content(path_from_root=['TESTFOLD', 'A255'], content=b'last')
fatfs.write_filesystem('fatfs_image.img')

run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
assert set(os.listdir('Espressif')) == {'TESTFOLD'}
assert set(os.listdir('Espressif/TESTFOLD')) == {f'A{str(i).upper()}' for i in range(256)}

Expand All @@ -88,15 +88,15 @@ def test_full_two_sectors_folder() -> None:
def test_empty_fat16() -> None:
fatfs = fatfsgen.FATFS(size=17 * 1024 * 1024)
fatfs.write_filesystem('fatfs_image.img')
run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)

@staticmethod
def test_chaining_fat16() -> None:
fatfs = fatfsgen.FATFS(size=17 * 1024 * 1024)
fatfs.create_file('WRITEF', extension='TXT')
fatfs.write_content(path_from_root=['WRITEF.TXT'], content=4096 * b'a' + b'a')
fatfs.write_filesystem('fatfs_image.img')
run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
with open('Espressif/WRITEF.TXT', 'rb') as in_:
assert in_.read() == 4097 * b'a'

Expand All @@ -109,7 +109,7 @@ def test_full_sector_folder_fat16() -> None:
fatfs.write_content(path_from_root=['TESTFOLD', 'A0'], content=b'first')
fatfs.write_content(path_from_root=['TESTFOLD', 'A126'], content=b'later')
fatfs.write_filesystem('fatfs_image.img')
run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
assert set(os.listdir('Espressif')) == {'TESTFOLD'}
assert set(os.listdir('Espressif/TESTFOLD')) == {f'A{str(i).upper()}' for i in range(128)}
with open('Espressif/TESTFOLD/A0', 'rb') as in_:
Expand All @@ -134,20 +134,20 @@ def test_e2e_file(self) -> None:
}
generate_local_folder_structure(struct_, path_='.')
run([
'python',
sys.executable,
f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}',
'testf'
], stderr=STDOUT)
run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
assert compare_folders('testf', 'Espressif')
shutil.rmtree('Espressif', ignore_errors=True)

run([
'python',
sys.executable,
f'{os.path.join(os.path.dirname(__file__), "..", "wl_fatfsgen.py")}',
'testf'
], stderr=STDOUT)
run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
assert compare_folders('testf', 'Espressif')

def test_e2e_deeper(self) -> None:
Expand All @@ -173,20 +173,20 @@ def test_e2e_deeper(self) -> None:

generate_local_folder_structure(struct_, path_='.')
run([
'python',
sys.executable,
f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}',
'testf'
], stderr=STDOUT)
run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
assert compare_folders('testf', 'Espressif')
shutil.rmtree('Espressif', ignore_errors=True)

run([
'python',
sys.executable,
f'{os.path.join(os.path.dirname(__file__), "..", "wl_fatfsgen.py")}',
'testf'
], stderr=STDOUT)
run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
assert compare_folders('testf', 'Espressif')

def test_e2e_deeper_large(self) -> None:
Expand Down Expand Up @@ -229,20 +229,20 @@ def test_e2e_deeper_large(self) -> None:
}
generate_local_folder_structure(struct_, path_='.')
run([
'python',
sys.executable,
f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}',
'testf'
], stderr=STDOUT)
run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
assert compare_folders('testf', 'Espressif')
shutil.rmtree('Espressif', ignore_errors=True)

run([
'python',
sys.executable,
f'{os.path.join(os.path.dirname(__file__), "..", "wl_fatfsgen.py")}',
'testf'
], stderr=STDOUT)
run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
assert compare_folders('testf', 'Espressif')

def test_e2e_very_deep(self) -> None:
Expand Down Expand Up @@ -287,11 +287,11 @@ def test_e2e_very_deep(self) -> None:
}
generate_local_folder_structure(struct_, path_='.')
run([
'python',
sys.executable,
f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}',
'testf'
], stderr=STDOUT)
run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
assert compare_folders('testf', 'Espressif')

def test_e2e_very_deep_long(self) -> None:
Expand All @@ -317,11 +317,11 @@ def test_e2e_very_deep_long(self) -> None:
}
generate_local_folder_structure(struct_, path_='.')
run([
'python',
sys.executable,
f'{os.path.join(os.path.dirname(__file__), "..", "fatfsgen.py")}',
'testf', '--long_name_support'
], stderr=STDOUT)
run(['python', '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
run([sys.executable, '../fatfsparse.py', 'fatfs_image.img'], stderr=STDOUT)
assert compare_folders('testf', 'Espressif')

def test_parse_long_name(self) -> None:
Expand Down

0 comments on commit 9940087

Please sign in to comment.