/**
  * Indexes document that was set in __construct.
  */
 public function indexCrawledDocuments()
 {
     $sFileName = $this->oFile->getName();
     $oFileMinorDocType = $this->oDbr->selectRow('image', 'img_minor_mime', array('img_name' => $sFileName, 'img_major_mime' => 'application'));
     if ($oFileMinorDocType === false) {
         return;
     }
     $sFileDocType = $this->mimeDecoding($oFileMinorDocType->img_minor_mime, $sFileName);
     if (!$this->checkDocType($sFileDocType, $sFileName)) {
         return;
     }
     $sFileTimestamp = $this->oFile->getTimestamp();
     $sVirtualFilePath = $this->oFile->getPath();
     $oFileRepoLocalRef = $this->oFile->getRepo()->getLocalReference($sVirtualFilePath);
     if (!is_null($oFileRepoLocalRef)) {
         $sFilePath = $oFileRepoLocalRef->getPath();
     }
     if ($this->checkExistence($sVirtualFilePath, 'repo', $sFileTimestamp, $sFileName)) {
         return;
     }
     $sFileText = $this->getFileText($sFilePath, $sFileName);
     $doc = $this->makeRepoDocument($sFileDocType, $sFileName, $sFileText, $sFilePath, $sFileTimestamp, $sVirtualFilePath);
     if ($doc) {
         // mode and ERROR_MSG_KEY are only passed for the case when addDocument fails
         $this->oMainControl->addDocument($doc, $this->mode, self::S_ERROR_MSG_KEY);
     }
 }
Example #2
0
 public function copy($destination, $overwrite = false, $mt = false)
 {
     //    if (dirname($destination) == ".") {
     //      $destination = $this->getDirectory() . DS . $destination;
     //    }
     $destination = $this->preparePath($destination);
     if (strcmp(substr($destination, -1), DS) == 0) {
         $destination .= $this->getName();
     }
     $file = new File($destination);
     $dir = new Directory($file->getDirectory());
     if (!$dir->exists() && !$dir->make()) {
         throw new FileException(array("Directory '%s' not exists.", $dir->getPath()));
     }
     if (!$overwrite && $file->exists()) {
         throw new FileException(array("File '%s' already exists.", $file->getPath()));
     }
     if ($file->exists() && !$file->delete()) {
         throw new FileException(array("File '%s' cannot be deleted.", $file->getPath()));
     }
     if (!copy($this->pathAbsolute, $file->getPathAbsolute())) {
         throw new FileException(array("Failed to copy file '%s'.", $this->path));
     }
     if ($mt) {
         $filemtime = $this->getModificationTime();
         @touch($file->getPathAbsolute(), $filemtime);
     }
     return $file;
 }
 /**
  * @return void
  */
 public function execute()
 {
     if (is_null($this->file)) {
         throw new \Exception('ファイルを指定してください');
     }
     $file = new File();
     $file->setPath('copy_of_' . $this->file->getPath());
     $file->create();
 }
Example #4
0
 /**
  * Construct the iterator with a file instance
  * @param File $file Instance of a file object.
  * @throws \InvalidArgumentException
  */
 public function __construct(File $file)
 {
     if (!$file->exists()) {
         throw new \InvalidArgumentException('The file "' . $file->getPath() . '" does not exist');
     }
     if (!$file->isReadable()) {
         throw new \InvalidArgumentException('The file "' . $file->getPath() . '" is not readable.');
     }
     $this->file = $file;
     $this->file->open('r');
 }
