/** * This process is alive. * * @return array|false */ public function alive() { if ($this->aliveTimestamp >= time() - $this->aliveInterval) { return; } $this->aliveTimestamp = time(); $time = (string) time(); if ($this->output->has($this->aliveFile)) { return $this->output->update($this->aliveFile, $time); } return $this->output->write($this->aliveFile, $time); }
/** * 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]); } } } }