Get the full hash for the provided Parsed File ID,
@param FileIDHelper $helper
@param ParsedFileID $parsedFileID
@param Filesystem $filesystem
@return bool|string
497523
private function findHashOf(FileIDHelper $helper, ParsedFileID $parsedFileID, Filesystem $filesystem)
    {
        // Re build the file ID but without the variant
        $fileID = $helper->buildFileID(
            $parsedFileID->getFilename(),
            $parsedFileID->getHash()
        );

        // Couldn't find the original file, let's bail.
        if (!$filesystem->has($fileID)) {
            return false;
        }

        // Get hash from stream
        $stream = $filesystem->readStream($fileID);
        $hc = hash_init('sha1');
        hash_update_stream($hc, $stream);
        $fullHash = hash_final($hc);

        return $fullHash;
    }
124909
protected function extractHashFromLocationHeader(array $headers)
    {
        $location = reset($headers);

        // Check if we got a Location header, otherwise something went wrong here.
        if (empty($location)) {
            return false;
        }

        $uri = new Uri($location);
        $parts = explode('/', $uri->getPath());

        // Returning just the HASH part for "api.rokka.io/organization/sourceimages/{HASH}"
        $return = array_pop($parts);
        if (null === $return) {
            return false;
        }

        return $return;
    }
462202
private function actionCacheClear(SymfonyStyle $helper)
    {
        $kernel = $this->getContainer()->get('kernel');

        if (!$kernel instanceof PMKernel) {
            $helper->note("Kernel doesn't use PMKernel. Cache should be regular");

            return null;
        }

        $user = SystemUtility::getCurrentUser();
        $dir = $kernel->getBaseTmpDir();

        $dirTillUser = [];
        foreach (explode(DIRECTORY_SEPARATOR, $dir) as $part) {
            if ($part === $user) {
                break;
            }

            $dirTillUser[] = $part;
        }

        $dir = implode(DIRECTORY_SEPARATOR, $dirTillUser);

        $command = sprintf('sudo rm -rf %s', $dir);
        $helper->comment($command);

        $process = new Process($command);
        $process->setTimeout(300);

        $process->run(function ($type, $buffer) use ($helper) {
            if (Process::ERR === $type) {
                $helper->error($buffer);
            } else {
                $helper->comment($buffer);
            }
        });

        return null;
    }
494708
public function guessFileType(FileId $fileId)
    {
        $extension = strtolower(\pathinfo($fileId->id(), PATHINFO_EXTENSION));

        foreach($this->fileTypeExtensions as $fileType => $extensions) {
            if(in_array($extension, $extensions)) {
                return $fileType;
            }
        }

        return 'file';
    }
1081867
public function __isset($helper)
  {
    if (isset($this->_helpers[$helper])) {
      $isset = true;
    } else {
      $isset = !is_null($this->_getHelper($helper));
    }
    return $isset;
  }
1061320
protected function getFilesystem($ident)
    {
        if (isset($this->filesystems[$ident])) {
            return $this->filesystems[$ident];
        }

        return null;
    }
14105
protected function getPath(string $hash, ?string $cacheContext = null, bool $confirmed = true, string $ds = '/'): string
    {
        $folderName = $this->getBaseUrl();

        if (!$confirmed) {
            $folderName .= $ds . 'uploads';
        }

        //isolate cached files
        if ($cacheContext) {
            $folderName .= $ds . 'cache' . $ds . $cacheContext;
        }

        //in order to avoid a folder with a to big number of files in
        if ($confirmed) {
            $folderName .= $ds . substr($hash, 0, 3);
        }

        //create folder if missing
        if (!file_exists($folderName)) {
            mkdir($folderName, 0777, true);
        }

        return $folderName . $ds . $hash;
    }
601382
protected function hashedCombinedFilename($combinedFile, $fileList)
    {
        $name = pathinfo($combinedFile, PATHINFO_FILENAME);
        $hash = $this->hashOfFiles($fileList);
        $extension = File::get_file_extension($combinedFile);
        return $name . '-' . substr($hash, 0, 7) . '.' . $extension;
    }
