Skip to content

Commit

Permalink
Avoid usueless double calls to rescanLibraries()
Browse files Browse the repository at this point in the history
Previously rescanLibraries() was automatically called internally in
setLibrariesFolder(). This lead to double calls to rescanLibraries()
when setLibrariesFolder() was used in combination with an explicit
call to rescanLibraries().

This commit adds a new method setLibrariesFoldersAndRescan(..) and
removes the internal call to rescanLibraries() from setLibrariesFolder().

The existing setLibrariesFolder()+rescanLibraries() combos have been
replaced with setLibrariesFoldersAndRescan().

Fix arduino#10228
  • Loading branch information
ricardojlrufino authored and cmaglie committed May 25, 2020
1 parent cc65234 commit b914070
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 4 additions & 6 deletions app/test/cc/arduino/contributions/UpdatableLibraryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public void testUpdatableLibrary() throws Exception {
LibrariesIndexer indexer = new LibrariesIndexer(index_SD_only);
BaseNoGui.librariesIndexer = indexer;
indexer.parseIndex();
indexer.setLibrariesFolders(folders);
indexer.rescanLibraries();
indexer.setLibrariesFoldersAndRescan(folders);

ContributedLibrary sdLib = indexer.getIndex().getInstalled("SD").get();
assertTrue("SD lib is installed", sdLib.isLibraryInstalled());
Expand All @@ -46,7 +45,7 @@ public void testUpdatableLibrary() throws Exception {
assertTrue(ContributionsSelfCheck.checkForUpdatableLibraries());

folders.add(new UserLibraryFolder(SD121, Location.SKETCHBOOK));
indexer.setLibrariesFolders(folders);
indexer.setLibrariesFoldersAndRescan(folders);

sdLib = indexer.getIndex().getInstalled("SD").get();
assertTrue("SD lib is installed", sdLib.isLibraryInstalled());
Expand All @@ -63,8 +62,7 @@ public void testUpdatableLibraryWithBundled() throws Exception {
LibrariesIndexer indexer = new LibrariesIndexer(index_Bridge_only);
BaseNoGui.librariesIndexer = indexer;
indexer.parseIndex();
indexer.setLibrariesFolders(folders);
indexer.rescanLibraries();
indexer.setLibrariesFoldersAndRescan(folders);

ContributedLibrary l = indexer.getIndex().getInstalled("Bridge").get();
assertTrue("Bridge lib is installed", l.isLibraryInstalled());
Expand All @@ -73,7 +71,7 @@ public void testUpdatableLibraryWithBundled() throws Exception {
assertTrue(ContributionsSelfCheck.checkForUpdatableLibraries());

folders.add(new UserLibraryFolder(Bridge170, Location.SKETCHBOOK));
indexer.setLibrariesFolders(folders);
indexer.setLibrariesFoldersAndRescan(folders);

l = indexer.getIndex().getInstalled("Bridge").get();
assertTrue("Bridge lib is installed", l.isLibraryInstalled());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@ private void parseIndex(File file) throws IOException {
}

public void setLibrariesFolders(List<UserLibraryFolder> folders) {
librariesFolders = folders;
this.librariesFolders = folders;
}

public void setLibrariesFoldersAndRescan(List<UserLibraryFolder> folders) {
setLibrariesFolders(folders);
rescanLibraries();
}

Expand Down

0 comments on commit b914070

Please sign in to comment.