Example #5
0
 function testProps()
 {
     $storage_test_root = "/" . FRAMEWORK_CORE_PATH . "tests/io/storage_dir/";
     Storage::set_storage_root($storage_test_root);
     $test_file = new File("/" . FRAMEWORK_CORE_PATH . "tests/io/file_props_test.php");
     $this->assertFalse($test_file->hasStoredProps(), "Il file ha delle proprieta' con lo storage vuoto!!");
     $storage = $test_file->getStoredProps();
     $storage->add("test", array("hello" => 1, "world" => "good"));
     $this->assertTrue($test_file->hasStoredProps(), "Il file storage delle proprieta' non e' stato creato!!");
     $file_path = $test_file->getPath();
     $sum = md5($file_path);
     $store_subdir = "_" . substr($sum, 0, 1);
     $storage_test_root_dir = new Dir($storage_test_root);
     $real_store_dir = $storage_test_root_dir->getSingleSubdir();
     $all_dirs = $real_store_dir->listFiles();
     $props_file_dir = $all_dirs[0];
     $this->assertEqual($props_file_dir->getName(), $store_subdir, "La directory creata non corrisponde!!");
     $final_stored_path = new File($real_store_dir->getPath() . $props_file_dir->getName() . DS . $sum . ".ini");
     $this->assertTrue($final_stored_path->exists(), "Il file finale delle props non e' stato trovato!!");
     $test_file->deleteStoredProps();
     $this->assertFalse($test_file->hasStoredProps(), "Il file delle proprieta' non e' stato eliminato!!");
     $all_files = $real_store_dir->listFiles();
     foreach ($all_files as $f) {
         $f->delete(true);
     }
     Storage::set_storage_root(Storage::get_default_storage_root());
 }
 public function newFile($name, $contents)
 {
     $file = new File($this->t, $name);
     $path = new Folder($file->getPath());
     $path->exists() || $path->create();
     $file->out()->write($contents);
 }
Example #7
0
 protected function updateFileHeaders(File $file, array $headers)
 {
     $status = $file->getRepo()->getBackend()->describe(['src' => $file->getPath(), 'headers' => $headers]);
     if (!$status->isGood()) {
         $this->error("Encountered error: " . print_r($status, true));
     }
 }
Example #8
0
 /**
  * @return string
  */
 public function getPath() : string
 {
     if (!$this->hasPath()) {
         $this->setPath($this->createPath());
     }
     return parent::getPath();
 }
Example #9
0
 /**
  * Tests File::getPath
  */
 public function testGetPath()
 {
     $spl = $this->getFileInfo();
     $file = new File($spl);
     $path = $file->getPath();
     $this->assertEquals($spl->getPath(), $path);
 }
Example #10
0
 /**
  * Constructor - Defines the log file to be written
  *
  * @param string $filepath	Path of the log file
  */
 public function __construct($filepath)
 {
     $filepath = DATA_DIR . Config::DIR_DATA_LOGS . $filepath;
     if (!File::exists(File::getPath($filepath))) {
         throw new Exception('Log directory "' . $filepath . '" not found!');
     }
     $this->filepath = $filepath;
 }
Example #11
0
 /**
  * Executes a program and returns the return code.
  * Output from command is logged at INFO level.
  * @return int Return code from execution.
  */
 public function execute()
 {
     // test if os match
     $myos = Phing::getProperty("os.name");
     $this->log("Myos = " . $myos, PROJECT_MSG_VERBOSE);
     if ($this->os !== null && strpos($os, $myos) === false) {
         // this command will be executed only on the specified OS
         $this->log("Not found in " . $os, PROJECT_MSG_VERBOSE);
         return 0;
     }
     if ($this->dir !== null) {
         if ($this->dir->isDirectory()) {
             $currdir = getcwd();
             @chdir($this->dir->getPath());
         } else {
             throw new BuildException("Can't chdir to:" . $this->dir->__toString());
         }
     }
     if ($this->escape == true) {
         // FIXME - figure out whether this is correct behavior
         $this->command = escapeshellcmd($this->command);
     }
     if ($this->error !== null) {
         $this->command .= ' 2> ' . $this->error->getPath();
         $this->log("Writing error output to: " . $this->error->getPath());
     }
     if ($this->output !== null) {
         $this->command .= ' 1> ' . $this->output->getPath();
         $this->log("Writing standard output to: " . $this->output->getPath());
     } elseif ($this->spawn) {
         $this->command .= ' 1>/dev/null';
         $this->log("Sending ouptut to /dev/null");
     }
     // If neither output nor error are being written to file
     // then we'll redirect error to stdout so that we can dump
     // it to screen below.
     if ($this->output === null && $this->error === null) {
         $this->command .= ' 2>&1';
     }
     // we ignore the spawn boolean for windows
     if ($this->spawn) {
         $this->command .= ' &';
     }
     $this->log("Executing command: " . $this->command);
     $output = array();
     $return = null;
     exec($this->command, $output, $return);
     if ($this->dir !== null) {
         @chdir($currdir);
     }
     foreach ($output as $line) {
         $this->log($line, $this->passthru ? PROJECT_MSG_INFO : PROJECT_MSG_VERBOSE);
     }
     if ($return != 0 && $this->checkreturn) {
         throw new BuildException("Task exited with code {$return}");
     }
     return $return;
 }
Example #12
0
 function testGetSectorNames()
 {
     $f = new File("/framework/core/tests/pages/layout/my_test.layout.php");
     $l = new Layout();
     $l->__setup($f->getPath(), "my_test.layout.php", new Tree());
     $this->assertEqual(count($l->getSectorNames()), 3, "Il numero dei settori non coincide!!");
     $sector_names = $l->getSectorNames();
     $this->assertEqual($sector_names[0], "/page/headers", "Il nome del settore non coincide!! : " . $sector_names[0]);
     $this->assertEqual($sector_names[1], "/content", "Il nome del settore non coincide!! : " . $sector_names[1]);
     $this->assertEqual($sector_names[2], "/footer", "Il nome del settore non coincide!! : " . $sector_names[2]);
 }
Example #13
0
 private function get_layout_cache_key()
 {
     if ($this->layout_cache_key != null) {
         return $this->layout_cache_key;
     }
     $layout_class_source = ClassLoader::instance()->get_element_content_by_name(get_class($this));
     $f = new File("/" . $this->layout_path);
     $layout_file_path = $f->getPath();
     $layout_file_size = $f->getSize();
     $layout_modification_time = $f->getModificationTime();
     $this->layout_cache_key = md5($layout_class_source . $layout_file_path . $layout_file_size . $layout_modification_time);
     return $this->layout_cache_key;
 }
Example #14
0
 static function extract($f, $dir)
 {
     $reader = $f->openReader();
     $binarydata = $reader->read(3);
     $data = unpack("a3", $binarydata);
     if ($data[1] !== self::FF_ARCHIVE_HEADER) {
         throw new InvalidDataException("Intestazione del file non valida : " . $data[1]);
     }
     $binarydata = $reader->read(2 + 2 + 2);
     $data = unpack("v3", $binarydata);
     if ($data[1] !== self::CURRENT_MAJOR || $data[2] !== self::CURRENT_MINOR || $data[3] !== self::CURRENT_REV) {
         throw new InvalidDataException("Versione del file non supportata!! : " . $data[1] . "-" . $data[2] . "-" . $data[3]);
     }
     $binarydata = $reader->read(2);
     $data = unpack("v", $binarydata);
     $num_entries = $data[1];
     $i = 0;
     while ($i < $num_entries) {
         $binarydata = $reader->read(2);
         $data = unpack("v", $binarydata);
         $entry_type = $data[1];
         $binarydata = $reader->read(2);
         $data = unpack("v", $binarydata);
         $path_length = $data[1];
         $binarydata = $reader->read($path_length);
         $data = unpack("a*", $binarydata);
         $path = $data[1];
         if ($entry_type === self::ENTRY_TYPE_DIR) {
             $d = $dir->newSubdir($path);
             $d->touch();
         }
         if ($entry_type === self::ENTRY_TYPE_FILE) {
             $binarydata = $reader->read(4);
             $data = unpack("V", $binarydata);
             $num_bytes = $data[1];
             $compressed_file_data = $reader->read($num_bytes);
             $uncompressed_file_data = gzuncompress($compressed_file_data);
             $f = new File($dir->getPath() . $path);
             $writer = $f->openWriter();
             $writer->write($uncompressed_file_data);
             $writer->close();
             $sha1_checksum = $reader->read(20);
             if (strcmp($sha1_checksum, sha1_file($f->getFullPath(), true)) !== 0) {
                 throw new InvalidDataException("La somma sha1 non corrisponde per il file : " . $f->getPath());
             }
         }
         $i++;
     }
     $reader->close();
 }
Example #15
0
 public static function require_script_file($file)
 {
     if ($file instanceof File) {
         $file_object = $file;
     } else {
         $file_object = new File($file);
     }
     if (!$file_object->exists()) {
         throw new Exception("Script not found : " . $file);
     } else {
         $path_with_hash = $file_object->getPath() . "?hash=" . md5($file_object->getModificationTime());
         self::require_script($path_with_hash);
     }
 }
