/** * Is another process alive and working on this folder? * * @return bool */ public function isOtherProcessAlive() { if (!$this->output->has($this->aliveFile)) { return false; } if ($this->output->read($this->aliveFile) < time() - $this->settings->timeout()) { return false; } return true; }
/** * Get only directories from a file list. * * @param array $files * * @return array */ public function getDirs($files = []) { return array_values(array_filter($files, function ($file) { if ($file['type'] != 'dir') { return false; } if ($this->exclude($file['path'], $this->settings->excludeInput())) { return false; } return false; })); }
/** * Set output. * * @param OutputContract $output */ public function setOutput(OutputContract $output) { $this->worker->setOutput($output); $this->manager->setOutput($output); $this->settings->setOutput($output); }
/** * @param SyncSettingsContract $settings */ protected function setTimezone(SyncSettingsContract $settings) { date_default_timezone_set($settings->timezone()); }
/** * Create default encryption middleware. * * @param SyncSettingsContract $settings * @param Application $app * @param BackupCommand|null $command * * @throws PathNotFoundException */ protected function createEncryptionMiddleware(SyncSettingsContract $settings, Application &$app, BackupCommand $command = null) { if ($settings->encrypt() === false) { return; } $command = $this->getCommand($command); try { $encryptionMiddleware = new EncryptionMiddleware($settings->encrypt()); $app->middleware($encryptionMiddleware); } catch (PathNotFoundException $e) { // If we have access to the actual command object we can ask the user // if a new random encryption key should be generated and do this task // for him or her. if (!$command) { throw $e; } $helper = $command->getHelper('question'); $question = new ConfirmationQuestion("<comment>The encryption-key '" . $e->getPath() . "' doesn't exist. Create a new random one?</comment> <info>[y|n]</info>\n", false); if (!$helper->ask($input = $command->getInput(), $output = $command->getOutput(), $question)) { throw $e; } touch($e->getPath()); chmod($e->getPath(), 0600); file_put_contents($e->getPath(), (new Rand())->bytes(32)); $output->writeln(''); $this->createEncryptionMiddleware($settings, $app, $command); } }
/** * This is a local one. * Just sync and commit then. * * @param SyncContract $sync * @param SyncOutputContract $output * @param LocalOutput $outputHandler * @param SyncSettingsContract $settings */ protected function local(SyncContract &$sync, SyncOutputContract $output, LocalOutput $outputHandler, SyncSettingsContract $settings) { // Set git to local $this->git->local($outputHandler); $this->git->init(); // Override the settings for versioning $settings->setExcludeOutput(array_merge($settings->excludeOutput(), ['.git/**/*', '**/.gitignore', '**/.gitkeep'])); $settings->setDelete(true); $sync->setSettings($settings); }