|
40 | 40 | */ |
41 | 41 | package org.graalvm.buildtools.agent; |
42 | 42 |
|
43 | | -import java.io.File; |
44 | 43 | import java.io.IOException; |
45 | 44 | import java.io.InputStream; |
46 | 45 | import java.io.Serializable; |
47 | | -import java.nio.file.CopyOption; |
48 | | -import java.nio.file.Files; |
49 | | -import java.nio.file.Path; |
50 | | -import java.nio.file.StandardCopyOption; |
| 46 | +import java.nio.file.*; |
51 | 47 | import java.util.ArrayList; |
52 | 48 | import java.util.Collection; |
53 | 49 | import java.util.List; |
@@ -151,16 +147,18 @@ private void addDefaultAccessFilter() { |
151 | 147 | } |
152 | 148 |
|
153 | 149 | try(InputStream accessFilter = AgentConfiguration.class.getResourceAsStream(DEFAULT_ACCESS_FILTER_FILE)) { |
154 | | - if (accessFilter != null) { |
155 | | - if (!Files.exists(agentDir)) { |
156 | | - Files.createDirectory(agentDir); |
157 | | - } |
158 | | - |
159 | | - Files.copy(accessFilter, accessFilterFile, StandardCopyOption.REPLACE_EXISTING); |
160 | | - accessFilterFiles.add(accessFilterFile.toString()); |
161 | | - } else { |
| 150 | + if (accessFilter == null) { |
162 | 151 | throw new IOException("Cannot find access-filter.json on default location: " + DEFAULT_ACCESS_FILTER_FILE); |
163 | 152 | } |
| 153 | + |
| 154 | + try { |
| 155 | + Files.createDirectory(agentDir); |
| 156 | + } catch (FileAlreadyExistsException e) { |
| 157 | + System.out.println("Agent directory already exists probably because other thread or process created it."); |
| 158 | + } |
| 159 | + |
| 160 | + Files.copy(accessFilter, accessFilterFile, StandardCopyOption.REPLACE_EXISTING); |
| 161 | + accessFilterFiles.add(accessFilterFile.toString()); |
164 | 162 | } catch (IOException e) { |
165 | 163 | throw new RuntimeException("Cannot add default access-filter.json" ,e); |
166 | 164 | } |
|
0 commit comments