Skip to content

Commit

Permalink
Merge pull request #214 from rage/cs
Browse files Browse the repository at this point in the history
Fix csharp project dir detection in submissions
  • Loading branch information
Heliozoa authored Dec 17, 2024
2 parents 2a3a8ab + aed67ae commit 82fdd23
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 20 deletions.
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
10 changes: 7 additions & 3 deletions crates/plugins/csharp/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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<R: Read + Seek>(
Expand All @@ -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() {
Expand Down
4 changes: 3 additions & 1 deletion crates/tmc-langs-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -630,6 +630,8 @@ fn run_tmc_inner(
submission_id,
save_old_state,
)?;
drop(output_guard);
output_lock.forget();
CliOutput::finished("extracted project")
}

Expand Down
11 changes: 11 additions & 0 deletions crates/tmc-langs-util/src/file_util/lock_unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub struct Lock {
pub path: PathBuf,
options: LockOptions,
lock_file_path: Option<PathBuf>,
forget: bool,
}

impl Lock {
Expand All @@ -32,6 +33,7 @@ impl Lock {
path,
options,
lock_file_path: None,
forget: false,
})
}

Expand All @@ -56,6 +58,7 @@ impl Lock {
path,
options,
lock_file_path: Some(lock_path),
forget: false,
})
}

Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions crates/tmc-langs-util/src/file_util/lock_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ impl Lock {
path: Cow::Borrowed(&self.path),
})
}

pub fn forget(self) {
let _self = self;
// no-op on windows
}
}

pub struct Guard<'a> {
Expand Down

0 comments on commit 82fdd23

Please sign in to comment.