Skip to content

Commit 5ca50eb

Browse files
committed
Take compression setting into account when overwriting
1 parent 1be0723 commit 5ca50eb

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

tmc-langs/src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,16 @@ pub enum LangsError {
1818
InvalidParam(String, #[source] ParamError),
1919
#[error("Error compressing data with zstd")]
2020
Zstd(#[source] std::io::Error),
21+
#[error("Error decoding data with zstd")]
22+
ZstdDecode(#[source] std::io::Error),
2123
#[error("Error retrieving file handle from tar builder")]
2224
TarIntoInner(#[source] std::io::Error),
2325
#[error("Error finishing tar")]
2426
TarFinish(#[source] std::io::Error),
2527
#[error("Error appending path {0} to tar")]
2628
TarAppend(PathBuf, #[source] std::io::Error),
29+
#[error("Error extracting tar to {0}")]
30+
TarExtract(PathBuf, #[source] std::io::Error),
2731
#[error("Failed to aquire mutex")]
2832
MutexError,
2933
#[error("No project directory found in archive during unzip")]

tmc-langs/src/lib.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ pub fn extract_project(
812812
"no matching language plugin found for {}, overwriting",
813813
target_location.display()
814814
);
815-
extract_project_overwrite(compressed_project, target_location)?;
815+
extract_project_overwrite(compressed_project, target_location, compression)?;
816816
}
817817
Ok(())
818818
}
@@ -907,7 +907,7 @@ pub fn extract_student_files(
907907
"no matching language plugin found for {}, overwriting",
908908
target_location.display()
909909
);
910-
extract_project_overwrite(compressed_project, target_location)?;
910+
extract_project_overwrite(compressed_project, target_location, Compression::Zip)?;
911911
}
912912
Ok(())
913913
}
@@ -991,8 +991,24 @@ fn finish_stage(message: impl Into<String>) {
991991
fn extract_project_overwrite(
992992
compressed_project: impl std::io::Read + std::io::Seek,
993993
target_location: &Path,
994+
compression: Compression,
994995
) -> Result<(), LangsError> {
995-
compression::unzip(compressed_project, target_location)?;
996+
match compression {
997+
Compression::Tar => {
998+
let mut archive = tar::Archive::new(compressed_project);
999+
archive
1000+
.unpack(target_location)
1001+
.map_err(|e| LangsError::TarExtract(target_location.to_path_buf(), e))?;
1002+
}
1003+
Compression::TarZstd => {
1004+
let decoder = zstd::Decoder::new(compressed_project).map_err(LangsError::ZstdDecode)?;
1005+
let mut archive = tar::Archive::new(decoder);
1006+
archive
1007+
.unpack(target_location)
1008+
.map_err(|e| LangsError::TarExtract(target_location.to_path_buf(), e))?;
1009+
}
1010+
Compression::Zip => compression::unzip(compressed_project, target_location)?,
1011+
}
9961012
Ok(())
9971013
}
9981014

0 commit comments

Comments
 (0)