Skip to content

Commit 13b46d5

Browse files
fix(desktop): disk space detection (hoppscotch#5019)
This fix replace `sys-info v0.9.1` with the more actively maintained `sysinfo 0.34.2` which does return size of the disk in bytes. Closes hoppscotch#5017, HFE-831 Rebased on hoppscotch#5010, consider merging that first. Issues: Appload fails to load with a "Storage full" error despite having sufficient disk space. This was caused by a unit mismatch in the `sys-info` crate which returns disk space in kilobytes instead of bytes. - sys_info::disk_info() returns values in KB, see: https://github.com/FillZpp/sys-info-rs/blob/60ecf1470a5b7c90242f429934a3bacb6023ec4d/c/linux.c#L119 - The `StorageFull` error was triggered when comparing raw bytes against a KB value, causing false positive Changes: - Rewrite the `ensure_space` function to find the correct disk of the config dir - Add a new `StorageError::DiskNotFound` for cases where the disk cannot be resolved
1 parent 93787f8 commit 13b46d5

File tree

7 files changed

+287
-120
lines changed

7 files changed

+287
-120
lines changed

packages/hoppscotch-desktop/plugin-workspace/tauri-plugin-appload/Cargo.lock

Lines changed: 88 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/hoppscotch-desktop/plugin-workspace/tauri-plugin-appload/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ blake3 = { version = "1.5.4", features = ["serde"] }
2828
ed25519-dalek = { version = "2.1.1", features = ["rand_core", "serde"] }
2929
hex = "0.4.3"
3030
lru = "0.12.5"
31-
sys-info = "0.9.1"
31+
sysinfo = "0.34.2"
3232
humantime-serde = "1.1.1"
3333
futures = "0.3.31"
3434
mime_guess = "2.0.5"

packages/hoppscotch-desktop/plugin-workspace/tauri-plugin-appload/src/storage/error.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ pub enum StorageError {
1111
#[error("Invalid path: {0}")]
1212
InvalidPath(String),
1313

14+
#[error("Disk not found: fatal error, unable to resolve user config storage disk")]
15+
DiskNotFound,
16+
1417
#[error("Storage full: required {required} bytes, available {available} bytes")]
1518
StorageFull { required: u64, available: u64 },
1619

packages/hoppscotch-desktop/plugin-workspace/tauri-plugin-appload/src/storage/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::path::PathBuf;
22

33
pub struct StorageLayout {
4-
root: PathBuf,
4+
pub(crate) root: PathBuf,
55
}
66

77
impl StorageLayout {

packages/hoppscotch-desktop/plugin-workspace/tauri-plugin-appload/src/storage/manager.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::path::PathBuf;
22
use std::sync::Arc;
3+
use sysinfo::Disks;
34
use tokio::sync::RwLock;
45
use tracing;
56

@@ -144,12 +145,27 @@ impl StorageManager {
144145

145146
async fn ensure_space(&self, required: usize) -> Result<()> {
146147
tracing::debug!(required_space = required, "Checking available disk space");
147-
let available = sys_info::disk_info()
148-
.map_err(|e| {
149-
tracing::error!(error = %e, "Failed to retrieve disk information");
150-
StorageError::OtherError(format!("Failed to get disk info: {}", e))
151-
})?
152-
.free;
148+
149+
let disks = Disks::new_with_refreshed_list();
150+
151+
let storage_path = self.layout.root.canonicalize().map_err(|e| {
152+
tracing::error!(error = %e, "Failed to resolve storage path");
153+
StorageError::Io(e)
154+
})?;
155+
156+
// NOTE: There cannot be more than one user config storage disk,
157+
// although even if there is, defaulting to the first one we found
158+
// is as good of a guess as any.
159+
let disk = disks
160+
.into_iter()
161+
.find(|disk| storage_path.starts_with(disk.mount_point()));
162+
163+
let Some(disk) = disk else {
164+
tracing::error!("Fatal error, unable to resolve user config storage disk");
165+
return Err(StorageError::DiskNotFound);
166+
};
167+
168+
let available = disk.available_space();
153169

154170
if (required as u64) > available {
155171
tracing::warn!(

0 commit comments

Comments
 (0)