Esempio n. 1
0
 /**
  * Re-sends a problem to Grader.
  *
  * @param Request $r
  * @throws InvalidDatabaseOperationException
  */
 public static function apiRejudge(Request $r)
 {
     // Init
     self::initializeGrader();
     // Get the user who is calling this API
     self::authenticateRequest($r);
     self::validateDetailsRequest($r);
     if (!Authorization::CanEditRun($r['current_user_id'], $r['run'])) {
         throw new ForbiddenAccessException('userNotAllowed');
     }
     self::$log->info('Run being rejudged!!');
     // Try to delete existing directory, if exists.
     try {
         $grade_dir = RunController::getGradePath($r['run']);
         FileHandler::DeleteDirRecursive($grade_dir);
     } catch (Exception $e) {
         // Soft error :P
         self::$log->warn($e);
     }
     try {
         self::$grader->Grade([$r['run']->guid], true, $r['debug'] || false);
     } catch (Exception $e) {
         self::$log->error('Call to Grader::grade() failed:');
         self::$log->error($e);
     }
     $response = array();
     $response['status'] = 'ok';
     self::invalidateCacheOnRejudge($r['run']);
     // Expire ranks
     UserController::deleteProblemsSolvedRankCacheList();
     return $response;
 }
Esempio n. 2
0
                    $zip = new ZipArchive();
                    $zip->open("{$dirname}/interactive.zip", ZipArchive::CREATE | ZipArchive::OVERWRITE);
                    $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dirname), RecursiveIteratorIterator::LEAVES_ONLY);
                    foreach ($files as $name => $file) {
                        if ($file->isDir()) {
                            continue;
                        }
                        if ($file->getFilename() == 'interactive.zip') {
                            continue;
                        }
                        $filePath = $file->getRealPath();
                        $relativePath = substr($filePath, strlen($dirname) + 1);
                        // Add current file to archive
                        $zip->addFile($filePath, $relativePath);
                    }
                    $zip->close();
                    header('Content-Type: application/zip');
                    header("Content-Disposition: attachment; filename={$_POST['name']}.zip");
                    readfile("{$dirname}/interactive.zip");
                    FileHandler::DeleteDirRecursive($dirname);
                    die;
                }
            }
        } catch (Exception $e) {
            $smarty->assign('error', $e);
        } finally {
            FileHandler::DeleteDirRecursive($dirname);
        }
    }
}
$smarty->display('../../../templates/libinteractive.gen.tpl');
Esempio n. 3
0
 public function cleanup()
 {
     if ($this->tmpDir != null && is_dir($this->tmpDir)) {
         FileHandler::DeleteDirRecursive($this->tmpDir);
     }
     // Something went wrong and the target directory was not committed. Rollback.
     if ($this->created && !file_exists($this->targetDir)) {
         FileHandler::DeleteDirRecursive($this->gitDir);
     }
 }
Esempio n. 4
0
 static function CleanPath($path)
 {
     FileHandler::DeleteDirRecursive($path);
     mkdir($path, 0755, true);
 }