/*
 * Autopsy Forensic Browser
 * 
 * Copyright 2013-2014 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.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.sleuthkit.autopsy.coreutils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.sleuthkit.autopsy.casemodule.Case;
import org.sleuthkit.autopsy.core.RuntimeProperties;

/**
 * Validates absolute path (e.g. to a data source or case output folder)
 * depending on case type.
 */
public final class PathValidator {

    private static final Pattern driveLetterPattern = Pattern.compile("^[Cc]:.*$");
    private static final Pattern unixMediaDrivePattern = Pattern.compile("^\\/(media|mnt)\\/.*$");

    public static boolean isValidForMultiUserCase(String path, Case.CaseType caseType) {

        if (caseType == Case.CaseType.MULTI_USER_CASE) {
            // check that path is not on "C:" drive
            if (pathOnCDrive(path)) {
                return false;
            }
        } else {
            // single user case - no validation needed
            }

        return true;
    }
    
    public static boolean isValidForRunningOnTarget(String path) {
        if(checkForLiveAutopsy()) {
            if(PlatformUtil.isWindowsOS()) {
                if(pathOnCDrive(path)){
                    return false;
                }
            }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 
     */
    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.
     *
     * @param filePath Input file absolute path
     *
     * @return true if path matches the pattern, false otherwise.
     */
    private static boolean pathOnCDrive(String filePath) {
        Matcher m = driveLetterPattern.matcher(filePath);
        return m.find();
    }
}

@@ -26,17 +26,16 @@
 owser%0A *
- 
 %0A * Copy
@@ -52,9 +52,9 @@
 -201
-4
+8
  Bas
@@ -120,17 +120,16 @@
 %3E org%0A *
- 
 %0A * Lice
@@ -301,17 +301,16 @@
 se at%0A *
- 
 %0A *     
@@ -354,17 +354,16 @@
 E-2.0%0A *
- 
 %0A * Unle
@@ -1214,16 +1214,306 @@
 .*$%22);%0A%0A
+    /**%0A     * Checks if the provided path is valid given the case type.%0A     *%0A     * @param path     - the path to validate%0A     * @param caseType - the type of case which the path is being validated for%0A     *%0A     * @return - boolean true for valid path, false for invalid path%0A     */%0A
     publ
@@ -1865,20 +1865,16 @@
         
-    
 %7D%0A%0A     
@@ -1891,28 +1891,24 @@
 true;%0A    %7D%0A
-    
 %0A    public 
@@ -1973,16 +1973,17 @@
       if
+ 
 (checkFo
@@ -2014,16 +2014,17 @@
       if
+ 
 (Platfor
@@ -2064,16 +2064,17 @@
       if
+ 
 (pathOnC
@@ -2081,24 +2081,25 @@
 Drive(path))
+ 
 %7B%0A          
@@ -2157,15 +2157,17 @@
    %7D
+ 
 else if
+ 
 (Sys
@@ -2245,16 +2245,17 @@
 a(path))
+ 
 %7B%0A      
@@ -2321,36 +2321,32 @@
 urn true;%0A    %7D%0A
-    
 %0A    /**%0A     * 
@@ -2404,25 +2404,24 @@
  disk%0A     *
- 
 %0A     * @ret
@@ -2586,36 +2586,32 @@
 Target();%0A    %7D%0A
-    
 %0A    /**%0A     * 
@@ -2667,25 +2667,24 @@
 edia%22%0A     *
- 
 %0A     * @par
@@ -2726,17 +2726,16 @@
 h%0A     *
- 
 %0A     * 
@@ -2791,17 +2791,16 @@
 therwise
- 
 %0A     */
@@ -2962,20 +2962,16 @@
 ;%0A    %7D%0A
-    
 %0A    /**
@@ -3330,11 +3330,566 @@
 );%0A    %7D
+%0A%0A    /**%0A     * Checks if the provided path is valid given the case type.%0A     *%0A     * @param path     - the path to validate%0A     * @param caseType - the type of case which the path is being validated for%0A     *%0A     * @return - boolean true for valid path, false for invalid path%0A     *%0A     * @deprecated - PathValidator.isValidForMultiUserCase directly replaces%0A     * PathValidator.isValid%0A     */%0A    @Deprecated%0A    public static boolean isValid(String path, Case.CaseType caseType) %7B%0A        return isValidForMultiUserCase(path, caseType);%0A    %7D
 %0A%7D%0A

Add back a deprecated PathValidater.isValid method for public API