Skip to content

Commit c468ed3

Browse files
committed
use prepare_stub to copy clone path instead of just copy in prepare-submission
1 parent a384cb4 commit c468ed3

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

tmc-langs-framework/src/io/submission_processing.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,47 +92,41 @@ pub fn contains_tmcignore(entry: &DirEntry) -> bool {
9292

9393
// Copies the entry to the destination. Parses and filters text files according to `filter`
9494
fn copy_file(
95-
entry: &DirEntry,
95+
file: &Path,
9696
source_root: &Path,
9797
dest_root: &Path,
9898
line_filter: &mut impl Fn(&MetaString) -> bool,
9999
file_filter: &mut impl Fn(&[MetaString]) -> bool,
100100
) -> Result<(), TmcError> {
101-
let is_dir = entry.metadata().map(|e| e.is_dir()).unwrap_or_default();
102-
if is_dir {
101+
if file.is_dir() {
103102
return Ok(());
104103
}
105104
// get relative path
106-
let relative_path = entry
107-
.path()
105+
let relative_path = file
108106
.strip_prefix(source_root)
109107
.unwrap_or_else(|_| Path::new(""));
110108
let dest_path = dest_root.join(&relative_path);
111109
if let Some(parent) = dest_path.parent() {
112110
file_util::create_dir_all(parent)?;
113111
}
114-
let extension = entry.path().extension().and_then(|e| e.to_str());
112+
let extension = file.extension().and_then(|e| e.to_str());
115113
let is_binary = extension
116114
.map(|e| NON_TEXT_TYPES.is_match(e))
117115
.unwrap_or_default();
118116
if is_binary {
119117
// copy binary files
120-
debug!(
121-
"copying binary file from {:?} to {:?}",
122-
entry.path(),
123-
dest_path
124-
);
125-
file_util::copy(entry.path(), &dest_path)?;
118+
debug!("copying binary file from {:?} to {:?}", file, dest_path);
119+
file_util::copy(file, &dest_path)?;
126120
} else {
127121
// filter text files
128-
let source_file = file_util::open_file(entry.path())?;
122+
let source_file = file_util::open_file(file)?;
129123

130124
let parser = MetaSyntaxParser::new(source_file, extension.unwrap_or_default());
131125
let parsed: Vec<MetaString> = parser.collect::<Result<Vec<_>, _>>()?;
132126

133127
// files that don't pass the filter are skipped
134128
if !file_filter(&parsed) {
135-
log::debug!("skipping {} due to file filter", entry.path().display());
129+
log::debug!("skipping {} due to file filter", file.display());
136130
return Ok(());
137131
}
138132

@@ -152,7 +146,7 @@ fn copy_file(
152146
// writes all lines
153147
log::debug!(
154148
"filtered file {} to {}",
155-
entry.path().display(),
149+
file.display(),
156150
dest_path.display()
157151
);
158152
file_util::write_to_file(&mut write_lines.as_slice(), &dest_path)?;
@@ -162,20 +156,26 @@ fn copy_file(
162156

163157
// Processes all files in path, copying files in directories that are not skipped
164158
fn process_files(
165-
path: &Path,
159+
source: &Path,
166160
dest_root: &Path,
167161
mut line_filter: impl Fn(&MetaString) -> bool,
168162
mut file_filter: impl Fn(&[MetaString]) -> bool,
169163
) -> Result<(), TmcError> {
170-
info!("Project: {:?}", path);
164+
info!("Project: {:?}", source);
171165

172-
let walker = WalkDir::new(path).into_iter();
166+
let walker = WalkDir::new(source).into_iter();
173167
// silently skips over errors, for example when there's a directory we don't have permissions for
174168
for entry in walker
175169
.filter_entry(|e| !is_hidden_dir(e) && !on_skip_list(e) && !contains_tmcignore(e))
176170
.filter_map(|e| e.ok())
177171
{
178-
copy_file(&entry, path, dest_root, &mut line_filter, &mut file_filter)?;
172+
copy_file(
173+
entry.path(),
174+
source,
175+
dest_root,
176+
&mut line_filter,
177+
&mut file_filter,
178+
)?;
179179
}
180180
Ok(())
181181
}

tmc-langs-util/src/task_executor/submission_packaging.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,12 @@ pub fn prepare_submission(
227227
// idea
228228
".idea",
229229
] {
230-
let dir_in_received = project_root.join(ide_dir);
231-
let dir_in_clone = clone_path.join(ide_dir);
232-
if dir_in_received.exists() {
233-
file_util::copy(dir_in_received, &dest)?;
234-
} else if dir_in_clone.exists() {
235-
file_util::copy(dir_in_clone, &dest)?;
230+
let ide_dir_in_received = project_root.join(ide_dir);
231+
let ide_dir_in_clone = clone_path.join(ide_dir);
232+
if ide_dir_in_received.exists() {
233+
file_util::copy(ide_dir_in_received, &dest)?;
234+
} else if ide_dir_in_clone.exists() {
235+
file_util::copy(ide_dir_in_clone, &dest)?;
236236
}
237237
}
238238

@@ -256,7 +256,10 @@ pub fn prepare_submission(
256256
// copy src main and test
257257
let main_path = clone_path.join("src/main");
258258
if main_path.exists() {
259-
file_util::copy(main_path, dest.join("src"))?;
259+
tmc_langs_framework::io::submission_processing::prepare_stub(
260+
&main_path,
261+
&dest.join("src"),
262+
)?;
260263
}
261264
let test_path = tests_dir.join("src/test");
262265
if test_path.exists() {
@@ -305,7 +308,10 @@ pub fn prepare_submission(
305308
log::debug!("copying src and test");
306309
let main_path = clone_path.join("src");
307310
if main_path.exists() {
308-
file_util::copy(main_path, &dest)?;
311+
tmc_langs_framework::io::submission_processing::prepare_stub(
312+
&main_path,
313+
&dest.join("src"),
314+
)?;
309315
}
310316
let test_path = clone_path.join("test");
311317
if test_path.exists() {

0 commit comments

Comments
 (0)