Example #16
0
 public static function require_css_file($file, $media = CSS::MEDIA_ALL)
 {
     if ($file instanceof File) {
         $file_object = $file;
     } else {
         $file_object = new File($file);
     }
     if (!$file_object->exists()) {
         throw new Exception("Css not found : " . $file);
     } else {
         $path_with_hash = $file_object->getPath() . "?hash=" . md5($file_object->getModificationTime());
         self::require_css($path_with_hash, $media);
     }
 }
 /**
  * Get the parent of the provided file
  *
  * If you provide a path like /var/www/yoursite, the parent will be /var/www
  * @param File $file
  * @return File the parent of the file
  */
 public function getParent(File $file)
 {
     $path = $file->getPath();
     if (strpos($path, File::DIRECTORY_SEPARATOR) === false) {
         $parent = new File('.');
         return new File($this->getAbsolutePath($parent));
     }
     $name = $file->getName();
     $nameLength = strlen($name);
     $parent = substr($path, 0, ($nameLength + 1) * -1);
     if (!$parent) {
         return new File(File::DIRECTORY_SEPARATOR);
     }
     return new File($parent);
 }
 public function onCreateFileImageThumbnailSource(File $file, &$imgPath, $media = null)
 {
     // The calling function might accidentally pass application/ogg videos.
     // If that's a problem, let's fix it in the calling function.
     if ($media !== 'video' || empty($file->filename)) {
         return true;
     }
     // Let's save our frame to a temporary file. If we fail, remove it.
     $imgPath = tempnam(sys_get_temp_dir(), 'socialthumb-');
     $result = exec('avconv -i ' . escapeshellarg($file->getPath()) . ' -vcodec mjpeg -vframes 1 -f image2 -an ' . escapeshellarg($imgPath));
     if (!getimagesize($imgPath)) {
         common_debug('exec of "avconv" produced a bad/nonexisting image it seems');
         @unlink($imgPath);
         $imgPath = null;
         // pretend we didn't touch it
         return true;
     }
     return false;
 }
 /**
  * Extract a ".ar" file into a given target directory
  *
  * @param   string base
  * @param   string ar
  * @param   io.Folder target
  * @throws  lang.IllegalStateException in case the target is not found
  * @throws  lang.FormatException in case the .ar-file is not parseable
  */
 protected function extract($base, $ar, Folder $target)
 {
     // Open a HTTP connection
     $url = new URL($base . $ar . '.ar');
     $r = create(new HttpConnection($url))->get();
     if (HttpConstants::STATUS_OK != $r->getStatusCode()) {
         throw new IllegalStateException(sprintf('Unexpected response %d:%s for %s', $r->getStatusCode(), $r->getMessage(), $url->getURL()));
     }
     $in = new BufferedInputStream($r->getInputStream());
     do {
         // Seach for first section header, --[LENGTH]:[FILENAME]-- and parse it
         do {
             $line = $this->readLine($in);
             if (!$in->available()) {
                 throw new FormatException('Cannot locate section header');
             }
         } while (2 !== sscanf($line, '--%d:%[^:]--', $length, $filename));
         // Calculate target file
         $file = new File($target, $filename);
         $folder = new Folder($file->getPath());
         $folder->exists() || $folder->create();
         Console::writef('     >> [%-10s] %s (%.2f kB) [%s]%s', $ar, $filename, $length / 1024, str_repeat('.', self::PROGRESS_INDICATOR_WIDTH), str_repeat("", self::PROGRESS_INDICATOR_WIDTH + 1));
         // Transfer length bytes into file
         $c = 0;
         $out = $file->getOutputStream();
         $size = 0;
         while ($size < $length) {
             $chunk = $in->read(min(0x1000, $length - $size));
             $size += strlen($chunk);
             $out->write($chunk);
             // Update progress
             $d = ceil($size / $length * self::PROGRESS_INDICATOR_WIDTH);
             if ($d == $c) {
                 continue;
             }
             Console::write(str_repeat('#', $d - $c));
             $c = $d;
         }
         $out->close();
         Console::writeLine();
     } while ($in->available() > 0);
     $in->close();
 }
