From 2f105eaf2d1b91510684ac4007dcff6eafd1b151 Mon Sep 17 00:00:00 2001 From: William Schaefer Date: Wed, 15 Aug 2018 10:08:42 -0400 Subject: [PATCH] Add back a deprecated PathValidater.isValid method for public API --- .../autopsy/coreutils/PathValidator.java | 60 +++++++++++++------ 1 file changed, 42 insertions(+), 18 deletions(-) diff --git a/Core/src/org/sleuthkit/autopsy/coreutils/PathValidator.java b/Core/src/org/sleuthkit/autopsy/coreutils/PathValidator.java index 71c8ec292c..e3b091174a 100644 --- a/Core/src/org/sleuthkit/autopsy/coreutils/PathValidator.java +++ b/Core/src/org/sleuthkit/autopsy/coreutils/PathValidator.java @@ -1,15 +1,15 @@ /* * Autopsy Forensic Browser - * - * Copyright 2013-2014 Basis Technology Corp. + * + * Copyright 2013-2018 Basis Technology Corp. * Contact: carrier sleuthkit 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); + } }