summaryrefslogtreecommitdiff
path: root/crates/vcs_data/src/data/local
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2025-11-23 15:16:55 +0800
committer魏曹先生 <1992414357@qq.com>2025-11-23 15:16:55 +0800
commitc1a50fbdddc5fad986f4b3b6310cc5167e68f87e (patch)
treea7b8b62691a0eefdffd5e25f59941c12a70efb04 /crates/vcs_data/src/data/local
parentbe76a48b6b53756fe1ba2f2ddd44bc14c9eb35bb (diff)
Apply clippy suggestions
Diffstat (limited to 'crates/vcs_data/src/data/local')
-rw-r--r--crates/vcs_data/src/data/local/cached_sheet.rs16
-rw-r--r--crates/vcs_data/src/data/local/config.rs28
-rw-r--r--crates/vcs_data/src/data/local/file_status.rs32
-rw-r--r--crates/vcs_data/src/data/local/latest_info.rs5
-rw-r--r--crates/vcs_data/src/data/local/local_files.rs21
-rw-r--r--crates/vcs_data/src/data/local/local_sheet.rs1
6 files changed, 40 insertions, 63 deletions
diff --git a/crates/vcs_data/src/data/local/cached_sheet.rs b/crates/vcs_data/src/data/local/cached_sheet.rs
index e617922..39f9814 100644
--- a/crates/vcs_data/src/data/local/cached_sheet.rs
+++ b/crates/vcs_data/src/data/local/cached_sheet.rs
@@ -55,16 +55,14 @@ impl CachedSheet {
while let Some(entry) = dir.next_entry().await? {
let path = entry.path();
- if path.is_file() {
- if let Some(file_name) = path.file_name().and_then(|n| n.to_str()) {
- if file_name.ends_with(CLIENT_SUFFIX_CACHED_SHEET_FILE) {
+ if path.is_file()
+ && let Some(file_name) = path.file_name().and_then(|n| n.to_str())
+ && file_name.ends_with(CLIENT_SUFFIX_CACHED_SHEET_FILE) {
let name_without_ext = file_name
.trim_end_matches(CLIENT_SUFFIX_CACHED_SHEET_FILE)
.to_string();
sheet_names.push(name_without_ext);
}
- }
- }
}
Ok(sheet_names)
@@ -84,13 +82,11 @@ impl CachedSheet {
while let Some(entry) = dir.next_entry().await? {
let path = entry.path();
- if path.is_file() {
- if let Some(file_name) = path.file_name().and_then(|n| n.to_str()) {
- if file_name.ends_with(CLIENT_SUFFIX_CACHED_SHEET_FILE) {
+ if path.is_file()
+ && let Some(file_name) = path.file_name().and_then(|n| n.to_str())
+ && file_name.ends_with(CLIENT_SUFFIX_CACHED_SHEET_FILE) {
sheet_paths.push(format_path(workspace_path.join(path))?);
}
- }
- }
}
Ok(sheet_paths)
diff --git a/crates/vcs_data/src/data/local/config.rs b/crates/vcs_data/src/data/local/config.rs
index 5b288cc..28bd439 100644
--- a/crates/vcs_data/src/data/local/config.rs
+++ b/crates/vcs_data/src/data/local/config.rs
@@ -130,7 +130,7 @@ impl LocalConfig {
}
self.sheet_in_use = Some(sheet);
- LocalConfig::write(&self).await?;
+ LocalConfig::write(self).await?;
Ok(())
}
@@ -153,8 +153,7 @@ impl LocalConfig {
// Create the draft folder if it doesn't exist
if !draft_folder.exists() {
- std::fs::create_dir_all(&draft_folder)
- .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
+ std::fs::create_dir_all(&draft_folder).map_err(std::io::Error::other)?;
}
// Move all files and folders (except .jv folder) to the draft folder with rollback support
@@ -162,7 +161,7 @@ impl LocalConfig {
// Clear the sheet in use
self.sheet_in_use = None;
- LocalConfig::write(&self).await?;
+ LocalConfig::write(self).await?;
Ok(())
}
@@ -177,8 +176,7 @@ impl LocalConfig {
/// Check if local path is empty (except for .jv folder)
async fn check_local_path_empty(&self, local_path: &Path) -> Result<(), std::io::Error> {
let jv_folder = local_path.join(CLIENT_PATH_WORKSPACE_ROOT);
- let mut entries = std::fs::read_dir(local_path)
- .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
+ let mut entries = std::fs::read_dir(local_path).map_err(std::io::Error::other)?;
if entries.any(|entry| {
if let Ok(entry) = entry {
@@ -206,9 +204,9 @@ impl LocalConfig {
local_path: &Path,
) -> Result<(), std::io::Error> {
let draft_entries: Vec<_> = std::fs::read_dir(draft_folder)
- .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?
+ .map_err(std::io::Error::other)?
.collect::<Result<Vec<_>, _>>()
- .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
+ .map_err(std::io::Error::other)?;
let mut moved_items: Vec<MovedItem> = Vec::new();
@@ -222,7 +220,7 @@ impl LocalConfig {
for moved_item in &moved_items {
let _ = std::fs::rename(&moved_item.target, &moved_item.source);
}
- std::io::Error::new(std::io::ErrorKind::Other, e)
+ std::io::Error::other(e)
})?;
moved_items.push(MovedItem {
@@ -237,7 +235,7 @@ impl LocalConfig {
for moved_item in &moved_items {
let _ = std::fs::rename(&moved_item.target, &moved_item.source);
}
- std::io::Error::new(std::io::ErrorKind::Other, e)
+ std::io::Error::other(e)
})?;
Ok(())
@@ -251,9 +249,9 @@ impl LocalConfig {
) -> Result<(), std::io::Error> {
let jv_folder = local_path.join(CLIENT_PATH_WORKSPACE_ROOT);
let entries: Vec<_> = std::fs::read_dir(local_path)
- .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?
+ .map_err(std::io::Error::other)?
.collect::<Result<Vec<_>, _>>()
- .map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
+ .map_err(std::io::Error::other)?;
let mut moved_items: Vec<MovedItem> = Vec::new();
@@ -276,7 +274,7 @@ impl LocalConfig {
for moved_item in &moved_items {
let _ = std::fs::rename(&moved_item.target, &moved_item.source);
}
- std::io::Error::new(std::io::ErrorKind::Other, e)
+ std::io::Error::other(e)
})?;
moved_items.push(MovedItem {
@@ -344,9 +342,7 @@ impl LocalConfig {
return None;
};
- let Some(current_dir) = current_local_path() else {
- return None;
- };
+ let current_dir = current_local_path()?;
Some(self.draft_folder(&self.using_account, sheet_name, current_dir))
}
diff --git a/crates/vcs_data/src/data/local/file_status.rs b/crates/vcs_data/src/data/local/file_status.rs
index ca5799f..b8b5952 100644
--- a/crates/vcs_data/src/data/local/file_status.rs
+++ b/crates/vcs_data/src/data/local/file_status.rs
@@ -67,7 +67,7 @@ impl<'a> AnalyzeResult<'a> {
let local_path = workspace.local_path();
let file_relative_paths = {
let mut paths = HashSet::new();
- for entry in WalkDir::new(&local_path) {
+ for entry in WalkDir::new(local_path) {
let entry = match entry {
Ok(entry) => entry,
Err(_) => continue,
@@ -78,25 +78,21 @@ impl<'a> AnalyzeResult<'a> {
continue;
}
- if entry.file_type().is_file() {
- if let Ok(relative_path) = entry.path().strip_prefix(&local_path) {
+ if entry.file_type().is_file()
+ && let Ok(relative_path) = entry.path().strip_prefix(local_path) {
let format = format_path(relative_path.to_path_buf());
let Ok(format) = format else {
continue;
};
paths.insert(format);
}
- }
}
paths
};
// Read local sheet
- let local_sheet = match workspace.local_sheet(&member, &sheet_name).await {
- Ok(v) => Some(v),
- Err(_) => None,
- };
+ let local_sheet = (workspace.local_sheet(&member, &sheet_name).await).ok();
// Read cached sheet
let cached_sheet_data = match CachedSheet::cached_sheet_data(&sheet_name).await {
@@ -110,7 +106,7 @@ impl<'a> AnalyzeResult<'a> {
};
// Create new result
- let mut result = Self::none_result(&workspace);
+ let mut result = Self::none_result(workspace);
// Analyze entry
let mut analyze_ctx = AnalyzeContext {
@@ -119,12 +115,12 @@ impl<'a> AnalyzeResult<'a> {
local_sheet,
cached_sheet_data,
};
- Self::analyze_moved(&mut result, &file_relative_paths, &analyze_ctx, &workspace).await?;
+ Self::analyze_moved(&mut result, &file_relative_paths, &analyze_ctx, workspace).await?;
Self::analyze_modified(
&mut result,
&file_relative_paths,
&mut analyze_ctx,
- &workspace,
+ workspace,
)
.await?;
@@ -165,7 +161,7 @@ impl<'a> AnalyzeResult<'a> {
let file_hashes: HashSet<(PathBuf, String)> =
match calc_sha1_multi::<PathBuf, Vec<PathBuf>>(new_files_for_hash, 8192).await {
Ok(hash) => hash,
- Err(e) => return Err(Error::new(std::io::ErrorKind::Other, e)),
+ Err(e) => return Err(Error::other(e)),
}
.iter()
.map(|r| (r.file_path.clone(), r.hash.to_string()))
@@ -222,11 +218,7 @@ impl<'a> AnalyzeResult<'a> {
.as_ref()
.and_then(|local_sheet| local_sheet.mapping_data(from).ok())
.map(|mapping_data| mapping_data.mapping_vfid.clone());
- if let Some(vfid) = vfid {
- Some((vfid, (from.clone(), to.clone())))
- } else {
- None
- }
+ vfid.map(|vfid| (vfid, (from.clone(), to.clone())))
})
.collect();
@@ -246,7 +238,7 @@ impl<'a> AnalyzeResult<'a> {
for path in file_relative_paths {
// Get mapping data
- let Ok(mapping_data) = local_sheet.mapping_data_mut(&path) else {
+ let Ok(mapping_data) = local_sheet.mapping_data_mut(path) else {
continue;
};
@@ -263,7 +255,7 @@ impl<'a> AnalyzeResult<'a> {
let hash_calc = match sha1_hash::calc_sha1(workspace.local_path.join(path), 2048).await
{
Ok(hash) => hash,
- Err(e) => return Err(Error::new(std::io::ErrorKind::Other, e)),
+ Err(e) => return Err(Error::other(e)),
};
// If hash not match, mark as modified
@@ -289,7 +281,7 @@ impl<'a> AnalyzeResult<'a> {
/// Generate a empty AnalyzeResult
fn none_result(local_workspace: &'a LocalWorkspace) -> AnalyzeResult<'a> {
AnalyzeResult {
- local_workspace: local_workspace,
+ local_workspace,
moved: HashMap::new(),
created: HashSet::new(),
lost: HashSet::new(),
diff --git a/crates/vcs_data/src/data/local/latest_info.rs b/crates/vcs_data/src/data/local/latest_info.rs
index 77d632e..99f423b 100644
--- a/crates/vcs_data/src/data/local/latest_info.rs
+++ b/crates/vcs_data/src/data/local/latest_info.rs
@@ -1,5 +1,5 @@
use std::{
- path::PathBuf,
+ path::{Path, PathBuf},
time::{SystemTime, UNIX_EPOCH},
};
@@ -10,7 +10,6 @@ use tokio::time::Instant;
use crate::{
constants::{CLIENT_FILE_LATEST_INFO, CLIENT_FILE_LATEST_INFO_NOSET},
data::{
- local::{LocalWorkspace, config::LocalConfig},
member::{Member, MemberId},
sheet::{SheetData, SheetName},
},
@@ -46,7 +45,7 @@ pub struct LatestInfo {
impl LatestInfo {
/// Get the path to the latest info file for a given workspace and member ID
- pub fn latest_info_path(local_workspace_path: &PathBuf, member_id: &MemberId) -> PathBuf {
+ pub fn latest_info_path(local_workspace_path: &Path, member_id: &MemberId) -> PathBuf {
local_workspace_path.join(CLIENT_FILE_LATEST_INFO.replace(ACCOUNT, member_id))
}
}
diff --git a/crates/vcs_data/src/data/local/local_files.rs b/crates/vcs_data/src/data/local/local_files.rs
index 8444f97..9cc244f 100644
--- a/crates/vcs_data/src/data/local/local_files.rs
+++ b/crates/vcs_data/src/data/local/local_files.rs
@@ -1,4 +1,4 @@
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
use string_proc::format_path::format_path;
use tokio::fs;
@@ -25,16 +25,13 @@ impl RelativeFiles {
}
/// Read the relative paths within the project from the input file list
-pub async fn get_relative_paths(
- local_path: &PathBuf,
- paths: &Vec<PathBuf>,
-) -> Option<RelativeFiles> {
+pub async fn get_relative_paths(local_path: &PathBuf, paths: &[PathBuf]) -> Option<RelativeFiles> {
// Get Relative Paths
- let Ok(paths) = format_input_paths_and_ignore_outside_paths(&local_path, &paths).await else {
+ let Ok(paths) = format_input_paths_and_ignore_outside_paths(local_path, paths).await else {
return None;
};
let files: Vec<PathBuf> = abs_paths_to_abs_files(paths).await;
- let Ok(files) = parse_to_relative(&local_path, files) else {
+ let Ok(files) = parse_to_relative(local_path, files) else {
return None;
};
Some(RelativeFiles { files })
@@ -42,7 +39,7 @@ pub async fn get_relative_paths(
/// Normalize the input paths
async fn format_input_paths(
- local_path: &PathBuf,
+ local_path: &Path,
track_files: &[PathBuf],
) -> Result<Vec<PathBuf>, std::io::Error> {
let current_dir = local_path;
@@ -54,8 +51,7 @@ async fn format_input_paths(
// Skip paths that contain .jv directories
if path.components().any(|component| {
if let std::path::Component::Normal(name) = component {
- name.to_str()
- .map_or(false, |s| s == CLIENT_FOLDER_WORKSPACE_ROOT_NAME)
+ name.to_str() == Some(CLIENT_FOLDER_WORKSPACE_ROOT_NAME)
} else {
false
}
@@ -109,10 +105,7 @@ fn parse_to_relative(
})
.collect();
- match result {
- Ok(paths) => Ok(paths),
- Err(e) => Err(e),
- }
+ result
}
/// Convert absolute paths to absolute file paths, expanding directories to their contained files
diff --git a/crates/vcs_data/src/data/local/local_sheet.rs b/crates/vcs_data/src/data/local/local_sheet.rs
index d1d889e..f1a2159 100644
--- a/crates/vcs_data/src/data/local/local_sheet.rs
+++ b/crates/vcs_data/src/data/local/local_sheet.rs
@@ -89,6 +89,7 @@ impl LocalSheetData {
impl LocalMappingMetadata {
/// Create a new MappingMetaData instance
+ #[allow(clippy::too_many_arguments)]
pub fn new(
hash_when_updated: String,
time_when_updated: SystemTime,