Skip to content

Commit

Permalink
fix: Apply copying a file should not copy permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
VorpalBlade committed Aug 3, 2024
1 parent 5220404 commit 4049f63
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions crates/konfigkoll_core/src/apply.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Apply a stream of instructions to the current system

use std::fs::Permissions;
use std::os::unix::fs::OpenOptionsExt;
use std::os::unix::fs::PermissionsExt;
use std::sync::Arc;

Expand Down Expand Up @@ -197,8 +198,20 @@ impl Applicator for InProcessApplicator {
.context("Failed to write file data")?;
}
konfigkoll_types::FileContents::FromFile { checksum: _, path } => {
// TODO: This copies permissions, replace
std::fs::copy(path, &instr.path).context("Failed to copy file")?;
// std::fs::copy copies permissions, which we don't want (we want the
// file to be owned by root with default permissions until an
// instruction says otherwise), so we can't use it.
let mut target_file = std::fs::OpenOptions::new()
.write(true)
.truncate(true)
.create(true)
.mode(0o644)
.open(&instr.path)
.context("Failed to open target file for writing")?;
let mut source_file = std::fs::File::open(path)
.context("Failed to open source file for reading")?;
std::io::copy(&mut source_file, &mut target_file)
.context("Failed to copy file contents")?;
}
}
}
Expand Down

0 comments on commit 4049f63

Please sign in to comment.