Skip to content

Library Manager commands can produce redundant installations #1870

Closed
@per1234

Description

@per1234

Describe the problem

Libraries are identified by the "real name" defined in the name field of the library.properties metadata file (or by the folder name in the case of a "legacy"/"1.0 format" library that doesn't have a metadata file).

During the implementation of the Arduino Library Manager system, an unfortunate decision was made to reuse the user's library folder (<directories.data/libraries or LIBRARY_LOCATION_USER). This can be problematic because the set of libraries recognized by Library Manager include those installed by the user via alternative methods:

Libraries installed via arduino-cli lib install are always installed to a folder named by "sanitizing" the "real name". However, installations of a library made via other methods can have any arbitrary folder name.

🐛 If a library was installed to a folder with a name different from the sanitized "real name", the Library Manager commands that install a library generate a separate installation of the library. This means that multiple libraries with the same identifier are installed in LIBRARY_LOCATION_USER, which breaks some of the Library Manager capabilities.

To reproduce

lib install demo

$ arduino-cli version
arduino-cli.exe  Version: git-snapshot Commit: 3cd782d6 Date: 2022-09-07T19:10:31Z

$ export ARDUINO_DIRECTORIES_USER="/tmp/arduino-cli-directories/user"

$ export ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL="true"

$ arduino-cli lib install --git-url https://github.com/arduino-libraries/SigFox
--git-url and --zip-path flags allow installing untrusted files, use it at your own risk.
Enumerating objects: 86, done.
Counting objects: 100% (86/86), done.
Compressing objects: 100% (62/62), done.
Total 86 (delta 30), reused 64 (delta 20), pack-reused 0
Library installed

$ ls "$ARDUINO_DIRECTORIES_USER/libraries"
SigFox/

$ arduino-cli lib list
Name                          Installed     Available         Location              Description
Arduino SigFox for MKRFox1200 1.0.5         -                 LIBRARY_LOCATION_USER -

$ arduino-cli lib install "Arduino SigFox for MKRFox1200"
Downloading Arduino SigFox for [email protected]...
Arduino SigFox for [email protected] already downloaded
Installing Arduino SigFox for [email protected]...
Installed Arduino SigFox for [email protected]

$ ls "$ARDUINO_DIRECTORIES_USER/libraries"
Arduino_SigFox_for_MKRFox1200/  SigFox/

$ arduino-cli lib list
Name                          Installed Available    Location              Description     
Arduino SigFox for MKRFox1200 1.0.4     -            LIBRARY_LOCATION_USER -
 "                            1.0.5     -            LIBRARY_LOCATION_USER -

🐛 There are now two "Arduino SigFox for MKRFox1200" libraries installed in LIBRARY_LOCATION_USER. It is impossible for some Library Manager commands to operate correctly under these conditions.

lib upgrade demo

$ arduino-cli version
arduino-cli.exe  Version: git-snapshot Commit: 3cd782d6 Date: 2022-09-07T19:10:31Z

$ export ARDUINO_DIRECTORIES_USER="/tmp/arduino-cli-directories/user"

$ export ARDUINO_LIBRARY_ENABLE_UNSAFE_INSTALL="true"

$ arduino-cli lib install --git-url https://github.com/arduino-libraries/SigFox#1.0.3  # install outdated version of library
--git-url and --zip-path flags allow installing untrusted files, use it at your own risk.
Enumerating objects: 86, done.
Counting objects: 100% (86/86), done.
Compressing objects: 100% (62/62), done.
Total 86 (delta 30), reused 64 (delta 20), pack-reused 0
Library installed

$ ls "$ARDUINO_DIRECTORIES_USER/libraries"
SigFox/

$ arduino-cli lib list
Name                          Installed     Available         Location              Description
Arduino SigFox for MKRFox1200 1.0.5         -                 LIBRARY_LOCATION_USER -

$ arduino-cli lib upgrade "Arduino SigFox for MKRFox1200"
Downloading Arduino SigFox for [email protected]...
Arduino SigFox for [email protected] already downloaded
Installing Arduino SigFox for [email protected]...
Installed Arduino SigFox for [email protected]

$ ls "$ARDUINO_DIRECTORIES_USER/libraries"
Arduino_SigFox_for_MKRFox1200/  SigFox/

$ arduino-cli lib list
Name                          Installed Available      Location              Description
Arduino SigFox for MKRFox1200 1.0.4     -              LIBRARY_LOCATION_USER -
 "                            1.0.3     1.0.4          LIBRARY_LOCATION_USER Helper library for MKRFox1200 board a...

🐛 There are now two "Arduino SigFox for MKRFox1200" libraries installed in LIBRARY_LOCATION_USER. It is impossible for some Library Manager commands to operate correctly under these conditions.

Expected behavior

arduino-cli lib commands must never result in multiple libraries with the same identifier being installed in LIBRARY_LOCATION_USER.

They should use one of the following approaches:

Remove previous installation after installing to a new folder name.

OR

Update in place, using the folder name of the existing library.

Arduino CLI version

3cd782d

Operating system

Windows, Ubuntu

Operating system version

Windows 10, Ubuntu 20.04

Additional context

This produces the conditions for #1871

Issue checklist

  • I searched for previous reports in the issue tracker
  • I verified the problem still occurs when using the nightly build
  • My report contains all necessary details

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions