Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: create tempfile in root dir prevent cross-device link #438

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 7 additions & 9 deletions resource/src/lib.rs
Expand Up @@ -146,29 +146,27 @@ impl ResourceLocator {
pub fn export_ckb<'a>(&self, context: &TemplateContext<'a>) -> Result<()> {
let ckb = Resource::Bundled(CKB_CONFIG_FILE_NAME.to_string());
let template = Template::new(from_utf8(ckb.get()?)?);
let mut out = NamedTempFile::new()?;
let mut out = NamedTempFile::new_in(&self.root_dir)?;
template.write_to(&mut out, context)?;
out.into_temp_path()
.persist(self.root_dir.join(CKB_CONFIG_FILE_NAME))
.map_err(Into::into)
out.persist(self.root_dir.join(CKB_CONFIG_FILE_NAME))?;
Ok(())
}

pub fn export_miner<'a>(&self, context: &TemplateContext<'a>) -> Result<()> {
let miner = Resource::Bundled(MINER_CONFIG_FILE_NAME.to_string());
let template = Template::new(from_utf8(miner.get()?)?);
let mut out = NamedTempFile::new()?;
let mut out = NamedTempFile::new_in(&self.root_dir)?;
template.write_to(&mut out, context)?;
out.into_temp_path()
.persist(self.root_dir.join(MINER_CONFIG_FILE_NAME))
.map_err(Into::into)
out.persist(self.root_dir.join(MINER_CONFIG_FILE_NAME))?;
Ok(())
}

pub fn export_specs(&self) -> Result<()> {
for name in BUNDLED.file_names() {
if name.starts_with(SPECS_RESOURCE_DIR_NAME) {
let path = self.root_dir.join(name);
fs::create_dir_all(path.parent().unwrap())?;
let mut out = NamedTempFile::new()?;
let mut out = NamedTempFile::new_in(&self.root_dir)?;
io::copy(&mut BUNDLED.read(name)?, &mut out)?;
out.into_temp_path().persist(path)?;
}
Expand Down