diff options
| author | Bruno Ribas <brunoribas@gmail.com> | 2023-03-01 15:28:41 +0000 |
|---|---|---|
| committer | Davi Antônio da Silva Santos <antoniossdavi@gmail.com> | 2023-03-04 01:35:16 +0000 |
| commit | cec49620aa67bb376f212ca2aa2be7c00c9da8ea (patch) | |
| tree | ccbf7cd68067745dcf4e25ea96d622756122b4bd /src/admin/report | |
| parent | 734dce195d2d60117a520211c8e8e0ea94267dc4 (diff) | |
| download | boca-cec49620aa67bb376f212ca2aa2be7c00c9da8ea.tar.gz boca-cec49620aa67bb376f212ca2aa2be7c00c9da8ea.zip | |
webcast.php: Add lock to avoid sending corrupted files
Signed-off-by: Bruno Ribas <brunoribas@gmail.com>
Diffstat (limited to 'src/admin/report')
| -rw-r--r-- | src/admin/report/webcast.php | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/src/admin/report/webcast.php b/src/admin/report/webcast.php index 5189809..3798115 100644 --- a/src/admin/report/webcast.php +++ b/src/admin/report/webcast.php @@ -62,6 +62,10 @@ if($i>=count($wcdata)) { exit; } +//$fplock = fopen($webcastdir . '.lock',"r+"); +//flock($fplock,LOCK_EX); +//sleep(10); + //cleardir($webcastdir); @mkdir($webcastdir); @@ -314,17 +318,23 @@ while(list($e, $c) = each($score)) { } if(is_writable($webcastdir)) { - @file_put_contents($webcastdir . $ds . 'runs',$runfile); + $fplock = fopen($webcastdir . '.lock',"w"); + flock($fplock,LOCK_EX); + fwrite($fplock,"teste\n"); + @file_put_contents($webcastdir . $ds . 'runs',$runfile,LOCK_EX); if($contestfile!='') - @file_put_contents($webcastdir . $ds . 'contest',$contestfile); - @file_put_contents($webcastdir . $ds . 'version',$versionfile); - @file_put_contents($webcastdir . $ds . 'time',$timefile); - @file_put_contents($webcastdir . $ds . 'icpc',$icpcfile); + @file_put_contents($webcastdir . $ds . 'contest',$contestfile,LOCK_EX); + @file_put_contents($webcastdir . $ds . 'version',$versionfile,LOCK_EX); + @file_put_contents($webcastdir . $ds . 'time',$timefile,LOCK_EX); + @file_put_contents($webcastdir . $ds . 'icpc',$icpcfile,LOCK_EX); if(@create_zip($webcastdir,array('.'),$webcastdir . ".zip") != 1) { LOGError("Cannot create score webcast.zip file"); MSGError("Cannot create score webcast.zip file"); } else { echo file_get_contents($webcastdir . ".zip"); + //sleep(30); + flock($fplock,LOCK_UN); + fclose($fplock); exit; } } else { |