Example #20
0
 /**
  * Builds the full command to execute and stores it in $command.
  *
  * @return void
  * @uses   $command
  */
 protected function buildCommand()
 {
     if ($this->command === null && $this->commandline->getExecutable() === null) {
         throw new BuildException('ExecTask: Please provide "command" OR "executable"');
     } else {
         if ($this->command === null) {
             $this->command = Commandline::toString($this->commandline->getCommandline(), $this->escape);
         } else {
             if ($this->commandline->getExecutable() === null) {
                 //we need to escape the command only if it's specified directly
                 // commandline takes care of "executable" already
                 if ($this->escape == true) {
                     $this->command = escapeshellcmd($this->command);
                 }
             } else {
                 throw new BuildException('ExecTask: Either use "command" OR "executable"');
             }
         }
     }
     if ($this->error !== null) {
         $this->command .= ' 2> ' . $this->error->getPath();
         $this->log("Writing error output to: " . $this->error->getPath(), $this->logLevel);
     }
     if ($this->output !== null) {
         $this->command .= ' 1> ' . $this->output->getPath();
         $this->log("Writing standard output to: " . $this->output->getPath(), $this->logLevel);
     } elseif ($this->spawn) {
         $this->command .= ' 1>/dev/null';
         $this->log("Sending output to /dev/null", $this->logLevel);
     }
     // If neither output nor error are being written to file
     // then we'll redirect error to stdout so that we can dump
     // it to screen below.
     if ($this->output === null && $this->error === null) {
         $this->command .= ' 2>&1';
     }
     // we ignore the spawn boolean for windows
     if ($this->spawn) {
         $this->command .= ' &';
     }
 }
 /**
  * @param File $file
  * @param bool $dumpContents
  * @return string
  */
 function writeUpload($file, $dumpContents = false)
 {
     if ($file->isOld()) {
         $archiveName = "      " . Xml::element('archivename', null, $file->getArchiveName()) . "\n";
     } else {
         $archiveName = '';
     }
     if ($dumpContents) {
         $be = $file->getRepo()->getBackend();
         # Dump file as base64
         # Uses only XML-safe characters, so does not need escaping
         # @todo Too bad this loads the contents into memory (script might swap)
         $contents = '      <contents encoding="base64">' . chunk_split(base64_encode($be->getFileContents(array('src' => $file->getPath())))) . "      </contents>\n";
     } else {
         $contents = '';
     }
     if ($file->isDeleted(File::DELETED_COMMENT)) {
         $comment = Xml::element('comment', array('deleted' => 'deleted'));
     } else {
         $comment = Xml::elementClean('comment', null, $file->getDescription());
     }
     return "    <upload>\n" . $this->writeTimestamp($file->getTimestamp()) . $this->writeContributor($file->getUser('id'), $file->getUser('text')) . "      " . $comment . "\n" . "      " . Xml::element('filename', null, $file->getName()) . "\n" . $archiveName . "      " . Xml::element('src', null, $file->getCanonicalURL()) . "\n" . "      " . Xml::element('size', null, $file->getSize()) . "\n" . "      " . Xml::element('sha1base36', null, $file->getSha1()) . "\n" . "      " . Xml::element('rel', null, $file->getRel()) . "\n" . $contents . "    </upload>\n";
 }
 /**
  * Store data
  *
  * @param   string name
  * @param   string data
  */
 protected function store($name, $data, $overwrite = TRUE)
 {
     $file = new File($this->path, $name);
     mkdir($file->getPath(), 0755, true);
     FileUtil::setContents($file, $data);
 }
