static function BackupDir($source, $dest) { if (!is_dir($source)) { return; } if (!is_dir($dest)) { @mkdir($dest, 0755); } if ($handle = opendir($source)) { while (false !== ($entry = readdir($handle))) { if ($entry == "." || $entry == "..") { continue; } $sourcePath = "{$source}/{$entry}"; $targetPath = "{$dest}/{$entry}"; if (is_dir($sourcePath)) { FileHandler::BackupDir($sourcePath, $targetPath); } else { link($sourcePath, $targetPath); } } closedir($handle); } }
public function commit($message, $user) { $this->git('add .', $this->tmpDir); $this->requiresRejudge = false; $changedFiles = false; foreach (explode('\\n', $this->git('status -s --porcelain', $this->tmpDir)) as $line) { if ($line == '') { // Happens when the input is empty. continue; } $changedFiles = true; $path = substr($line, 3); if (strpos($path, '.git') === 0 || strpos($path, 'statements/') === 0 || strpos($path, 'examples/') === 0 || strpos($path, 'interactive/examples/') === 0) { continue; } $this->requiresRejudge = true; } if (!$changedFiles) { // No changes detected. Return happily. $this->log->debug('No files changed.'); return; } elseif ($this->requiresRejudge) { $this->log->debug('Files changed, rejudge required.'); } else { $this->log->debug('Files changed.'); } $this->git('config user.email ' . escapeshellarg("{$user->username}@omegaup"), $this->tmpDir); $this->git('config user.name ' . escapeshellarg($user->username), $this->tmpDir); $this->git('config push.default matching', $this->tmpDir); $this->git('commit -am ' . escapeshellarg($message), $this->tmpDir); $this->git('push origin master', $this->tmpDir); if (!file_exists($this->targetDir . DIRECTORY_SEPARATOR . '.git')) { $this->git('clone ' . escapeshellarg($this->gitDir) . ' ' . escapeshellarg($this->targetDir), PROBLEMS_PATH); } else { $this->git('pull --rebase', $this->targetDir); } // Copy the libinteractive templates to a publically accessible location. $publicDestination = TEMPLATES_PATH . "/{$this->alias}/"; if (is_dir($publicDestination)) { FileHandler::DeleteDirRecursive($publicDestination); } if (is_dir("{$this->tmpDir}/interactive/generated")) { FileHandler::BackupDir("{$this->tmpDir}/interactive/generated", $publicDestination); } }