Skip to content

Commit 0231def

Browse files
authored
[rust] Check driver in cache before uncompressing (fix #11226) (#11273)
1 parent 5ce0a04 commit 0231def

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

rust/src/files.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ pub fn untargz(file: File, target: PathBuf) -> Result<(), Box<dyn Error>> {
8888
let parent_path = target
8989
.parent()
9090
.ok_or(format!("Error getting parent of {:?}", file))?;
91-
archive.unpack(parent_path)?;
91+
if !target.exists() {
92+
archive.unpack(parent_path)?;
93+
}
9294
Ok(())
9395
}
9496

@@ -98,6 +100,9 @@ pub fn unzip(file: File, target: PathBuf) -> Result<(), Box<dyn Error>> {
98100

99101
for i in 0..archive.len() {
100102
let mut file = archive.by_index(i)?;
103+
if target.exists() {
104+
continue;
105+
}
101106
let target_file_name = target.file_name().unwrap().to_str().unwrap();
102107
if target_file_name == file.name() {
103108
log::debug!(
@@ -108,17 +113,19 @@ pub fn unzip(file: File, target: PathBuf) -> Result<(), Box<dyn Error>> {
108113
if let Some(p) = target.parent() {
109114
create_path_if_not_exists(p);
110115
}
111-
let mut outfile = File::create(&target)?;
116+
if !target.exists() {
117+
let mut outfile = File::create(&target)?;
112118

113-
// Set permissions in Unix-like systems
114-
#[cfg(unix)]
115-
{
116-
use std::os::unix::fs::PermissionsExt;
119+
// Set permissions in Unix-like systems
120+
#[cfg(unix)]
121+
{
122+
use std::os::unix::fs::PermissionsExt;
117123

118-
fs::set_permissions(&target, fs::Permissions::from_mode(0o755))?;
119-
}
124+
fs::set_permissions(&target, fs::Permissions::from_mode(0o755))?;
125+
}
120126

121-
io::copy(&mut file, &mut outfile)?;
127+
io::copy(&mut file, &mut outfile)?;
128+
}
122129
break;
123130
}
124131
}

0 commit comments

Comments
 (0)