Reduce logging in SFTP wormfile implementation

Signed-off-by: Olivier <olivier@librepush.net>
This commit is contained in:
Olivier 'reivilibre' 2024-07-21 11:50:08 +01:00
parent 0869aa1afb
commit 1e029a1826
1 changed files with 12 additions and 6 deletions

View File

@ -17,7 +17,7 @@ use std::path::{Path, PathBuf};
use std::pin::Pin; use std::pin::Pin;
use std::sync::Arc; use std::sync::Arc;
use std::task::{Context, Poll}; use std::task::{Context, Poll};
use std::time::Duration; use std::time::{Duration, Instant};
use tokio::io::{AsyncRead, AsyncSeek, AsyncWrite, AsyncWriteExt, ReadBuf}; use tokio::io::{AsyncRead, AsyncSeek, AsyncWrite, AsyncWriteExt, ReadBuf};
use tokio_stream::StreamExt; use tokio_stream::StreamExt;
use tracing::debug; use tracing::debug;
@ -465,10 +465,10 @@ impl AsyncWrite for SftpWormWriter {
impl WormFileWriter for SftpWormWriter { impl WormFileWriter for SftpWormWriter {
#[async_backtrace::framed] #[async_backtrace::framed]
async fn finalise(&mut self, target_path: &WormPath, replace: bool) -> io::Result<()> { async fn finalise(&mut self, target_path: &WormPath, replace: bool) -> io::Result<()> {
debug!("finalising SFTP file to {target_path:?}"); let flush_start = Instant::now();
self.flush().await?; self.flush().await?;
debug!("flushed SFTP file to {target_path:?}");
let mkdirs_start = Instant::now();
let SftpWormWriter { let SftpWormWriter {
temp_path, temp_path,
file, file,
@ -492,7 +492,6 @@ impl WormFileWriter for SftpWormWriter {
.await .await
.map_err(|e| io::Error::new(ErrorKind::Other, e.to_string()))?; .map_err(|e| io::Error::new(ErrorKind::Other, e.to_string()))?;
} }
debug!("created dirs SFTP file to {target_path:?}");
// Avoid allowing a replacement if not intended. // Avoid allowing a replacement if not intended.
// But this is currently not atomic, so it's just a sanity check rather than a foolproof // But this is currently not atomic, so it's just a sanity check rather than a foolproof
// safeguard! // safeguard!
@ -513,12 +512,19 @@ impl WormFileWriter for SftpWormWriter {
} }
} }
debug!("moving SFTP file to {target_path:?}"); let move_start = Instant::now();
// Perform the move. // Perform the move.
fs.rename(&temp_path.as_ref().as_str(), target_path.as_str()) fs.rename(&temp_path.as_ref().as_str(), target_path.as_str())
.await .await
.map_err(|e| io::Error::new(ErrorKind::Other, e))?; .map_err(|e| io::Error::new(ErrorKind::Other, e))?;
debug!("moved SFTP file to {target_path:?}");
let end = Instant::now();
debug!(
"Saved SFTP file to {target_path:?} (flush={:?}, mkdirs={:?}, move={:?})",
mkdirs_start - flush_start,
move_start - mkdirs_start,
end - move_start
);
Ok(()) Ok(())
} }
} }