Skip to content

Commit

Permalink
Make accessFilter file registration thread safe
Browse files Browse the repository at this point in the history
  • Loading branch information
dnestoro committed Oct 31, 2024
1 parent 979e9ec commit 5d84566
Showing 1 changed file with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,10 @@
*/
package org.graalvm.buildtools.agent;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.nio.file.CopyOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.nio.file.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -151,16 +147,18 @@ private void addDefaultAccessFilter() {
}

try(InputStream accessFilter = AgentConfiguration.class.getResourceAsStream(DEFAULT_ACCESS_FILTER_FILE)) {
if (accessFilter != null) {
if (!Files.exists(agentDir)) {
Files.createDirectory(agentDir);
}

Files.copy(accessFilter, accessFilterFile, StandardCopyOption.REPLACE_EXISTING);
accessFilterFiles.add(accessFilterFile.toString());
} else {
if (accessFilter == null) {
throw new IOException("Cannot find access-filter.json on default location: " + DEFAULT_ACCESS_FILTER_FILE);
}

try {
Files.createDirectory(agentDir);
} catch (FileAlreadyExistsException e) {
System.out.println("Agent directory already exists probably because other thread or process created it.");
}

Files.copy(accessFilter, accessFilterFile, StandardCopyOption.REPLACE_EXISTING);
accessFilterFiles.add(accessFilterFile.toString());
} catch (IOException e) {
throw new RuntimeException("Cannot add default access-filter.json" ,e);
}
Expand Down

0 comments on commit 5d84566

Please sign in to comment.