Skip to content

Commit 8b8f612

Browse files
committed
feat: add windows paths and funcs to manage it
1 parent 19c3502 commit 8b8f612

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

agent-control/src/agent_control/defaults.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ cfg_if::cfg_if! {
4141
pub const AGENT_CONTROL_DATA_DIR: &str = "/opt/homebrew/var/lib/newrelic-agent-control";
4242
pub const AGENT_CONTROL_LOG_DIR: &str = "/opt/homebrew/var/log/newrelic-agent-control";
4343

44-
}else{
44+
} else if #[cfg(target_os = "windows")] {
45+
pub const AGENT_CONTROL_LOCAL_DATA_DIR: &str = "C:\\Program Files\\New Relic\\newrelic-agent-control";
46+
pub const AGENT_CONTROL_DATA_DIR: &str = "C:\\ProgramData\\New Relic\\newrelic-agent-control";
47+
pub const AGENT_CONTROL_LOG_DIR: &str = "C:\\ProgramData\\New Relic\\newrelic-agent-control\\logs";
48+
49+
} else {
4550
pub const AGENT_CONTROL_LOCAL_DATA_DIR: &str = "/etc/newrelic-agent-control";
4651
pub const AGENT_CONTROL_DATA_DIR: &str = "/var/lib/newrelic-agent-control";
4752
pub const AGENT_CONTROL_LOG_DIR: &str = "/var/log/newrelic-agent-control";

fs/src/directory_manager.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,17 @@ impl DirectoryManager for DirectoryManagerFs {
4949

5050
#[cfg(target_family = "windows")]
5151
fn create(&self, path: &Path) -> Result<(), DirectoryManagementError> {
52-
unimplemented!()
52+
validate_path(path)?;
53+
54+
let directory_creation = DirBuilder::new().recursive(true).create(path);
55+
56+
match directory_creation {
57+
Err(e) => Err(DirectoryManagementError::ErrorCreatingDirectory(
58+
path.to_str().unwrap().to_string(),
59+
e.to_string(),
60+
)),
61+
_ => Ok(()),
62+
}
5363
}
5464

5565
#[instrument(skip_all, fields(path = %path.display()))]

fs/src/writer_file.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,20 @@ impl FileWriter for LocalFile {
4646
Ok(())
4747
}
4848

49-
// TODO : Code below is not tested yet as Windows is not supported at this time
5049
#[cfg(target_family = "windows")]
51-
fn write(&self, _path: &Path, _content: String) -> Result<(), WriteError> {
52-
unimplemented!()
50+
#[instrument(skip_all, fields(path = %path.display()))]
51+
fn write(&self, path: &Path, content: String) -> Result<(), WriteError> {
52+
validate_path(path)?;
53+
54+
let mut file = fs::OpenOptions::new()
55+
.create(true)
56+
.write(true)
57+
.truncate(true)
58+
.open(path)?;
59+
60+
file.write_all(content.as_bytes())?;
61+
62+
Ok(())
5363
}
5464
}
5565

@@ -181,7 +191,6 @@ pub mod tests {
181191
assert_eq!(fs::read_to_string(path.clone()).unwrap(), new_content);
182192
}
183193

184-
#[cfg(target_family = "unix")]
185194
#[test]
186195
fn test_path_to_write_cannot_contain_dots() {
187196
// Prepare temp path and folder name

0 commit comments

Comments
 (0)