Skip to content

Commit 82fdd23

Browse files
authored
Merge pull request #214 from rage/cs
Fix csharp project dir detection in submissions
2 parents 2a3a8ab + aed67ae commit 82fdd23

File tree

6 files changed

+42
-20
lines changed

6 files changed

+42
-20
lines changed

Cargo.lock

+15-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ authors = [
2222
edition = "2021"
2323
license = "MIT OR Apache-2.0"
2424
rust-version = "1.70.0"
25-
version = "0.36.4"
25+
version = "0.37.0"
2626

2727
[workspace.dependencies]
2828
mooc-langs-api = { git = "https://github.com/rage/secret-project-331.git", rev = "9fb5f894c72932e77dafa6d0f00df7a8abdfa84c" }

crates/plugins/csharp/src/plugin.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl CSharpPlugin {
132132
}
133133

134134
/// Project directory:
135-
/// Contains a src directory which contains a .csproj file (which may be inside a subdirectory).
135+
/// Contains a src directory which contains a .cs or .csproj file (which may be inside a subdirectory).
136136
impl LanguagePlugin for CSharpPlugin {
137137
const PLUGIN_NAME: &'static str = "csharp";
138138
const DEFAULT_SANDBOX_IMAGE: &'static str = "eu.gcr.io/moocfi-public/tmc-sandbox-csharp:latest";
@@ -145,7 +145,10 @@ impl LanguagePlugin for CSharpPlugin {
145145
.max_depth(2)
146146
.into_iter()
147147
.filter_map(|e| e.ok())
148-
.any(|e| e.path().extension() == Some(&OsString::from("csproj")))
148+
.any(|e| {
149+
let ext = e.path().extension();
150+
ext == Some(&OsString::from("cs")) || ext == Some(&OsString::from("csproj"))
151+
})
149152
}
150153

151154
fn find_project_dir_in_archive<R: Read + Seek>(
@@ -155,9 +158,10 @@ impl LanguagePlugin for CSharpPlugin {
155158
let project_dir = loop {
156159
let next = iter.with_next(|entry| {
157160
let file_path = entry.path()?;
161+
let ext = file_path.extension();
158162

159163
if entry.is_file()
160-
&& file_path.extension() == Some(OsStr::new("csproj"))
164+
&& (ext == Some(OsStr::new("cs")) || ext == Some(OsStr::new("csproj")))
161165
&& !file_path.components().any(|c| c.as_os_str() == "__MACOSX")
162166
{
163167
if let Some(parent) = file_path.parent() {

crates/tmc-langs-cli/src/lib.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ fn run_tmc_inner(
621621
output_path,
622622
} => {
623623
let mut output_lock = Lock::dir(&output_path, file_util::LockOptions::Write)?;
624-
let _output_guard = output_lock.lock()?;
624+
let output_guard = output_lock.lock()?;
625625

626626
tmc_langs::download_old_submission(
627627
client,
@@ -630,6 +630,8 @@ fn run_tmc_inner(
630630
submission_id,
631631
save_old_state,
632632
)?;
633+
drop(output_guard);
634+
output_lock.forget();
633635
CliOutput::finished("extracted project")
634636
}
635637

crates/tmc-langs-util/src/file_util/lock_unix.rs

+11
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub struct Lock {
1717
pub path: PathBuf,
1818
options: LockOptions,
1919
lock_file_path: Option<PathBuf>,
20+
forget: bool,
2021
}
2122

2223
impl Lock {
@@ -32,6 +33,7 @@ impl Lock {
3233
path,
3334
options,
3435
lock_file_path: None,
36+
forget: false,
3537
})
3638
}
3739

@@ -56,6 +58,7 @@ impl Lock {
5658
path,
5759
options,
5860
lock_file_path: Some(lock_path),
61+
forget: false,
5962
})
6063
}
6164

@@ -84,10 +87,18 @@ impl Lock {
8487
};
8588
Ok(Guard { lock, path })
8689
}
90+
91+
pub fn forget(mut self) {
92+
self.forget = true;
93+
}
8794
}
8895

8996
impl Drop for Lock {
9097
fn drop(&mut self) {
98+
if self.forget {
99+
return;
100+
}
101+
91102
// check if we created a lock file
92103
if let Some(lock_file_path) = self.lock_file_path.take() {
93104
// try to get a write lock and delete file

crates/tmc-langs-util/src/file_util/lock_windows.rs

+5
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ impl Lock {
121121
path: Cow::Borrowed(&self.path),
122122
})
123123
}
124+
125+
pub fn forget(self) {
126+
let _self = self;
127+
// no-op on windows
128+
}
124129
}
125130

126131
pub struct Guard<'a> {

0 commit comments

Comments
 (0)