Add a shared error type and shared file helpers to the Rust host
Replace the three error styles with one Error type and one Result alias in error.rs. The error crosses IPC as the same plain string as before. The message text does not change. Move the shared file mechanics to fsutil.rs. These are the reserved-name check, the link and junction check, the limited reads, and the atomic writes. Each module keeps its own path rules, limits, and messages. The plugin settings writer now flushes its file to disk before the rename. Remove the current_root_path and list_entries wrappers and an unused mime value. Use named windows-sys constants for the process, file, drive, and error codes. Add a test that compares the command lists in lib.rs, build.rs, and the capability files. The settings capability must be a subset of the full list. In Cargo.toml, set the author, keep only the rlib crate type, and remove the unused thiserror dependency. Remove panic = "abort" from the release profile. A panic on a worker thread then stops only that thread. It does not stop the editor with unsaved buffers.
This commit is contained in:
@@ -3,7 +3,8 @@ use reqwest::{blocking::Client, Url};
|
||||
use serde_json::Value;
|
||||
use std::{io::Read, time::Duration};
|
||||
|
||||
type Result<T> = std::result::Result<T, String>;
|
||||
use crate::error::Result;
|
||||
|
||||
const MAX_METADATA: usize = 2 * 1024 * 1024;
|
||||
const MAX_ARCHIVE: usize = 100 * 1024 * 1024;
|
||||
|
||||
@@ -86,15 +87,9 @@ pub struct Download {
|
||||
}
|
||||
|
||||
fn read_limited(reader: impl Read, limit: usize) -> Result<Vec<u8>> {
|
||||
let mut bytes = Vec::new();
|
||||
reader
|
||||
.take(limit as u64 + 1)
|
||||
.read_to_end(&mut bytes)
|
||||
.map_err(|_| "The download was interrupted. Try again.")?;
|
||||
if bytes.len() > limit {
|
||||
return Err("The download exceeds its size limit.".into());
|
||||
}
|
||||
Ok(bytes)
|
||||
crate::fsutil::read_to_limit(reader, limit as u64)
|
||||
.map_err(|_| "The download was interrupted. Try again.")?
|
||||
.ok_or_else(|| "The download exceeds its size limit.".into())
|
||||
}
|
||||
|
||||
// Send credentials only to the release API's origin, including after redirects.
|
||||
@@ -142,7 +137,7 @@ fn get(
|
||||
401 | 403 => "Access denied. Check the token and repository read access.".into(),
|
||||
404 => "Release not found. Check the repository, release tag, and token for private access.".into(),
|
||||
429 => "The server request limit was reached. Try again later.".into(),
|
||||
code => format!("The release server returned HTTP {code}."),
|
||||
code => format!("The release server returned HTTP {code}.").into(),
|
||||
});
|
||||
}
|
||||
if response
|
||||
@@ -323,6 +318,7 @@ pub(crate) mod tests {
|
||||
let url = Url::parse(&base).unwrap();
|
||||
assert!(get(&client, url.clone(), &url, None, limit)
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
.contains(message));
|
||||
handle.join().unwrap();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user