Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MCR-2885 proposal for a start of a more controlled handling of "alien objects"… #1841

Draft
wants to merge 3 commits into
base: 2022.06.x
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -563,12 +563,18 @@ public List<String> listIDsOfType(String type) {
public List<String> listIDs() {
try (Stream<Path> streamBasePath = list(basePath)) {
return streamBasePath.flatMap(projectPath -> {
final String project = projectPath.getFileName().toString();
return list(projectPath).flatMap(typePath -> {
final String type = typePath.getFileName().toString();
final String base = getStoryKey(project, type);
return listIDsForBase(base).stream();
});
if (isProjectDirSane(projectPath)) {
final String project = projectPath.getFileName().toString();
return list(projectPath).flatMap(typePath -> {
if (isTypeDirSane(typePath)) {
final String type = typePath.getFileName().toString();
final String base = getStoryKey(project, type);
return listIDsForBase(base).stream();
}
return Stream.empty();
});
}
return Stream.empty();
}).collect(Collectors.toList());
}
}
Expand All @@ -592,7 +598,65 @@ public Collection<String> getObjectBaseIds() {
.collect(Collectors.toSet());
}
}


/**
*
* @param path
* @return true when usable project
*/
private boolean isProjectDirSane(Object path) {
return projectDirStatus(path) > 0;
}

/**
*
* @param path
* @return: 0 - not usable / no project
* 1 - clean
* 2 - dirty
*
*/
//TODO: consider sanity checks like getObjectTypes() does. (performance penalty?)
private int projectDirStatus(Object path) {
File p = new File(path.toString());
golsch marked this conversation as resolved.
Show resolved Hide resolved
if (!p.isDirectory()) {
LOGGER.warn(
"File '{}' spotted in data-directory where only subdirectories are expected.",
p.getAbsolutePath()
);
return 0;
}
return 1;
}

/**
*
* @param path
* @return true when usable type directory (inside project)
*/
private boolean isTypeDirSane(Object path) {
return typeDirStatus(path) > 0;
}

/**
*
* @param path
* @return: 0 - not usable / no type dir
* 1 - clean
* 2 - dirty
*/
private int typeDirStatus(Object path) {
File p = new File(path.toString());
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9% of developers fix this issue

PATH_TRAVERSAL_IN: This API (java/io/File.(Ljava/lang/String;)V) reads a file whose location might be specified by user input


ℹ️ Expand to see all @sonatype-lift commands

You can reply with the following commands. For example, reply with @sonatype-lift ignoreall to leave out all findings.

Command Usage
@sonatype-lift ignore Leave out the above finding from this PR
@sonatype-lift ignoreall Leave out all the existing findings from this PR
@sonatype-lift exclude <file|issue|path|tool> Exclude specified file|issue|path|tool from Lift findings by updating your config.toml file

Note: When talking to LiftBot, you need to refresh the page to see its response.
Click here to add LiftBot to another repo.

if (!p.isDirectory()) {
LOGGER.warn(
kkrebs marked this conversation as resolved.
Show resolved Hide resolved
"File '{}' spotted in data-directory where only subdirectories are expected.",
p.getAbsolutePath()
);
return 0;
}
return 1;
}

/**
* Returns the entries of the given path. Throws a MCRException if an I/O-Exceptions occur.
*
Expand Down