-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Judger): 🚧 draft crate::sandbox::Context implementer in language…
… model
- Loading branch information
Showing
18 changed files
with
293 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use std::{ | ||
ffi::{CStr, CString, OsStr}, | ||
os::unix::ffi::OsStrExt, | ||
path::{Path, PathBuf}, | ||
}; | ||
|
||
use tokio::fs::remove_dir; | ||
|
||
pub struct MkdTemp(PathBuf); | ||
|
||
impl Drop for MkdTemp { | ||
fn drop(&mut self) { | ||
tokio::spawn(remove_dir(self.0.clone())); | ||
} | ||
} | ||
|
||
impl MkdTemp { | ||
pub fn new() -> Self { | ||
Self(unsafe { Self::new_inner("mdoj-XXXXXX") }) | ||
} | ||
pub unsafe fn new_inner(template: &str) -> PathBuf { | ||
let template = CString::new(template).unwrap(); | ||
let tmp_ptr = libc::mkdtemp(template.as_ptr() as *mut _); | ||
let tmp_path = CStr::from_ptr(tmp_ptr); | ||
let str_path = OsStr::from_bytes(tmp_path.to_bytes()); | ||
drop(template); | ||
// libc::free(tmp_ptr as *mut _); | ||
PathBuf::from(str_path) | ||
} | ||
pub fn get_path(&self) -> &Path { | ||
self.0.as_path() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.