[FIX] Probably fix access profileMap with multiple threads

This commit is contained in:
Gravita 2025-06-28 21:40:43 +07:00
parent b149686abd
commit 101d8c7275

View file

@ -23,6 +23,7 @@
import java.nio.file.*; import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes; import java.nio.file.attribute.BasicFileAttributes;
import java.util.*; import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Stream; import java.util.stream.Stream;
public class LocalProfilesProvider extends ProfilesProvider implements Reconfigurable { public class LocalProfilesProvider extends ProfilesProvider implements Reconfigurable {
@ -196,7 +197,7 @@ private void readCache(Path file) throws IOException {
public void readProfilesDir() throws IOException { public void readProfilesDir() throws IOException {
Path profilesDirPath = Path.of(profilesDir); Path profilesDirPath = Path.of(profilesDir);
Map<UUID, LocalProfile> newProfiles = new HashMap<>(); Map<UUID, LocalProfile> newProfiles = new ConcurrentHashMap<>();
IOHelper.walk(profilesDirPath, new ProfilesFileVisitor(newProfiles), false); IOHelper.walk(profilesDirPath, new ProfilesFileVisitor(newProfiles), false);
profilesMap = newProfiles; profilesMap = newProfiles;
} }
@ -218,7 +219,7 @@ public void readUpdatesDir() throws IOException {
public void sync(Collection<String> dirs) throws IOException { public void sync(Collection<String> dirs) throws IOException {
logger.info("Syncing updates dir"); logger.info("Syncing updates dir");
Map<String, HashedDir> newUpdatesDirMap = new HashMap<>(16); Map<String, HashedDir> newUpdatesDirMap = new ConcurrentHashMap<>(16);
try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(Path.of(updatesDir))) { try (DirectoryStream<Path> dirStream = Files.newDirectoryStream(Path.of(updatesDir))) {
for (final Path updateDir : dirStream) { for (final Path updateDir : dirStream) {
if (Files.isHidden(updateDir)) if (Files.isHidden(updateDir))