925155
public function getElement($file_id)
    {
        $ret = ['success' => false, 'message' => '', 'result'  => []];
        
        /* @var LazaretFile $lazaretFile */
        $lazaretFile = $this->getLazaretFileRepository()->find($file_id);

        if (null === $lazaretFile) {
            $ret['message'] = $this->app->trans('File is not present in quarantine anymore, please refresh');

            return $this->app->json($ret);
        }

        $ret['result'] = [
            'filename' => $lazaretFile->getOriginalName(),
            'base_id'  => $lazaretFile->getBaseId(),
            'created'  => $lazaretFile->getCreated()->format(\DateTime::ATOM),
            'updated'  => $lazaretFile->getUpdated()->format(\DateTime::ATOM),
            'pathname' => $this->app['tmp.lazaret.path'].'/'.$lazaretFile->getFilename(),
            'sha256'   => $lazaretFile->getSha256(),
            'uuid'     => $lazaretFile->getUuid(),
        ];
        $ret['success'] = true;

        return $this->app->json($ret);
    }
1022395
protected function getResourceInfoByHash($fullPathNameWithHash)
  {
    foreach ($this->resourceFilesInfo as $info)
    {
      if ($info['full_path_name_with_hash']===$fullPathNameWithHash)
      {
        return $info;
      }
    }

    $this->logError("Unknown resource file '%s'", $fullPathNameWithHash);

    return null;
  }
727886
private function getHash($mixed)
    {
        if ($mixed instanceof File) {
            $mixed = pathinfo($mixed->getHashName(), PATHINFO_EXTENSION);
        }

        return $this->container->get('claroline.utilities.misc')->generateGuid().'.'.$mixed;
    }
263209
protected function getMigrationFileName(Filesystem $filesystem): string
    {
        $timestamp = date('Y_m_d_His');

        return Collection::make($this->app->databasePath().DIRECTORY_SEPARATOR.'migrations'.DIRECTORY_SEPARATOR)
            ->flatMap(function ($path) use ($filesystem) {
                return $filesystem->glob($path.'*_create_permission_tables.php');
            })->push($this->app->databasePath()."/migrations/{$timestamp}_create_permission_tables.php")
            ->first();
    }
940847
def get_file_hash( fd, hashfunc, fd_len=None ):
    

    h = hashfunc()
    fd.seek(0, os.SEEK_SET)

    count = 0
    while True:
        buf = fd.read(65536)
        if len(buf) == 0:
            break

        if fd_len is not None:
            if count + len(buf) > fd_len:
                buf = buf[:fd_len - count]

        h.update(buf)
        count += len(buf)

    hashed = h.hexdigest()
    return hashed
831995
protected function getFullPathNameWithHash($fileInfo)
  {
    $path = $this->resourceDirFullPath;
    $path .= '/'.$fileInfo['hash'].'.'.$fileInfo['ordinal'].$this->extension;

    return $path;
  }
1282574
public static function chmodr($path, $fileMode) {
		if (!is_dir($path))
			return chmod($path, $fileMode);

		$dh = opendir($path);
		while (($file = readdir($dh)) !== false) {
			if($file != '.' && $file != '..') {
				$fullpath = $path.'/'.$file;
				if(is_link($fullpath))
					return false;
				elseif(!is_dir($fullpath) && !@chmod($fullpath, $fileMode))
						return false;
				elseif(!self::chmodr($fullpath, $fileMode))
					return false;
			}
		}
		closedir($dh);

		if(@chmod($path, $fileMode))
			return true;
		else
			return false;
	}
368320
public function getHashValue($fsTaskId)
    {
        $service = sprintf(self::API_FS_TASK_HASH, $fsTaskId);

        $result = $this->callService('GET', $service, []);

        return $result->getResult();
    }
1312277
public function createHelper($helper, $config = array())
    {
        //Create the complete identifier if a partial identifier was passed
        if (is_string($helper) && strpos($helper, '.') === false)
        {
            $identifier = $this->getIdentifier()->toArray();

            if($identifier['type'] != 'lib') {
                $identifier['path'] = array('template', 'helper');
            } else {
                $identifier['path'] = array('helper');
            }

            $identifier['name'] = $helper;
        }
        else $identifier = $this->getIdentifier($helper);

        $config = array_merge(ObjectConfig::unbox($config), ['template' => $this->getTemplate()]);

        return $this->getObject('template.helper.factory')->createHelper($identifier, $config);
    }