Verify checksum if available.

@param string $checksum
@param string $filePath

@return bool
352568
protected function verifyChecksum(string $checksum, string $filePath) : bool
    {
        // Skip if checksum is empty.
        if (empty($checksum)) {
            return true;
        }

        return $checksum === $this->getServerChecksum($filePath);
    }
1200570
public function isUploadedFile($filePath)
    {
        // If it's a serialized one.
        if (filter_var($filePath, FILTER_VALIDATE_URL)) {
            return true;
        }

        // If it's a normal filename.
        $file = $this->getUploadDir()->getFile($this->getUserDirectoryHash() . '/' . $filePath);
        if ($file->exists()) {
            return true;
        }

        return false;
    }
9982
private function fileContains($filePath, $text) {
		$fileData = file_get_contents($filePath);
		if (strpos($fileData, $text) === false ) {
			return true;
		} else {
			return false;
		}
	}
410430
private File fileExists(final String path, final long checksum) throws FrameworkException {

		final PropertyKey<Long> checksumKey = StructrApp.key(File.class, "checksum");
		final PropertyKey<String> pathKey   = StructrApp.key(File.class, "path");

		return app.nodeQuery(File.class).and(pathKey, path).and(checksumKey, checksum).getFirst();
	}
1366623
protected function findCheckCriteria($filepath, $criteria)
	{
		$match = true;
		$filename = basename($filepath);
		if ($match && isset($criteria['regexs'])) {
			if (!is_array($criteria['regexs'])) {
				$criteria['regexs'] = array($criteria['regexs']);
			}
			$match = false;
			foreach ($criteria['regexs'] as $regex) {
				if (preg_match($regex, $filename)) {
					$match = true;
					break;
				}
			}
		}
		if ($match && isset($criteria['mod_since'])) {
			$match = $criteria['mod_since'] < @filemtime($filepath);
		}
		if ($match && isset($criteria['mod_before'])) {
			$match = $criteria['mod_before'] > @filemtime($filepath);
		}
		if ($match && isset($criteria['contains'])) {
			$match = false;
			if (preg_match('/\.(.*?)$/', $filename, $matches)) {
				$extension = strtolower($matches[1]);
				if (in_array($extension, $criteria['search_extensions'])) {
					if ($contents = file_get_contents($filepath)) {
						$match = preg_match($criteria['contains'], $contents);
						unset($contents);
					}
				}
			}
		}
		return $match;
	}
956956
protected function checksum(FileInterface $entity)
    {
        $currentHash = $this->fileManager->checksumTemporaryFileByName($entity->getName());
        
        if ($entity->getHash() !== $currentHash){
            throw new FileHashChangedException($entity->getName());
        }
    }
22658
protected function _ensurePathExistence($filePath) {
        $folders = explode(DIRECTORY_SEPARATOR, $filePath);
        // discard the actual file
        array_pop($folders);
        $path = implode(DIRECTORY_SEPARATOR, $folders);
        if (file_exists($path)) {
            return;
        }
        mkdir($path, 0777, true);
    }
1072666
public function checkCreateFile($filePath)
    {
        $defaultPermissions = $this->getPermissionUtils()->getDefaultPermissions();

        if (file_exists($filePath)) {
            if (!is_writable($filePath) && !in_array($this->getPermissionUtils()->getCurrentPermission($filePath), array($defaultPermissions['file'], $defaultPermissions['dir']))) {
                return $this->getPermissionUtils()->setDefaultPermissions($filePath, true);
            }
            return true;
        }

        $pathParts = pathinfo($filePath);
        if (!file_exists($pathParts['dirname'])) {
            $dirPermission = $defaultPermissions['dir'];
            $dirPermission = is_string($dirPermission) ? base_convert($dirPermission,8,10) : $dirPermission;

            if (!$this->mkdir($pathParts['dirname'], $dirPermission, true)) {
                throw new Error('Permission denied: unable to create a folder on the server - ' . $pathParts['dirname']);
            }
        }

        if (touch($filePath)) {
            return $this->getPermissionUtils()->setDefaultPermissions($filePath, true);
        }

        return false;
    }
