Skip to content

Commit

Permalink
Log directory deletions (Electron100#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvdb authored Mar 31, 2024
1 parent 2ca6075 commit fe41b72
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions butane_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ impl std::fmt::Display for SqlType {
#[cfg(feature = "log")]
pub use log::debug;
#[cfg(feature = "log")]
pub use log::info;
#[cfg(feature = "log")]
pub use log::warn;

#[cfg(not(feature = "log"))]
Expand All @@ -327,6 +329,13 @@ mod btlog {
($($arg:tt)+) => {};
}

/// Noop for when feature log is not enabled.
#[macro_export]
macro_rules! info {
(target: $target:expr, $($arg:tt)+) => {};
($($arg:tt)+) => {};
}

/// Noop for when feature log is not enabled.
#[macro_export]
macro_rules! warn {
Expand Down
5 changes: 5 additions & 0 deletions butane_core/src/migrations/fsmigrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ impl MigrationsMut for FsMigrations {
&mut self.current
}
fn clear_current(&mut self) -> Result<()> {
crate::info!("Deleting {}", self.current.root.display());
std::fs::remove_dir_all(&self.current.root)?;
Ok(())
}
Expand All @@ -394,6 +395,10 @@ impl MigrationsMut for FsMigrations {
}

fn clear_migrations(&mut self, conn: &impl ConnectionMethods) -> Result<()> {
crate::info!(
"Deleting everything in {} except 'current'",
self.root.display()
);
for entry in std::fs::read_dir(&self.root)? {
let entry = entry?;
if matches!(entry.path().file_name(), Some(name) if name == "current") {
Expand Down
4 changes: 4 additions & 0 deletions butane_test_helper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ impl Drop for PgServerState {
self.proc.kill().ok();
let mut buf = String::new();
self.stderr.read_to_string(&mut buf).unwrap();
if !buf.is_empty() {
log::warn!("pg shutdown error: {buf}");
}
log::info!("Deleting {}", self.dir.display());
std::fs::remove_dir_all(&self.dir).unwrap();
}
}
Expand Down

0 comments on commit fe41b72

Please sign in to comment.