Commit 6a9866f1 authored by Gudipaty Aniket's avatar Gudipaty Aniket

Modifications in backend corresponding to dir_tree

parent eb9ccd7f
...@@ -16,27 +16,37 @@ $postData = json_decode($postData, true); ...@@ -16,27 +16,37 @@ $postData = json_decode($postData, true);
$uname = $postData['username']; $uname = $postData['username'];
$filename = $postData['filename']; $filename = $postData['filename'];
$f_path = $postData['file_path'];
$language = $postData['language']; $language = $postData['language'];
$ret_stat = 0; $ret_stat = 0;
if(strcmp($language, ".cpp") == 0) if(strcmp($language, ".cpp") == 0)
{ {
system("g++ ../users/" . $uname . "/" . $filename . ".cpp -o ../user_execs/" . $uname . "/" . $filename , $ret_stat); if(!file_exists("../user_execs/" . $uname . "/" . $f_path))
{
mkdir("../user_execs/" . $uname . "/" . $f_path , 0777, true);
}
system("g++ ../users/" . $uname . "/" . $f_path . "/" . $filename . ".cpp -o ../user_execs/" . $uname . "/" . $f_path . "/" . $filename , $ret_stat);
if($ret_stat != 0) if($ret_stat != 0)
{ {
unlink("../users/" . $uname . "/" . $filename); unlink("../user_execs/" . $uname . "/" . $f_path . "/" . $filename);
throw new Exception("Compilation Error!"); throw new Exception("Compilation Error!");
} }
} }
else if(strcmp($language, ".java") == 0) else if(strcmp($language, ".java") == 0)
{ {
system("javac -d ../user_execs/" . $uname . "/ ../users/" . $uname . "/" . $filename . '.java', $ret_stat); if(!file_exists("../user_execs/" . $uname . "/" . $f_path))
{
mkdir("../user_execs/" . $uname . "/" . $f_path , 0777, true);
}
system("javac -d ../user_execs/" . $uname . "/" . $f_path . "/ ../users/" . $uname . "/" . $f_path . "/" . $filename . '.java', $ret_stat);
if($ret_stat != 0) if($ret_stat != 0)
{ {
unlink("../users/" . $uname . "/" . $filename . ".class"); unlink("../user_execs/" . $uname . "/" . $f_path . "/" . $filename . ".class");
throw new Exception("Compilation Error!"); throw new Exception("Compilation Error!");
} }
} }
......
...@@ -17,6 +17,7 @@ $postData = json_decode($postData, true); ...@@ -17,6 +17,7 @@ $postData = json_decode($postData, true);
$uname = $postData['file']['username']; $uname = $postData['file']['username'];
$filename = $postData['file']['filename']; $filename = $postData['file']['filename'];
$f_path = $postData['file']['file_path'];
$language = $postData['file']['language']; $language = $postData['file']['language'];
$input_data = $postData['input_data']; $input_data = $postData['input_data'];
...@@ -32,9 +33,9 @@ fclose($file); ...@@ -32,9 +33,9 @@ fclose($file);
$out_fname = "../user_execs/" . $uname . "/temp/temp_out" . $template; $out_fname = "../user_execs/" . $uname . "/temp/temp_out" . $template;
if (strcmp($language, ".cpp") == 0) { if (strcmp($language, ".cpp") == 0) {
system("./../user_execs/" . $uname . "/" . $filename . " < " . $in_fname . " > " . $out_fname, $ret_stat); system("./../user_execs/" . $uname . "/" . $f_path . "/" . $filename . " < " . $in_fname . " > " . $out_fname, $ret_stat);
} else if (strcmp($language, ".java") == 0) { } else if (strcmp($language, ".java") == 0) {
system("java -cp ../user_execs/" . $uname . "/ " . $filename . " < " . $in_fname . " > " . $out_fname, $ret_stat); system("java -cp ../user_execs/" . $uname . "/" . $f_path . "/ " . $filename . " < " . $in_fname . " > " . $out_fname, $ret_stat);
} else if (strcmp($language, ".py") == 0) { } else if (strcmp($language, ".py") == 0) {
system("python3 ../users/" . $uname . "/" . $filename . ".py < " . $in_fname . " > " . $out_fname, $ret_stat); system("python3 ../users/" . $uname . "/" . $filename . ".py < " . $in_fname . " > " . $out_fname, $ret_stat);
} }
......
...@@ -17,11 +17,19 @@ if (isset($postData) && !empty($postData)) { ...@@ -17,11 +17,19 @@ if (isset($postData) && !empty($postData)) {
$lang = trim($request['file']['language']); $lang = trim($request['file']['language']);
$path = '../users/' . $username . '/' . trim($request['file']['path']) . '/' . $filename . $lang; $path = '../users/' . $username . '/' . trim($request['file']['path']) . '/' . $filename . $lang;
$exec_path = '../user_execs/' . $username . '/' . trim($request['file']['path']) . '/' . $filename;
if(strcmp($lang, '.java') == 0)
{
$exec_path = $exec_path . $lang;
}
if (unlink($path)) { if (unlink($path)) {
$sql = "UPDATE users SET n_files=n_files-1 WHERE username = '$username'"; $sql = "UPDATE users SET n_files=n_files-1 WHERE username = '$username'";
mysqli_query($mysqli,$sql); mysqli_query($mysqli,$sql);
$msg = "file successfully deleted"; $msg = "file successfully deleted";
echo json_encode($msg); echo json_encode($msg);
unlink($exec_path);
} }
else{ else{
http_response_code(404); http_response_code(404);
...@@ -32,8 +40,11 @@ if (isset($postData) && !empty($postData)) { ...@@ -32,8 +40,11 @@ if (isset($postData) && !empty($postData)) {
$dirname = trim($request['file']['name']); $dirname = trim($request['file']['name']);
$path = '../users/' . $username . '/' . trim($request['file']['path']) . '/' . $dirname; $path = '../users/' . $username . '/' . trim($request['file']['path']) . '/' . $dirname;
$exec_path = '../user_execs/' . $username . '/' . trim($request['file']['path']) . '/' . $dirname;
$ret_stat = 0; $ret_stat = 0;
system('rm -r ' . $path, $ret_stat); system('rm -r ' . $path, $ret_stat);
system('rm -r ' . $exec_path);
if ($ret_stat === 0) { if ($ret_stat === 0) {
$msg = "directory successfully deleted"; $msg = "directory successfully deleted";
echo json_encode($msg); echo json_encode($msg);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment