A helper method to verify if the local file path from GS matches
what's parsed locally. This is for security purpose as documented in
SNOW-15153.

@param localFilePathFromGS the local file path to verify
@throws SnowflakeSQLException
488079
private void verifyLocalFilePath(String localFilePathFromGS)
  throws SnowflakeSQLException
  {
    if (command == null)
    {
      logger.error("null command");
      return;
    }

    if (command.indexOf(FILE_PROTOCOL) < 0)
    {
      logger.error(
          "file:// prefix not found in command: {}", command);
      return;
    }

    int localFilePathBeginIdx = command.indexOf(FILE_PROTOCOL) +
                                FILE_PROTOCOL.length();
    boolean isLocalFilePathQuoted =
        (localFilePathBeginIdx > FILE_PROTOCOL.length()) &&
        (command.charAt(localFilePathBeginIdx - 1 - FILE_PROTOCOL.length()) == '\'');

    // the ending index is exclusive
    int localFilePathEndIdx = 0;
    String localFilePath = "";

    if (isLocalFilePathQuoted)
    {
      // look for the matching quote
      localFilePathEndIdx = command.indexOf("'", localFilePathBeginIdx);
      if (localFilePathEndIdx > localFilePathBeginIdx)
      {
        localFilePath = command.substring(localFilePathBeginIdx,
                                          localFilePathEndIdx);
      }
      // unescape backslashes to match the file name from GS
      localFilePath = localFilePath.replaceAll("\\\\\\\\", "\\\\");
    }
    else
    {
      // look for the first space or new line or semi colon
      List<Integer> indexList = new ArrayList<>();
      char[] delimiterChars = {' ', '\n', ';'};
      for (int i = 0; i < delimiterChars.length; i++)
      {
        int charIndex = command.indexOf(delimiterChars[i], localFilePathBeginIdx);
        if (charIndex != -1)
        {
          indexList.add(charIndex);
        }
      }

      localFilePathEndIdx = indexList.isEmpty() ? -1 : Collections.min(indexList);

      if (localFilePathEndIdx > localFilePathBeginIdx)
      {
        localFilePath = command.substring(localFilePathBeginIdx,
                                          localFilePathEndIdx);
      }
      else if (localFilePathEndIdx == -1)
      {
        localFilePath = command.substring(localFilePathBeginIdx);
      }
    }

    if (!localFilePath.isEmpty() && !localFilePath.equals(localFilePathFromGS))
    {
      throw new SnowflakeSQLException(SqlState.INTERNAL_ERROR,
                                      ErrorCode.INTERNAL_ERROR.getMessageCode(),
                                      "Unexpected local file path from GS. From GS: " +
                                      localFilePathFromGS + ", expected: " + localFilePath);
    }
    else if (localFilePath.isEmpty())
    {
      logger.debug(
          "fail to parse local file path from command: {}", command);
    }
    else
    {
      logger.trace(
          "local file path from GS matches local parsing: {}", localFilePath);
    }
  }
867712
private boolean findJavaSourceFiles(String[] args) {
        String prev = "";
        for (String s : args) {
            if (s.endsWith(".java") && !prev.equals("-xf") && !prev.equals("-if")) {
                return true;
            }
            prev = s;
        }
        return false;
    }
991470
function(path_segments) {

		if (Lava.schema.VALIDATE_OBJECT_PATHS) {

			if (!(path_segments[0] in Lava.parsers.Common.LITERALS) && this.valid_globals.indexOf(path_segments[0]) == -1) {
				Lava.t("ObjectParser: invalid external path. Text: " + path_segments.join('.'));
			}

		}

	}
1239981
private boolean isMatchingFieldError(final String path, final CsvFieldError fieldError) {
        
        if (fieldError.getField().equals(path)) {
            return true;
        }
        
        if(path.endsWith("*")) {
            String subPath = path.substring(0, path.length()-1);
            return fieldError.getField().startsWith(subPath);
        }
        
        return false;
    }
1348535
protected String checkValidAliasPath(String path, Locale locale) {

        if (org.opencms.db.CmsAlias.ALIAS_PATTERN.matcher(path).matches()) {
            return null;
        } else {
            return Messages.get().getBundle(locale).key(Messages.ERR_ALIAS_INVALID_PATH_0);
        }
    }
478013
public void copyFromLocalFile(boolean delSrc, boolean overwrite, 
                                Path[] srcs, Path dst)
    throws IOException {
    fs.copyFromLocalFile(delSrc, overwrite, srcs, dst);
  }
280827
public boolean matches(String resourcePath) {
    if (!valid) {
      return false;
    }
    if (resourcePath == null) {
      return acceptsContextPathEmpty;
    }
    if (contextPathRegex != null && !contextPathRegex.matcher(resourcePath).matches()) {
      return false;
    }
    if (contextPathBlacklistRegex != null && contextPathBlacklistRegex.matcher(resourcePath).matches()) {
      return false;
    }
    return true;
  }
722053
public boolean matches(String path) {
        List<String> segments;

        segments = Filesystem.SEPARATOR.split(path);
        if (segments.size() < minDepth || segments.size() > maxDepth) {
            return false;
        }
        if (predicates.size() > 0) {
            throw new UnsupportedOperationException("cannot match with predicates");
        }
        return matches(0, segments, new ArrayList<>(includes), new ArrayList<>(excludes));
    }
227276
protected InputStream getLocalFileInputStream(String path, String dataType, TestContext context) throws IOException {
        if (dataType.equals(DataType.ASCII.name())) {
            String content = context.replaceDynamicContentInString(FileUtils.readToString(FileUtils.getFileResource(path)));
            return new ByteArrayInputStream(content.getBytes(FileUtils.getDefaultCharset()));
        } else {
            return FileUtils.getFileResource(path).getInputStream();
        }
    }
367687
def path_localLocationCheck(self, d_msg, **kwargs):
        
        b_pull                      = False
        d_meta                      = d_msg['meta']
        if 'do' in d_meta:
            if d_meta['do'] == 'pull':
                b_pull              = True
        if 'local' in d_meta:
            d_local                 = d_meta['local']
        if 'to' in d_meta:
            d_local                 = d_meta['to']

        str_localPathFull           = d_local['path']
        str_localPath, str_unpack   = os.path.split(str_localPathFull)
        str_msg                     = ''
        str_checkedDir              = str_localPathFull

        b_isFile                    = os.path.isfile(str_localPathFull)
        b_isDir                     = os.path.isdir(str_localPathFull)
        b_exists                    = os.path.exists(str_localPathFull)

        if 'pull' in d_msg['action'] or b_pull:
            # If we are "pulling" data to local, then we assume the local
            # directory does not exist. If it does, and if 'createDir' is 'true', 
            # we remove the localPath and re-create it, thus assuring it will 
            # only contain the info pulled from the remote source.
            # If 'writeInExisting' is 'true', then execution continues, but
            # may fail if the pulled target exists in the localPath.

            str_checkedDir              = str_localPath
            b_isFile                    = os.path.isfile(str_localPath)
            b_isDir                     = os.path.isdir(str_localPath)
            b_exists                    = os.path.exists(str_localPath)

            if 'createDir' in d_local.keys():
                if d_local['createDir']:
                    if os.path.isdir(str_localPathFull):
                        self.dp.qprint('Removing local path %s...' % str_localPathFull)
                        shutil.rmtree(str_localPathFull)
                        str_msg         = 'Removed existing local path... '
                    self.dp.qprint('Creating empty local path %s...' % str_localPathFull)
                    os.makedirs(str_localPathFull)
                    b_exists = True
                    str_msg += 'Created new local path'
            else:
                str_msg = 'local path already exists!'
                if 'writeInExisting' in d_local.keys():
                    if not d_local['writeInExisting']: 
                        if b_isDir: b_exists = False
                else:
                    if b_isDir: b_exists = False

        d_ret = {
            'action':   d_msg['action'],
            'dir':      str_checkedDir,
            'status':   b_exists,
            'isfile':   b_isFile,
            'isdir':    b_isDir,
            'msg':      str_msg
        }

        return {'check':        d_ret,
                'status':       d_ret['status'],
                'timestamp':    '%s' % datetime.datetime.now()}
912132
private Path[] getMapFiles(FileSystem fs, boolean isLocal)
  throws IOException {
    List<Path> fileList = new ArrayList<Path>();
    if (isLocal) {
      // for local jobs
      for(int i = 0; i < numMaps; ++i) {
        fileList.add(mapOutputFile.getInputFile(i, getTaskID()));
      }
    } else {
      // for non local jobs
      for (FileStatus filestatus : mapOutputFilesOnDisk) {
        fileList.add(filestatus.getPath());
      }
    }
    return fileList.toArray(new Path[0]);
  }
347910
public void setFilePaths(String... filePaths) {
		Path[] paths = new Path[filePaths.length];
		for (int i = 0; i < paths.length; i++) {
			paths[i] = new Path(filePaths[i]);
		}
		setFilePaths(paths);
	}
738826
public void copyToLocalFile(Path src, Path dst, boolean copyCrc)
    throws IOException {
    if (!fs.isDirectory(src)) { // source is a file
      fs.copyToLocalFile(src, dst);
      FileSystem localFs = getLocal(getConf()).getRawFileSystem();
      if (localFs.isDirectory(dst)) {
        dst = new Path(dst, src.getName());
      }
      dst = getChecksumFile(dst);
      if (localFs.exists(dst)) { //remove old local checksum file
        localFs.delete(dst, true);
      }
      Path checksumFile = getChecksumFile(src);
      if (copyCrc && fs.exists(checksumFile)) { //copy checksum file
        fs.copyToLocalFile(checksumFile, dst);
      }
    } else {
      FileStatus[] srcs = listStatus(src);
      for (FileStatus srcFile : srcs) {
        copyToLocalFile(srcFile.getPath(), 
                        new Path(dst, srcFile.getPath().getName()), copyCrc);
      }
    }
  }
527387
public static FtpMessage put(String localPath, DataType type) {
        return put(localPath, FileUtils.getFileResource(localPath).getFilename(), type);
    }
832159
protected boolean validClassFilePath(String path)
	{
		if(path==null)
		{
			return false;
		}
		File file=new File(path);
		return file.exists()&&file.isFile();
	}
1348112
private boolean isValidFile(String s, Set<JavaFileObject.Kind> fileKinds) {
        JavaFileObject.Kind kind = getKind(s);
        return fileKinds.contains(kind);
    }
953616
def glob_files_locally(folder_path, pattern):
    """"""

    pattern = os.path.join(
        folder_path, pattern.lstrip('/')) if pattern else None

    len_folder_path = len(folder_path) + 1
    for root, _, files in os.walk(folder_path):
        for f in files:
            full_path = os.path.join(root, f)
            if not pattern or _match_path(full_path, pattern):
                yield (full_path, full_path[len_folder_path:])