Skip to content

Commit

Permalink
fix: create tempfile in root dir prevent cross-device link (nervosnet…
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangsoledad authored and doitian committed Apr 10, 2019
1 parent 79a9ea2 commit e1ac356
Showing 1 changed file with 7 additions and 9 deletions.
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

0 comments on commit e1ac356

Please sign in to comment.