Skip to content

Commit

Permalink
launder logged file paths (#4543)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladak committed Feb 16, 2024
1 parent 9a60c0c commit 28599fd
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
import org.opengrok.indexer.logger.LoggerFactory;

import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;

import static org.opengrok.indexer.web.Laundromat.launderLog;

/**
* Represents a gatekeeper that decides whether a particular file or directory
* is acceptable for history or code analysis with respect to configuration of
Expand Down Expand Up @@ -59,12 +60,13 @@ public boolean accept(File file) {
if (!includedNames.isEmpty()
&& // the filter should not affect directory names
(!(file.isDirectory() || includedNames.match(file)))) {
LOGGER.log(Level.FINER, "not including ''{0}''", file.getAbsolutePath());

LOGGER.finer(() -> String.format("not including '%s'", launderLog(file.getAbsolutePath())));
return false;
}

if (ignoredNames.ignore(file)) {
LOGGER.log(Level.FINER, "ignoring ''{0}''", file.getAbsolutePath());
LOGGER.finer(() -> String.format("ignoring '%s'", launderLog(file.getAbsolutePath())));
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

/*
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
*/
package org.opengrok.indexer.history;

Expand All @@ -40,6 +40,8 @@
import java.util.logging.Level;
import java.util.logging.Logger;

import static org.opengrok.indexer.web.Laundromat.launderLog;

public class FileAnnotationCache extends AbstractCache implements AnnotationCache {

private static final Logger LOGGER = LoggerFactory.getLogger(FileAnnotationCache.class);
Expand Down Expand Up @@ -169,11 +171,11 @@ public Annotation get(File file, @Nullable String rev) throws CacheException {
* should be present to catch weird cases of someone not using the store() or general badness.
*/
if (storedRevision == null) {
LOGGER.log(Level.FINER, "no stored revision in annotation cache for ''{0}''", file);
LOGGER.finer(() -> String.format("no stored revision in annotation cache for '%s'",
launderLog(file.toString())));
} else if (!storedRevision.equals(latestRevision)) {
LOGGER.log(Level.FINER,
"stored revision {0} for ''{1}'' does not match latest revision {2}",
new Object[]{storedRevision, file, rev});
LOGGER.finer(() -> String.format("stored revision %s for '%s' does not match latest revision %s",
storedRevision, launderLog(file.toString()), rev));
} else {
// read from the cache
annotation = readAnnotation(file);
Expand All @@ -188,8 +190,8 @@ public Annotation get(File file, @Nullable String rev) throws CacheException {
if (fileAnnotationCacheMisses != null) {
fileAnnotationCacheMisses.increment();
}
LOGGER.log(Level.FINEST, "annotation cache miss for ''{0}'' in revision {1}",
new Object[]{file, rev});
LOGGER.finest(() -> String.format("annotation cache miss for '%s' in revision %s",
launderLog(file.toString()), rev));
return null;
}

Expand Down
Loading

0 comments on commit 28599fd

Please sign in to comment.