Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OS X metadata folder not ignored when installing lib from zip #1228

Merged
merged 1 commit into from
Mar 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions arduino/libraries/librariesmanager/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ func (lm *LibrariesManager) InstallZipLib(ctx context.Context, archivePath strin
return err
}

// Ignores metadata from Mac OS X
paths.FilterOutPrefix("__MACOSX")

if len(paths) > 1 {
return fmt.Errorf("archive is not valid: multiple files found in zip file top level")
}
Expand Down
34 changes: 34 additions & 0 deletions test/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,3 +834,37 @@ def test_lib_upgrade_using_library_with_invalid_version(run_command, data_dir):
data = json.loads(res.stdout)
assert len(data) == 1
assert "" != data[0]["library"]["version"]


def test_install_zip_lib_with_macos_metadata(run_command, data_dir, downloads_dir):
# Initialize configs to enable --zip-path flag
env = {
"ARDUINO_DATA_DIR": data_dir,
"ARDUINO_DOWNLOADS_DIR": downloads_dir,
"ARDUINO_SKETCHBOOK_DIR": data_dir,
"ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL": "true",
}
assert run_command("config init --dest-dir .", custom_env=env)

lib_install_dir = Path(data_dir, "libraries", "fake-lib")
# Verifies library is not already installed
assert not lib_install_dir.exists()

zip_path = Path(__file__).parent / "testdata" / "fake-lib.zip"
# Test zip-path install
res = run_command(f"lib install --zip-path {zip_path}")
assert res.ok
assert "--git-url and --zip-path flags allow installing untrusted files, use it at your own risk." in res.stdout

# Verifies library is installed in expected path
assert lib_install_dir.exists()
files = list(lib_install_dir.glob("**/*"))
assert lib_install_dir / "library.properties" in files

# Reinstall library
assert run_command(f"lib install --zip-path {zip_path}")

# Verifies library remains installed
assert lib_install_dir.exists()
files = list(lib_install_dir.glob("**/*"))
assert lib_install_dir / "library.properties" in files
Binary file added test/testdata/fake-lib.zip
Binary file not shown.