Example #23
0
 public static function fromFileObject(File $file)
 {
     $imgPath = null;
     $media = common_get_mime_media($file->mimetype);
     if (Event::handle('CreateFileImageThumbnailSource', array($file, &$imgPath, $media))) {
         if (empty($file->filename) && !file_exists($imgPath)) {
             throw new UnsupportedMediaException(_('File without filename could not get a thumbnail source.'));
         }
         // First some mimetype specific exceptions
         switch ($file->mimetype) {
             case 'image/svg+xml':
                 throw new UseFileAsThumbnailException($file->id);
         }
         // And we'll only consider it an image if it has such a media type
         switch ($media) {
             case 'image':
                 $imgPath = $file->getPath();
                 break;
             default:
                 throw new UnsupportedMediaException(_('Unsupported media format.'), $file->getPath());
         }
     }
     if (!file_exists($imgPath)) {
         throw new ServerException(sprintf('Image not available locally: %s', $imgPath));
     }
     try {
         $image = new ImageFile($file->id, $imgPath);
     } catch (UnsupportedMediaException $e) {
         // Avoid deleting the original
         if ($imgPath != $file->getPath()) {
             unlink($imgPath);
         }
         throw $e;
     }
     return $image;
 }
 protected function createImagePreview(File $file, $outpath)
 {
     $magick = new Imagick($file->getPath());
     $magick->setImageFormat($this->preview_imageformat);
     $magick->writeImage($outpath);
     $magick->destroy();
     return getimagesize($outpath);
     // Verify that we wrote an understandable image.
 }
 /**
  * Delete file from index when file is deleted
  * @param File $oFile MediaWiki file object of deleted file
  * @param File $oOldimage the name of the old file
  * @param Article $oArticle reference to the article if all revisions are deleted
  * @param User $oUser user who performed the deletion
  * @param string $sReason reason
  * @return bool allow other hooked methods to be executed. Always true.
  */
 public function onFileDeleteComplete($oFile, $oOldimage, $oArticle, $oUser, $sReason)
 {
     try {
         BuildIndexMainControl::getInstance()->deleteIndexFile($oFile->getPath(), 'repo');
     } catch (BsException $e) {
         wfDebugLog('ExtendedSearch', 'onFileDeleteComplete: ' . $e->getMessage());
     }
     return true;
 }
Example #26
0
 /**
  * Attach a file to a post
  *
  * @param int $post_id		Post's id
  * @param string $filepath	Path of the tmp file
  * @param string $thumbpath	Path of the thumb (optional)
  */
 public function attachFile($post_id, $filepath, $name, $thumbpath = null, $mobilepath = null)
 {
     $ext = strtolower(File::getExtension($filepath));
     // In the DB
     $file_id = DB::createQuery('attachments')->set(array('post_id' => $post_id, 'name' => $name, 'ext' => $ext))->insert();
     // File, and optionally thumb
     $newfilepath = self::getAttachedFilePath($file_id, $ext);
     if (!File::exists(File::getPath($newfilepath))) {
         File::makeDir(File::getPath($newfilepath), 0777, true);
     }
     File::rename($filepath, $newfilepath);
     if (isset($thumbpath)) {
         File::rename($thumbpath, self::getAttachedFilePath($file_id, 'jpg', 'thumb'));
     }
     if (isset($mobilepath)) {
         File::rename($mobilepath, self::getAttachedFilePath($file_id, 'jpg', 'mobile'));
     }
 }
Example #27
0
 /**
  * Remove directory
  *
  * @param boolean $recursive (empty directory contents and remove)
  * @return boolean
  */
 public function remove($recursive = false)
 {
     if (!$this->__isDir()) {
         return false;
     }
     if (!$recursive) {
         if (!@rmdir($this->_path)) {
             $this->error = parent::_getLastError();
             return false;
         }
         return true;
     }
     // recursive remove
     foreach ($this->read(false, true) as $asset) {
         if ($asset['type'] === 'dir') {
             $dir = new Directory($this->_path . $asset['name'], false);
             if (!$dir->remove(true)) {
                 $this->error = 'Failed to remove subdirectory \'' . $dir->getPath() . '\' (' . $dir->error . '), try elevated chmod';
                 return false;
             }
         } else {
             $file = new File($this->_path . $asset['name'], false);
             if (!$file->remove()) {
                 $this->error = 'Failed to remove file \'' . $file->getPath() . '\' (' . $file->error . '), try elevated chmod';
                 return false;
             }
         }
     }
     return $this->remove();
     // finally remove base directory
 }