576745
public static function exists(string ...$filepath)
    {
        if (count($filepath) == 1) {
            return (file_exists($filepath[0]));
        } else {
            $exists = [];
            foreach ($filepath as $one) {
                array_push($exists, [$one => file_exists($one)]);
            }
            return ($exists);
        }
    }
873644
public function originalChecksums(array $checksums = null) {
        if ($checksums === null) {
            return $this->originalChecksums;
        }

        $this->originalChecksums = $checksums;

        return $this;
    }
1195149
function getChecksum(fs, path, callback) {
  getAttr(fs, path, constants.attributes.checksum, callback);
}
1234326
public static function isAnimated( $filePath ){
		$content	= file_get_contents( $filePath );
		$pos1		= 0;
		$count		= 0;
		while( $count < 2 ) # There is no point in continuing after we find a 2nd frame
		{
			$pos1	= strpos( $content, "\x00\x21\xF9\x04", $pos1 );
			if( $pos1 === FALSE )
				break;
			$pos2	= strpos( $content, "\x00\x2C", $pos1 );
			if( $pos2 === FALSE )
				break;
			else if( $pos1 + 8 == $pos2 )
				$count++;
			$pos1 = $pos2;
		}
		return $count > 1;
	}
1338350
def checksum_file(scheme, path):
    """"""
    h = getattr(hashlib, scheme)()

    with open(path, 'rb') as f:
        chunk = f.read(65535)
        while chunk:
            h.update(chunk)
            chunk = f.read(65535)
    return h.hexdigest()
1255827
public static function check($path)
	{
		if (strpos($path, '..') !== false)
		{
			throw new FilesystemException(
				sprintf(
					'%s() - Use of relative paths not permitted',
					__METHOD__
				),
				20
			);
		}

		$path = static::clean($path);

		if ((JPATH_ROOT != '') && strpos($path, static::clean(JPATH_ROOT)) !== 0)
		{
			throw new FilesystemException(
				sprintf(
					'%1$s() - Snooping out of bounds @ %2$s',
					__METHOD__,
					$path
				),
				20
			);
		}

		return $path;
	}
550151
public function isTrustedPHPDir($filepath)
    {
        if (empty($this->trusted_dir)) {
            throw new SmartyException("directory '{$filepath}' not allowed by security setting (no trusted_dir specified)");
        }

        // check if index is outdated
        if (!$this->_trusted_dir || $this->_trusted_dir !== $this->trusted_dir) {
            $this->_php_resource_dir = array();

            $this->_trusted_dir = $this->trusted_dir;
            foreach ((array) $this->trusted_dir as $directory) {
                $directory = realpath($directory);
                $this->_php_resource_dir[$directory] = true;
            }
        }

        $_filepath = realpath($filepath);
        $directory = dirname($_filepath);
        $_directory = array();
        while (true) {
            // remember the directory to add it to _resource_dir in case we're successful
            $_directory[] = $directory;
            // test if the directory is trusted
            if (isset($this->_php_resource_dir[$directory])) {
                // merge sub directories of current $directory into _resource_dir to speed up subsequent lookup
                $this->_php_resource_dir = array_merge($this->_php_resource_dir, $_directory);

                return true;
            }
            // abort if we've reached root
            if (($pos = strrpos($directory, DS)) === false || !isset($directory[2])) {
                break;
            }
            // bubble up one level
            $directory = substr($directory, 0, $pos);
        }

        throw new SmartyException("directory '{$_filepath}' not allowed by security setting");
    }
656901
def remove_checksum(path):
    

    path = '{}.md5sum'.format(path)
    if os.path.exists(path):
        os.remove(path)
52637
def checksum(path, hashfunc='md5'):
    
    import checksumdir
    hash_func = checksumdir.HASH_FUNCS.get(hashfunc)
    if not hash_func:
        raise NotImplementedError('{} not implemented.'.format(hashfunc))

    if os.path.isdir(path):
        return checksumdir.dirhash(path, hashfunc=hashfunc)

    hashvalues = []
    path_list = glob.glob(path)
    logger.debug("path_list " + str(path_list))
    for path in path_list:
        if os.path.isfile(path):
            hashvalues.append(checksumdir._filehash(path, hashfunc=hash_func))
    logger.debug(str(hashvalues))
    hash = checksumdir._reduce_hash(hashvalues, hashfunc=hash_func)
    return hash