From c5f99a234b6951b57171621b0155715ac884efa8 Mon Sep 17 00:00:00 2001 From: Heliozoa Date: Thu, 21 Nov 2024 10:02:19 +0200 Subject: [PATCH] Fix csharp project dir detection in submissions --- Cargo.lock | 30 +++++++++---------- Cargo.toml | 2 +- crates/plugins/csharp/src/plugin.rs | 10 +++++-- crates/tmc-langs-cli/src/lib.rs | 4 ++- .../tmc-langs-util/src/file_util/lock_unix.rs | 11 +++++++ .../src/file_util/lock_windows.rs | 6 ++++ 6 files changed, 43 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bb56167ae13..18a44a24247 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2502,7 +2502,7 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tmc-langs" -version = "0.36.4" +version = "0.37.0" dependencies = [ "base64 0.22.1", "blake3", @@ -2543,7 +2543,7 @@ dependencies = [ [[package]] name = "tmc-langs-cli" -version = "0.36.4" +version = "0.37.0" dependencies = [ "anyhow", "base64 0.22.1", @@ -2570,7 +2570,7 @@ dependencies = [ [[package]] name = "tmc-langs-csharp" -version = "0.36.4" +version = "0.37.0" dependencies = [ "dirs", "log", @@ -2588,7 +2588,7 @@ dependencies = [ [[package]] name = "tmc-langs-framework" -version = "0.36.4" +version = "0.37.0" dependencies = [ "fd-lock", "isolang", @@ -2613,7 +2613,7 @@ dependencies = [ [[package]] name = "tmc-langs-java" -version = "0.36.4" +version = "0.37.0" dependencies = [ "dirs", "flate2", @@ -2634,7 +2634,7 @@ dependencies = [ [[package]] name = "tmc-langs-make" -version = "0.36.4" +version = "0.37.0" dependencies = [ "log", "once_cell", @@ -2653,7 +2653,7 @@ dependencies = [ [[package]] name = "tmc-langs-node" -version = "0.36.4" +version = "0.37.0" dependencies = [ "base64 0.22.1", "env_logger", @@ -2671,7 +2671,7 @@ dependencies = [ [[package]] name = "tmc-langs-notests" -version = "0.36.4" +version = "0.37.0" dependencies = [ "log", "simple_logger", @@ -2683,7 +2683,7 @@ dependencies = [ [[package]] name = "tmc-langs-plugins" -version = "0.36.4" +version = "0.37.0" dependencies = [ "log", "simple_logger", @@ -2705,7 +2705,7 @@ dependencies = [ [[package]] name = "tmc-langs-python3" -version = "0.36.4" +version = "0.37.0" dependencies = [ "dunce", "hex", @@ -2727,7 +2727,7 @@ dependencies = [ [[package]] name = "tmc-langs-r" -version = "0.36.4" +version = "0.37.0" dependencies = [ "log", "serde", @@ -2743,7 +2743,7 @@ dependencies = [ [[package]] name = "tmc-langs-util" -version = "0.36.4" +version = "0.37.0" dependencies = [ "dunce", "fd-lock", @@ -2767,7 +2767,7 @@ dependencies = [ [[package]] name = "tmc-mooc-client" -version = "0.36.4" +version = "0.37.0" dependencies = [ "bytes", "chrono", @@ -2787,7 +2787,7 @@ dependencies = [ [[package]] name = "tmc-server-mock" -version = "0.36.4" +version = "0.37.0" dependencies = [ "mockito", "serde_json", @@ -2795,7 +2795,7 @@ dependencies = [ [[package]] name = "tmc-testmycode-client" -version = "0.36.4" +version = "0.37.0" dependencies = [ "chrono", "dirs", diff --git a/Cargo.toml b/Cargo.toml index c0172d3fc42..8c93046e7e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ authors = [ edition = "2021" license = "MIT OR Apache-2.0" rust-version = "1.70.0" -version = "0.36.4" +version = "0.37.0" [workspace.dependencies] mooc-langs-api = { git = "https://github.com/rage/secret-project-331.git", rev = "9fb5f894c72932e77dafa6d0f00df7a8abdfa84c" } diff --git a/crates/plugins/csharp/src/plugin.rs b/crates/plugins/csharp/src/plugin.rs index 4b1eb2563f7..69c71d9cb64 100644 --- a/crates/plugins/csharp/src/plugin.rs +++ b/crates/plugins/csharp/src/plugin.rs @@ -132,7 +132,7 @@ impl CSharpPlugin { } /// Project directory: -/// Contains a src directory which contains a .csproj file (which may be inside a subdirectory). +/// Contains a src directory which contains a .cs or .csproj file (which may be inside a subdirectory). impl LanguagePlugin for CSharpPlugin { const PLUGIN_NAME: &'static str = "csharp"; const DEFAULT_SANDBOX_IMAGE: &'static str = "eu.gcr.io/moocfi-public/tmc-sandbox-csharp:latest"; @@ -145,7 +145,10 @@ impl LanguagePlugin for CSharpPlugin { .max_depth(2) .into_iter() .filter_map(|e| e.ok()) - .any(|e| e.path().extension() == Some(&OsString::from("csproj"))) + .any(|e| { + let ext = e.path().extension(); + ext == Some(&OsString::from("cs")) || ext == Some(&OsString::from("csproj")) + }) } fn find_project_dir_in_archive( @@ -155,9 +158,10 @@ impl LanguagePlugin for CSharpPlugin { let project_dir = loop { let next = iter.with_next(|entry| { let file_path = entry.path()?; + let ext = file_path.extension(); if entry.is_file() - && file_path.extension() == Some(OsStr::new("csproj")) + && (ext == Some(OsStr::new("cs")) || ext == Some(OsStr::new("csproj"))) && !file_path.components().any(|c| c.as_os_str() == "__MACOSX") { if let Some(parent) = file_path.parent() { diff --git a/crates/tmc-langs-cli/src/lib.rs b/crates/tmc-langs-cli/src/lib.rs index 61ff25cfe73..831b6beceaa 100644 --- a/crates/tmc-langs-cli/src/lib.rs +++ b/crates/tmc-langs-cli/src/lib.rs @@ -621,7 +621,7 @@ fn run_tmc_inner( output_path, } => { let mut output_lock = Lock::dir(&output_path, file_util::LockOptions::Write)?; - let _output_guard = output_lock.lock()?; + let output_guard = output_lock.lock()?; tmc_langs::download_old_submission( client, @@ -630,6 +630,8 @@ fn run_tmc_inner( submission_id, save_old_state, )?; + drop(output_guard); + output_lock.forget(); CliOutput::finished("extracted project") } diff --git a/crates/tmc-langs-util/src/file_util/lock_unix.rs b/crates/tmc-langs-util/src/file_util/lock_unix.rs index 002552d6420..063a0785a95 100644 --- a/crates/tmc-langs-util/src/file_util/lock_unix.rs +++ b/crates/tmc-langs-util/src/file_util/lock_unix.rs @@ -17,6 +17,7 @@ pub struct Lock { pub path: PathBuf, options: LockOptions, lock_file_path: Option, + forget: bool, } impl Lock { @@ -32,6 +33,7 @@ impl Lock { path, options, lock_file_path: None, + forget: false, }) } @@ -56,6 +58,7 @@ impl Lock { path, options, lock_file_path: Some(lock_path), + forget: false, }) } @@ -84,10 +87,18 @@ impl Lock { }; Ok(Guard { lock, path }) } + + pub fn forget(mut self) { + self.forget = true; + } } impl Drop for Lock { fn drop(&mut self) { + if self.forget { + return; + } + // check if we created a lock file if let Some(lock_file_path) = self.lock_file_path.take() { // try to get a write lock and delete file diff --git a/crates/tmc-langs-util/src/file_util/lock_windows.rs b/crates/tmc-langs-util/src/file_util/lock_windows.rs index d2b697addfe..8b6d07e9e29 100644 --- a/crates/tmc-langs-util/src/file_util/lock_windows.rs +++ b/crates/tmc-langs-util/src/file_util/lock_windows.rs @@ -68,6 +68,7 @@ impl Lock { path: path.as_ref().to_path_buf(), options, lock, + forget: false, }); } Err(err) => { @@ -121,6 +122,11 @@ impl Lock { path: Cow::Borrowed(&self.path), }) } + + pub fn forget(mut self: Self) { + let _self = self; + // no-op on windows + } } pub struct Guard<'a> {