Example #28
0
 /**
  * Output HTTP response for file
  * Side effect: writes HTTP response to STDOUT.
  *
  * @param File $file File object with a local path (e.g. UnregisteredLocalFile,
  *   LocalFile. Oddly these don't share an ancestor!)
  * @throws SpecialUploadStashTooLargeException
  * @return bool
  */
 private function outputLocalFile(File $file)
 {
     if ($file->getSize() > self::MAX_SERVE_BYTES) {
         throw new SpecialUploadStashTooLargeException();
     }
     return $file->getRepo()->streamFile($file->getPath(), array('Content-Transfer-Encoding: binary', 'Expires: Sun, 17-Jan-2038 19:14:07 GMT'));
 }
Example #29
0
 static function extract($f, $dir)
 {
     if ($f instanceof File) {
         $source_file = $f;
     } else {
         $source_file = new File($f);
     }
     if ($dir instanceof Dir) {
         $target_dir = $dir;
     } else {
         $target_dir = new Dir($dir);
     }
     $reader = $source_file->openReader();
     $binarydata = $reader->read(3);
     $data = unpack("a3", $binarydata);
     if ($data[1] !== self::FF_ARCHIVE_HEADER) {
         throw new InvalidDataException("Intestazione del file non valida : " . $data[1]);
     }
     $binarydata = $reader->read(2 + 2 + 2);
     $data = unpack("v3", $binarydata);
     if ($data[1] !== self::CURRENT_MAJOR || $data[2] !== self::CURRENT_MINOR || $data[3] !== self::CURRENT_REV) {
         throw new InvalidDataException("Versione del file non supportata!! : " . $data[1] . "-" . $data[2] . "-" . $data[3]);
     }
     //properties
     $binarydata = $reader->read(2);
     $data = unpack("v", $binarydata);
     $properties_length = $data[1];
     if ($properties_length > 0) {
         $binarydata = $reader->read($properties_length);
         $data = unpack("a*", $binarydata);
         $properties = PropertiesUtils::readFromString($data[1], false);
     } else {
         $properties = array();
     }
     //num entries
     $binarydata = $reader->read(2);
     $data = unpack("v", $binarydata);
     $num_entries = $data[1];
     $i = 0;
     while ($i < $num_entries) {
         //entry type
         $binarydata = $reader->read(2);
         $data = unpack("v", $binarydata);
         $entry_type = $data[1];
         //path length
         $binarydata = $reader->read(2);
         $data = unpack("v", $binarydata);
         $path_length = $data[1];
         //path
         $binarydata = $reader->read($path_length);
         $data = unpack("a*", $binarydata);
         $path = $data[1];
         if ($entry_type === self::ENTRY_TYPE_DIR) {
             $d = $target_dir->newSubdir($path);
             $d->touch();
         }
         if ($entry_type === self::ENTRY_TYPE_FILE) {
             //compressed size
             $binarydata = $reader->read(4);
             $data = unpack("V", $binarydata);
             $num_bytes = $data[1];
             //compressed data
             $compressed_file_data = $reader->read($num_bytes);
             $uncompressed_file_data = gzuncompress($compressed_file_data);
             $f = new File($target_dir->getPath() . $path);
             $writer = $f->openWriter();
             $writer->write($uncompressed_file_data);
             $writer->close();
             //sha1 sum
             $sha1_checksum = $reader->read(20);
             if (strcmp($sha1_checksum, sha1_file($f->getFullPath(), true)) !== 0) {
                 throw new InvalidDataException("La somma sha1 non corrisponde per il file : " . $f->getPath());
             }
         }
         $i++;
     }
     $reader->close();
     return true;
 }
Will print '.' for each file, except for deleted ones which are marked as 'x'.

END_OF_HELP;
require_once INSTALLDIR . '/scripts/commandline.inc';
if (!have_option('y', 'yes')) {
    print "About to delete local file entries where the file cannot be found. Are you sure? [y/N] ";
    $response = fgets(STDIN);
    if (strtolower(trim($response)) != 'y') {
        print "Aborting.\n";
        exit(0);
    }
}
print "Deleting";
$file = new File();
$file->whereAdd('filename IS NOT NULL');
// local files
$file->whereAdd('filehash IS NULL', 'AND');
// without filehash value
if ($file->find()) {
    while ($file->fetch()) {
        try {
            $file->getPath();
            print '.';
        } catch (FileNotFoundException $e) {
            $file->delete();
            print 'x';
        }
    }
}
print "\nDONE.\n";