Skip to content

Commit

Permalink
don't delete symlinks content
Browse files Browse the repository at this point in the history
  • Loading branch information
ericvergnaud committed Feb 12, 2021
1 parent e99363a commit f0ca114
Showing 1 changed file with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
import org.junit.runner.Description;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Locale;
import java.util.logging.Logger;

import static org.junit.Assert.assertEquals;

@SuppressWarnings("ResultOfMethodCallIgnored")
public abstract class BaseRuntimeTestSupport implements RuntimeTestSupport {

// -J-Dorg.antlr.v4.test.BaseTest.level=FINE
Expand Down Expand Up @@ -102,8 +105,7 @@ private void createTempDir() {
String prop = System.getProperty(propName);
if(prop!=null && prop.length()>0) {
tempTestDir = new File(prop);
}
else {
} else {
String dirName = getClass().getSimpleName() + "-" + Thread.currentThread().getName() + "-" + System.currentTimeMillis();
tempTestDir = new File(System.getProperty("java.io.tmpdir"), dirName);
}
Expand Down Expand Up @@ -149,26 +151,36 @@ public static void eraseDirectory(File dir) {
public static void eraseFilesInDir(File dir) {
String[] files = dir.list();
for(int i = 0; files!=null && i < files.length; i++) {
File file = new File(dir,files[i]);
if(file.isDirectory())
eraseDirectory(file);
else
file.delete();
try {
eraseFile(dir, files[i]);
} catch(IOException e) {
logger.info(e.getMessage());
}
}
}

private static void eraseFile(File dir, String name) throws IOException {
File file = new File(dir,name);
if(Files.isSymbolicLink(file.toPath()))
Files.delete(file.toPath());
else if(file.isDirectory())
eraseDirectory(file);
else
file.delete();
}

private static String detectedOS;

public static String getOS() {
if (detectedOS == null) {
String os = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
if ((os.indexOf("mac") >= 0) || (os.indexOf("darwin") >= 0)) {
if (os.contains("mac") || os.contains("darwin")) {
detectedOS = "mac";
}
else if (os.indexOf("win") >= 0) {
else if (os.contains("win")) {
detectedOS = "windows";
}
else if (os.indexOf("nux") >= 0) {
else if (os.contains("nux")) {
detectedOS = "linux";
}
else {
Expand Down

0 comments on commit f0ca114

Please sign in to comment.