/** * Initialize the sync process: read the files (new, update, delete) and add them to the queue. */ public function init() { $this->out(SyncOutput::STARTUP_MESSAGE); $this->manager->init(); $this->addNewFilesToQueue($this->manager->sortDirectoriesUp($this->manager->getNewFiles())); $this->addFilesToUpdateToQueue($this->manager->getFiles($this->manager->getFilesToUpdate($this->settings->checkFileSize()))); if ($this->settings->delete()) { $this->addFilesToDeleteToQueue($this->manager->sortDirectoriesDown($this->manager->getFilesToDelete())); } if ($this->getFirstFromQueue()) { $this->out('lineBreak'); } $this->outputHelper->setTotal($this->total()); }
/** * Decrypt the given output. * * @param OutputContract $input * @param OutputContract $output * @param SyncOutputContract $console */ public function decrypt(OutputContract $input, OutputContract $output, SyncOutputContract $console = null) { $files = $input->listContents('', true); if ($console) { $console->setTotal(count($files)); } foreach ($files as $file) { if ($file['type'] == 'dir') { if ($console) { $console->out(SyncOutput::ENC_ENCRYPT_FILE, ['file' => $file['path']]); } continue; } try { $fileContents = $this->crypto->decrypt($input->read($file['path']), $this->key); if ($output->has($file['path'])) { $output->update($file['path'], $fileContents); } else { $output->write($file['path'], $fileContents); } unset($fileContents); if ($console) { $console->out(SyncOutput::ENC_DECRYPT_FILE, ['file' => $file['path']]); } } catch (GeneralSecurityException $e) { if ($console) { $console->out(SyncOutput::ENC_DECRYPT_FILE, ['file' => $file['path'], 'output' => $e]); } } } }