8000 Fix incorrect use of Path.getRoot() (#8751) · DataDog/dd-trace-java@37f0190 · GitHub
[go: up one dir, main page]

Skip to content

Commit 37f0190

Browse files
authored
Fix incorrect use of Path.getRoot() (#8751)
* Fix incorrect use of Path.getRoot() * Adjust tests
1 parent 15c0957 commit 37f0190

File tree

2 files changed

+4
-27
lines changed

2 files changed

+4
-27
lines changed

dd-java-agent/agent-profiling/profiling-controller/src/main/java/com/datadog/profiling/controller/TempLocationManager.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,9 @@ private void createTempDir(Path tempDir) {
465465
// we will find the first offender not having the expected permissions and fail the check
466466
if (isPosixFs) {
467467
// take the first subfolder below the base temp dir
468-
Path root = baseTempDir.resolve(baseTempDir.relativize(tempDir).getRoot());
468+
// we can wave the checks for tempDir being a subdir of baseTempDir because that's how it is
469+
// created
470+
Path root = baseTempDir.resolve(baseTempDir.relativize(tempDir).getName(0));
469471
try {
470472
AtomicReference<Path> failed = new AtomicReference<>();
471473
Files.walkFileTree(

dd-java-agent/agent-profiling/profiling-controller/src/test/java/com/datadog/profiling/controller/TempLocationManagerTest.java

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.util.UUID;
2020
import java.util.concurrent.Phaser;
2121
import java.util.concurrent.TimeUnit;
22-
import java.util.concurrent.atomic.AtomicBoolean;
2322
import java.util.concurrent.locks.LockSupport;
2423
import java.util.stream.Stream;
2524
import org.junit.jupiter.api.Test;
@@ -80,8 +79,7 @@ void testFromConfigNotWritable() throws Exception {
8079
Properties props = new Properties();
8180
props.put(ProfilingConfig.PROFILING_TEMP_DIR, myDir.toString());
8281
ConfigProvider configProvider = ConfigProvider.withPropertiesOverride(props);
83-
TempLocationManager tempLocationManager = new TempLocationManager(configProvider);
84-
assertThrows(IllegalStateException.class, tempLocationManager::getTempDir);
82+
assertThrows(IllegalStateException.class, () -> new TempLocationManager(configProvider));
8583
}
8684

8785
@ParameterizedTest
@@ -246,29 +244,6 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
246244
assertEquals(shouldSucceed, rslt);
247245
}
248246

249-
@Test
250-
void testShortCircuit() throws Exception {
251-
Path baseDir =
252-
Files.createTempDirectory(
253-
"ddprof-test-",
254-
PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwx------")));
255-
AtomicBoolean executed = new AtomicBoolean();
256-
TempLocationManager.CleanupHook hook =
257-
new TempLocationManager.CleanupHook() {
258-
@Override
259-
public void onCleanupStart(boolean selfCleanup, long timeout, TimeUnit unit) {
260-
executed.set(true);
261-
}
262-
};
263-
TempLocationManager instance = instance(baseDir, false, hook);
264-
265-
instance.createDirStructure();
266-
267-
boolean ret = instance.cleanup(false);
268-
assertTrue(ret);
269-
assertFalse(executed.get());
270-
}
271-
272247
private static Stream<Arguments> timeoutTestArguments() {
273248
List<Arguments> argumentsList = new ArrayList<>();
274249
for (boolean selfCleanup : new boolean[] {true, false}) {

0 commit comments

Comments
 (0)
0