From 32d4340e76ef851173f6caafe8b055d064e7ae8c Mon Sep 17 00:00:00 2001 From: MascoSkray Date: Tue, 25 Apr 2017 13:06:44 +0800 Subject: [PATCH] fix: data uploaded by zip success but not commited and can't checkout using svn If we upload data and problem.conf online, we may cannot checkout the existing data using svn. This commit fixed it. Also changed some button's position. --- uoj/1/app/controllers/problem_data_manage.php | 35 +++++++++---------- uoj/1/app/libs/uoj-svn-lib.php | 30 ++++++++++++++++ 2 files changed, 46 insertions(+), 19 deletions(-) diff --git a/uoj/1/app/controllers/problem_data_manage.php b/uoj/1/app/controllers/problem_data_manage.php index a714f64..860bb2f 100644 --- a/uoj/1/app/controllers/problem_data_manage.php +++ b/uoj/1/app/controllers/problem_data_manage.php @@ -74,21 +74,19 @@ EOD; //上传数据 if($_POST['problem_data_file_submit']=='submit'){ - if ($_FILES["problem_data_file"]["error"] > 0) - { + if ($_FILES["problem_data_file"]["error"] > 0){ $errmsg = "Error: ".$_FILES["problem_data_file"]["error"]; becomeMsgPage('
' . $errmsg . '
返回'); } - else - { + else{ //if($_FILES["problem_data_file"]["type"]=='application/zip'){ $up_filename="/tmp/".rand(0,100000000)."data.zip"; move_uploaded_file($_FILES["problem_data_file"]["tmp_name"], $up_filename); $zip = new ZipArchive; - if ($zip->open($up_filename) === TRUE) - { + if ($zip->open($up_filename) === TRUE){ $zip->extractTo("/var/svn/problem/{$problem['id']}/cur/{$problem['id']}/1"); $zip->close(); + svnCommitZipData($problem['id'], 'data'); echo ""; }else{ $errmsg = "解压失败!"; @@ -104,7 +102,6 @@ EOD; //添加配置文件 if($_POST['problem_settings_file_submit']=='submit'){ - if($_POST['use_builtin_checker'] and $_POST['n_tests'] and $_POST['input_pre'] and $_POST['input_suf'] and $_POST['output_pre'] and $_POST['output_suf'] and $_POST['time_limit'] and $_POST['memory_limit']){ if(!is_dir("/var/svn/problem/{$problem['id']}/cur/{$problem['id']}/1/")){ mkdir("/var/svn/problem/{$problem['id']}/cur/{$problem['id']}/1/"); @@ -138,12 +135,12 @@ EOD; fwrite($setfile, "time_limit ".$_POST['time_limit']."\n"); fwrite($setfile, "memory_limit ".$_POST['memory_limit']."\n"); fclose($setfile); + svnCommitZipData($problem['id'], 'conf'); if(!$has_legacy){ echo ""; }else{ echo ""; } - }else{ $errmsg = "添加配置文件失败,请检查是否所有输入框都已填写!"; becomeMsgPage('
' . $errmsg . '
返回'); @@ -167,7 +164,7 @@ EOD;

svn://{$http_host}/problem/{$problem['id']}

- +
@@ -771,16 +768,16 @@ EOD
@@ -863,10 +860,10 @@ EOD -
- diff --git a/uoj/1/app/libs/uoj-svn-lib.php b/uoj/1/app/libs/uoj-svn-lib.php index 1c68d96..cf141ea 100644 --- a/uoj/1/app/libs/uoj-svn-lib.php +++ b/uoj/1/app/libs/uoj-svn-lib.php @@ -362,4 +362,34 @@ EOD error_log('hack successfully but sync failed.'); } } + + function svnCommitZipData($problem, $type) { + $id = $problem['id']; + $cur_dir = "/var/svn/problem/$id/cur/$id"; + $svnusr = UOJConfig::$data['svn']['our-root']['username']; + $svnpwd = UOJConfig::$data['svn']['our-root']['password']; + + if($type=='conf'){ + exec( +<<