From 986bf51e2e294485febe997f2b95a0de50065e89 Mon Sep 17 00:00:00 2001 From: Pauline Date: Sat, 17 Aug 2024 21:22:52 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix(actions):=20use=20nightly=20?= =?UTF-8?q?for=20rustfmt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pauline --- .github/workflows/build.yml | 2 +- .../core/src/api/cluster/content/logger.rs | 22 ++----------------- packages/core/src/utils/http.rs | 3 +-- 3 files changed, 4 insertions(+), 23 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eb864724..65335b3b 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -101,7 +101,7 @@ jobs: - name: Run Rustfmt if: steps.filter.outcome != 'success' || steps.filter.outputs.changes == 'true' - run: cargo fmt --all -- --check + run: cargo +nightly fmt --all -- --check clippy: strategy: diff --git a/packages/core/src/api/cluster/content/logger.rs b/packages/core/src/api/cluster/content/logger.rs index 10eeed61..c87d72c5 100644 --- a/packages/core/src/api/cluster/content/logger.rs +++ b/packages/core/src/api/cluster/content/logger.rs @@ -7,7 +7,6 @@ use crate::utils::io::{self, IOError}; use futures::TryFutureExt; use serde::{Deserialize, Serialize}; use std::collections::HashMap; -use std::io::Read; use std::time::SystemTime; use tokio::io::{AsyncReadExt, AsyncSeekExt}; @@ -238,29 +237,12 @@ pub async fn delete_logs_by_file( pub async fn read_log_to_string(path: &std::path::PathBuf) -> crate::Result { if let Some(ext) = path.extension() { - let mut file = std::fs::File::open(path).map_err(|e| IOError::with_path(e, path))?; - let mut contents = [0; 1024]; let mut result = String::new(); if ext == "gz" { - let mut gz = flate2::read::GzDecoder::new(std::io::BufReader::new(file)); - while gz - .read(&mut contents) - .map_err(|e| IOError::with_path(e, path))? - > 0 - { - result.push_str(&String::from_utf8_lossy(&contents)); - contents = [0; 1024]; - } + result = io::read_gz_to_string(path).await?; } else if ext == "log" || ext == "txt" { - while file - .read(&mut contents) - .map_err(|e| IOError::with_path(e, path))? - > 0 - { - result.push_str(&String::from_utf8_lossy(&contents)); - contents = [0; 1024]; - } + result = io::read_to_string(path).await?; } return Ok(result); diff --git a/packages/core/src/utils/http.rs b/packages/core/src/utils/http.rs index 182f303d..ac8220fe 100644 --- a/packages/core/src/utils/http.rs +++ b/packages/core/src/utils/http.rs @@ -9,7 +9,6 @@ use std::time::Duration; use bytes::Bytes; use reqwest::Method; use serde::de::DeserializeOwned; -use tokio::fs::File; use tokio::io::AsyncWriteExt; use tokio::sync::{RwLock, Semaphore}; @@ -244,7 +243,7 @@ pub async fn write<'a>(path: &Path, bytes: &[u8], semaphore: &IoSemaphore) -> cr io::create_dir_all(parent).await?; } - let mut file = File::create(path) + let mut file = tokio::fs::File::create(path) .await .map_err(|e| IOError::with_path(e, path))?; file.write_all(bytes)