import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
+import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributeView;
import java.nio.file.attribute.FileTime;
import java.util.Collections;
File tmp = new File(workingDir, ".sonartmp_" + i);
tmp.mkdirs();
setFileCreationDate(tmp, creationTime);
+ assumeCorrectFileCreationDate(tmp.toPath(), creationTime);
}
tempFolderProvider.provide(
FileTime creationTime = FileTime.fromMillis(time);
attributes.setTimes(creationTime, creationTime, creationTime);
}
+
+ // See SONAR-22159, the test started failing due to issues in setting the correct creation time on Cirrus, skipping the test if the problem
+ // happens
+ private void assumeCorrectFileCreationDate(Path tmp, long creationTime) throws IOException {
+ FileTime fileCreationTimeSet = Files.getFileAttributeView(tmp, BasicFileAttributeView.class).readAttributes().creationTime();
+ FileTime expectedCreationTime = FileTime.fromMillis(creationTime);
+
+ assumeTrue(String.format("Incorrect creation date set on temporary file %s: %s set instead of %s",
+ tmp.toAbsolutePath(), fileCreationTimeSet, expectedCreationTime),
+ expectedCreationTime.compareTo(fileCreationTimeSet) >= 0);
+ }
}