From 354e2c4673c407ece74f12f92ad3ef720720afcc Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Sun, 9 Jul 2023 02:54:42 +0800 Subject: [PATCH 1/2] feat: fix: create-project & create_component with proper file permission --- tools/idf_py_actions/create_ext.py | 12 ++++++++++-- tools/test_build_system/test_common.py | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/tools/idf_py_actions/create_ext.py b/tools/idf_py_actions/create_ext.py index 6a3e632485..f84b3dbb02 100644 --- a/tools/idf_py_actions/create_ext.py +++ b/tools/idf_py_actions/create_ext.py @@ -40,7 +40,11 @@ def is_empty_and_create(path: str, action: str) -> None: def create_project(target_path: str, name: str) -> None: - copy_tree(os.path.join(os.environ['IDF_PATH'], 'examples', 'get-started', 'sample_project'), target_path) + copy_tree( + os.path.join(os.environ['IDF_PATH'], 'examples', 'get-started', 'sample_project'), + target_path, + preserve_mode=0, + ) main_folder = os.path.join(target_path, 'main') os.rename(os.path.join(main_folder, 'main.c'), os.path.join(main_folder, '.'.join((name, 'c')))) replace_in_file(os.path.join(main_folder, 'CMakeLists.txt'), 'main', name) @@ -49,7 +53,11 @@ def create_project(target_path: str, name: str) -> None: def create_component(target_path: str, name: str) -> None: - copy_tree(os.path.join(os.environ['IDF_PATH'], 'tools', 'templates', 'sample_component'), target_path) + copy_tree( + os.path.join(os.environ['IDF_PATH'], 'tools', 'templates', 'sample_component'), + target_path, + preserve_mode=0, + ) os.rename(os.path.join(target_path, 'main.c'), os.path.join(target_path, '.'.join((name, 'c')))) os.rename(os.path.join(target_path, 'include', 'main.h'), os.path.join(target_path, 'include', '.'.join((name, 'h')))) diff --git a/tools/test_build_system/test_common.py b/tools/test_build_system/test_common.py index 3b6940b079..c46e83f5f3 100644 --- a/tools/test_build_system/test_common.py +++ b/tools/test_build_system/test_common.py @@ -237,6 +237,20 @@ def test_create_project(idf_py: IdfPyFunc, idf_copy: Path) -> None: assert ret.returncode == 4, 'Command create-project exit value is wrong.' +def test_create_project_with_idf_readonly(idf_copy: Path) -> None: + def change_to_readonly(src: Path) -> None: + for root, dirs, files in os.walk(src): + for name in dirs: + os.chmod(os.path.join(root, name), 0o555) # read & execute + for name in files: + path = os.path.join(root, name) + if '/bin/' in path: continue # skip excutables + os.chmod(os.path.join(root, name), 0o444) # readonly + logging.info('Check that command for creating new project will success if the IDF itself is readonly.') + change_to_readonly(idf_copy) + run_idf_py('create-project', '--path', str(idf_copy / 'example_proj'), 'temp_test_project') + + @pytest.mark.usefixtures('test_app_copy') def test_docs_command(idf_py: IdfPyFunc) -> None: logging.info('Check docs command') From e8ee59f68bec505aa4a7932f47243b0ac3da43a0 Mon Sep 17 00:00:00 2001 From: Marek Fiala Date: Tue, 18 Jul 2023 14:08:37 +0200 Subject: [PATCH 2/2] fix(tools): create-project with proper file permission - pre-commit fix Closes https://github.com/espressif/esp-idf/pull/11836 --- tools/test_build_system/test_common.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/test_build_system/test_common.py b/tools/test_build_system/test_common.py index c46e83f5f3..6f46de169e 100644 --- a/tools/test_build_system/test_common.py +++ b/tools/test_build_system/test_common.py @@ -241,11 +241,12 @@ def test_create_project_with_idf_readonly(idf_copy: Path) -> None: def change_to_readonly(src: Path) -> None: for root, dirs, files in os.walk(src): for name in dirs: - os.chmod(os.path.join(root, name), 0o555) # read & execute + os.chmod(os.path.join(root, name), 0o555) # read & execute for name in files: path = os.path.join(root, name) - if '/bin/' in path: continue # skip excutables - os.chmod(os.path.join(root, name), 0o444) # readonly + if '/bin/' in path: + continue # skip excutables + os.chmod(os.path.join(root, name), 0o444) # readonly logging.info('Check that command for creating new project will success if the IDF itself is readonly.') change_to_readonly(idf_copy) run_idf_py('create-project', '--path', str(idf_copy / 'example_proj'), 'temp_test_project')