Merge pull request #4044 from wschaeferB/AddPathValidatorIsValid

Add back a deprecated PathValidater.isValid method for public API
This commit is contained in:
Richard Cordovano 2018-08-15 18:54:46 -04:00 committed by GitHub
commit 418e202079
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,15 +1,15 @@
/*
* Autopsy Forensic Browser
*
* Copyright 2013-2014 Basis Technology Corp.
*
* Copyright 2013-2018 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@ -32,6 +32,14 @@ public final class PathValidator {
private static final Pattern driveLetterPattern = Pattern.compile("^[Cc]:.*$");
private static final Pattern unixMediaDrivePattern = Pattern.compile("^\\/(media|mnt)\\/.*$");
/**
* Checks if the provided path is valid given the case type.
*
* @param path - the path to validate
* @param caseType - the type of case which the path is being validated for
*
* @return - boolean true for valid path, false for invalid path
*/
public static boolean isValidForMultiUserCase(String path, Case.CaseType caseType) {
if (caseType == Case.CaseType.MULTI_USER_CASE) {
@ -41,45 +49,45 @@ public final class PathValidator {
}
} else {
// single user case - no validation needed
}
}
return true;
}
public static boolean isValidForRunningOnTarget(String path) {
if(checkForLiveAutopsy()) {
if(PlatformUtil.isWindowsOS()) {
if(pathOnCDrive(path)){
if (checkForLiveAutopsy()) {
if (PlatformUtil.isWindowsOS()) {
if (pathOnCDrive(path)) {
return false;
}
}else if(System.getProperty("os.name").toLowerCase().contains("nux") && !pathIsMedia(path)){
} else if (System.getProperty("os.name").toLowerCase().contains("nux") && !pathIsMedia(path)) {
return false;
}
}
return true;
}
/**
* Checks whether Autopsy is running from the external disk
*
*
* @return true if Autopsy is running from external USB or CD
*/
private static boolean checkForLiveAutopsy() {
return RuntimeProperties.isRunningInTarget();
}
/**
* Checks whether a file path contains "/mnt" or "/media"
*
*
* @param filePath Input file absolute path
*
* @return true if path matches the pattern, false otherwise
*
* @return true if path matches the pattern, false otherwise
*/
private static boolean pathIsMedia(String filePath) {
Matcher matcher = unixMediaDrivePattern.matcher(filePath);
return matcher.find();
}
/**
* Checks whether a file path contains drive letter defined by pattern.
*
@ -91,4 +99,20 @@ public final class PathValidator {
Matcher m = driveLetterPattern.matcher(filePath);
return m.find();
}
/**
* Checks if the provided path is valid given the case type.
*
* @param path - the path to validate
* @param caseType - the type of case which the path is being validated for
*
* @return - boolean true for valid path, false for invalid path
*
* @deprecated - PathValidator.isValidForMultiUserCase directly replaces
* PathValidator.isValid
*/
@Deprecated
public static boolean isValid(String path, Case.CaseType caseType) {
return isValidForMultiUserCase(path, caseType);
}
}