summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/utils/cfg_file/src/config.rs46
-rw-r--r--crates/vcs_actions/src/actions/local_actions.rs8
-rw-r--r--crates/vcs_data/src/constants.rs2
3 files changed, 33 insertions, 23 deletions
diff --git a/crates/utils/cfg_file/src/config.rs b/crates/utils/cfg_file/src/config.rs
index 8f9edc9..daf5e10 100644
--- a/crates/utils/cfg_file/src/config.rs
+++ b/crates/utils/cfg_file/src/config.rs
@@ -115,13 +115,7 @@ pub trait ConfigFile: Serialize + for<'a> Deserialize<'a> + Default {
));
}
- // Open file
- let mut file = fs::File::open(&file_path).await?;
-
- let mut contents = String::new();
- file.read_to_string(&mut contents).await?;
-
- // Determine file format
+ // Determine file format first
let format = file_path
.file_name()
.and_then(|name| name.to_str())
@@ -130,16 +124,36 @@ pub trait ConfigFile: Serialize + for<'a> Deserialize<'a> + Default {
// Deserialize based on format
let result = match format {
- ConfigFormat::Yaml => serde_yaml::from_str(&contents)
- .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?,
- ConfigFormat::Toml => toml::from_str(&contents)
- .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?,
- ConfigFormat::Ron => ron::from_str(&contents)
- .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?,
- ConfigFormat::Json => serde_json::from_str(&contents)
- .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?,
+ ConfigFormat::Yaml => {
+ let mut file = fs::File::open(&file_path).await?;
+ let mut contents = String::new();
+ file.read_to_string(&mut contents).await?;
+ serde_yaml::from_str(&contents)
+ .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?
+ }
+ ConfigFormat::Toml => {
+ let mut file = fs::File::open(&file_path).await?;
+ let mut contents = String::new();
+ file.read_to_string(&mut contents).await?;
+ toml::from_str(&contents)
+ .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?
+ }
+ ConfigFormat::Ron => {
+ let mut file = fs::File::open(&file_path).await?;
+ let mut contents = String::new();
+ file.read_to_string(&mut contents).await?;
+ ron::from_str(&contents)
+ .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?
+ }
+ ConfigFormat::Json => {
+ let mut file = fs::File::open(&file_path).await?;
+ let mut contents = String::new();
+ file.read_to_string(&mut contents).await?;
+ serde_json::from_str(&contents)
+ .map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?
+ }
ConfigFormat::Bincode => {
- // For Bincode, we need to read the file as bytes
+ // For Bincode, we need to read the file as bytes directly
let bytes = fs::read(&file_path).await?;
bincode2::deserialize(&bytes)
.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidData, e))?
diff --git a/crates/vcs_actions/src/actions/local_actions.rs b/crates/vcs_actions/src/actions/local_actions.rs
index 8799930..93ef4d5 100644
--- a/crates/vcs_actions/src/actions/local_actions.rs
+++ b/crates/vcs_actions/src/actions/local_actions.rs
@@ -262,9 +262,7 @@ pub async fn update_to_latest_info_action(
))
.await
else {
- return Err(TcpTargetError::NotFound(
- "Latest info not found.".to_string(),
- ));
+ return Err(TcpTargetError::Io("Read latest info failed".to_string()));
};
// Collect all local versions
@@ -349,9 +347,7 @@ pub async fn update_to_latest_info_action(
))
.await
else {
- return Err(TcpTargetError::NotFound(
- "Latest info not found.".to_string(),
- ));
+ return Err(TcpTargetError::Io("Read latest info failed".to_string()));
};
// Collect files that need to know the holder
diff --git a/crates/vcs_data/src/constants.rs b/crates/vcs_data/src/constants.rs
index 569d0cc..94e245c 100644
--- a/crates/vcs_data/src/constants.rs
+++ b/crates/vcs_data/src/constants.rs
@@ -74,7 +74,7 @@ pub const CLIENT_FILE_LATEST_INFO_NOSET: &str = "./.jv/.temp/wrong.json";
// Client - Other
pub const CLIENT_FILE_IGNOREFILES: &str = "IGNORE_RULES.toml";
-pub const CLIENT_FILE_TODOLIST: &str = "./SETUP.txt";
+pub const CLIENT_FILE_TODOLIST: &str = "./SETUP.md";
pub const CLIENT_FILE_GITIGNORE: &str = "./.jv/.gitignore";
pub const CLIENT_CONTENT_GITIGNORE: &str = "# Git support for JVCS Workspace