Skip to content

Commit

Permalink
feat: implement write_and_check_err()
Browse files Browse the repository at this point in the history
  • Loading branch information
DPS0340 committed Jun 25, 2024
1 parent f3cf236 commit 0f5d445
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/executor/initializer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,7 @@ StandardError=file:/var/log/rrdb.stderr.log
[Install]
WantedBy=multi-user.target"#;

if let Err(error) = tokio::fs::write(base_path, script).await {
if error.kind() != std::io::ErrorKind::AlreadyExists {
return Err(ExecuteError::wrap(error.to_string()));
}
}
Ok(())
self.write_and_check_err(base_path, script).await
}

#[cfg(target_os = "macos")]
Expand All @@ -137,7 +132,15 @@ WantedBy=multi-user.target"#;
</dict>
</plist>"#;

if let Err(error) = tokio::fs::write(base_path, script).await {
self.write_and_check_err(base_path, script).await
}

async fn write_and_check_err(
&self,
base_path: PathBuf,
contents: &str,
) -> Result<(), RRDBError> {
if let Err(error) = tokio::fs::write(base_path, contents).await {
if error.kind() != std::io::ErrorKind::AlreadyExists {
return Err(ExecuteError::wrap(error.to_string()));
}
Expand Down

0 comments on commit 0f5d445

Please sign in to comment.