106 $this->data = array();
108 $this->hashEncoding = $this->_parseHashEncoding(
$fileName);
112 }
else if (is_dir(dirname($this->fileName))) {
113 touch($this->fileName);
131 $hashLen = ($this->hashEncoding ==
'sha1') ? 40 : 32;
132 $lines = readLines($this->fileName, $this->fileEncoding);
134 foreach ($lines as $line) {
135 $hash = trim(substr($line, 0, $hashLen));
136 $payload = trim(substr($line, $hashLen));
138 if (strlen($payload) > 0) {
139 $manifest[$payload] = $hash;
143 $this->data = $manifest;
152 public function clear()
154 $this->data = array();
155 file_put_contents($this->fileName,
'');
165 public function update($fileList)
169 foreach ($fileList as $file) {
170 if (file_exists($file)) {
172 $csums[$this->_makeRelative($file)] = $hash;
176 $this->data = $csums;
192 return hash_file($this->hashEncoding,
$fileName);
211 foreach ($this->data as $path => $hash) {
212 array_push($output,
"$hash $path\n");
232 if (array_key_exists(
$fileName, $this->data)) {
234 }
else if (array_key_exists($this->_makeRelative(
$fileName), $this->data)) {
235 return $this->data[$this->_makeRelative(
$fileName)];
315 "-$hashEncoding.txt",
344 $errLen = count($errors);
347 if (! file_exists($this->fileName)) {
348 $basename = basename($this->fileName);
351 array($basename,
"$basename does not exist.")
359 foreach ($this->data as
$fileName => $hash) {
360 $fullPath = $this->pathPrefix .
$fileName;
361 if (! file_exists($fullPath)) {
374 return ($errLen == count($errors));
391 private function _parseHashEncoding($filename)
394 if (preg_match(
'/-(sha1|md5)\.txt$/', $filename, $matches)) {
411 private function _resetFileName(
$fileName=
null)
416 $this->hashEncoding = $this->_parseHashEncoding(
$fileName);
432 private function _makeRelative($filename)
434 $rel = substr($filename, strlen($this->pathPrefix));