Skip to content

Commit

Permalink
test with file system check
Browse files Browse the repository at this point in the history
  • Loading branch information
guwirth committed Aug 26, 2024
1 parent 41cb367 commit a947a6c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileAlreadyExistsException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
Expand Down Expand Up @@ -129,6 +132,9 @@ public class CxxSquidConfiguration extends SquidConfiguration {

private static final Logger LOG = Loggers.get(CxxSquidConfiguration.class);

// case-sensitive file system or not
private static boolean isCaseSensitive = true;

private final XPathFactory xFactory = XPathFactory.instance();
private Document document;

Expand All @@ -149,6 +155,23 @@ public CxxSquidConfiguration(String baseDir) {
this(baseDir, Charset.defaultCharset());
}

public static boolean fileSystemIsCaseSensitive() throws IOException {
Path a = null, b = null;
try {
Path tempDir = Files.createTempDirectory("test");
a = Files.createFile(tempDir.resolve(Paths.get("test.test")));
b = Files.createFile(tempDir.resolve(Paths.get("TEST.TEST")));
} catch (FileAlreadyExistsException e) {
return false;
} finally {
Files.deleteIfExists(a);
if (b != null) {
Files.deleteIfExists(b);
}
}
return true;
}

/**
* Ctor.
*
Expand All @@ -158,6 +181,12 @@ public CxxSquidConfiguration(String baseDir, Charset encoding) {
super(encoding);
this.baseDir = baseDir;

try {
isCaseSensitive = fileSystemIsCaseSensitive();
} catch (IOException e) {
isCaseSensitive = true;
}

var root = new Element(ROOT);
root.setAttribute(new Attribute("version", "1.0"));
document = new Document(root);
Expand Down Expand Up @@ -553,6 +582,7 @@ public void readJsonCompilationDb() {
* Create uniform notation of path names.
*
* Normalize path and replace file separators by forward slash.
* Use lowercase path on case insensitive file systems.
*
* @param path to unify
* @return unified path
Expand All @@ -562,7 +592,11 @@ private static String unifyPath(String path) {
if (result == null) {
result = "unknown";
}
return result;
if (isCaseSensitive) {
return result;
} else {
return result.toLowerCase();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,20 +399,12 @@ private Iterable<InputFile> getInputFiles(SensorContext context, CxxSquidConfigu
if (context.config().hasKey(JSON_COMPILATION_DATABASE_KEY)
&& context.config().getBoolean(JSON_COMPILATION_DATABASE_ONLY_CONTAINED_FILES_KEY).orElse(Boolean.FALSE)) {

for (var inputFile : inputFiles) {
LOG.debug("inputFile: {}", Path.of(inputFile.uri()));
}

for (var squidFile : squidConfig.getFiles()) {
LOG.debug("squidFile: {}", squidFile);
}

// if the source of the configuration is JSON Compilation Database and analyzeOnlyContainedFiles=True,
// then analyze only the files contained in the db.
var inputFilesInConfig = new ArrayList<Path>();
// resolution of symbolic links and case-sensitive paths: In Json DB the path/filenames are often lowercase
for (var inputfile : squidConfig.getFiles()) {
try {
// resolution of symbolic links and case-sensitive paths: In Json DB the path/filenames are often lowercase
inputFilesInConfig.add(inputfile.toRealPath(LinkOption.NOFOLLOW_LINKS));
} catch (IOException | RuntimeException e) {
// ...
Expand Down

0 comments on commit a947a6c

Please sign in to comment.