Skip to content

Commit 658445c

Browse files
authored
Fix OS X metadata folder not ignored when installing lib from zip (#1228)
1 parent 2ed6dd0 commit 658445c

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

Diff for: arduino/libraries/librariesmanager/install.go

+3
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ func (lm *LibrariesManager) InstallZipLib(ctx context.Context, archivePath strin
124124
return err
125125
}
126126

127+
// Ignores metadata from Mac OS X
128+
paths.FilterOutPrefix("__MACOSX")
129+
127130
if len(paths) > 1 {
128131
return fmt.Errorf("archive is not valid: multiple files found in zip file top level")
129132
}

Diff for: test/test_lib.py

+34
Original file line numberDiff line numberDiff line change
@@ -834,3 +834,37 @@ def test_lib_upgrade_using_library_with_invalid_version(run_command, data_dir):
834834
data = json.loads(res.stdout)
835835
assert len(data) == 1
836836
assert "" != data[0]["library"]["version"]
837+
838+
839+
def test_install_zip_lib_with_macos_metadata(run_command, data_dir, downloads_dir):
840+
# Initialize configs to enable --zip-path flag
841+
env = {
842+
"ARDUINO_DATA_DIR": data_dir,
843+
"ARDUINO_DOWNLOADS_DIR": downloads_dir,
844+
"ARDUINO_SKETCHBOOK_DIR": data_dir,
845+
"ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL": "true",
846+
}
847+
assert run_command("config init --dest-dir .", custom_env=env)
848+
849+
lib_install_dir = Path(data_dir, "libraries", "fake-lib")
850+
# Verifies library is not already installed
851+
assert not lib_install_dir.exists()
852+
853+
zip_path = Path(__file__).parent / "testdata" / "fake-lib.zip"
854+
# Test zip-path install
855+
res = run_command(f"lib install --zip-path {zip_path}")
856+
assert res.ok
857+
assert "--git-url and --zip-path flags allow installing untrusted files, use it at your own risk." in res.stdout
858+
859+
# Verifies library is installed in expected path
860+
assert lib_install_dir.exists()
861+
files = list(lib_install_dir.glob("**/*"))
862+
assert lib_install_dir / "library.properties" in files
863+
864+
# Reinstall library
865+
assert run_command(f"lib install --zip-path {zip_path}")
866+
867+
# Verifies library remains installed
868+
assert lib_install_dir.exists()
869+
files = list(lib_install_dir.glob("**/*"))
870+
assert lib_install_dir / "library.properties" in files

Diff for: test/testdata/fake-lib.zip

635 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)