mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-19 00:17:32 +00:00
Scratch free space is asked of the folder itself, so network folders report their own numbers
Windows network folders reported unknown because sysinfo doesn't list them, and an unlisted Linux NFS or CIFS mount used the numbers of its listed parent. GetDiskFreeSpaceEx (Windows) and statvfs (Unix) on the directory fix both. macOS keeps sysinfo's figure, which counts purgeable space, when the listed disk is this volume. A mount that reports no space is flagged in Preferences, in the hard-limit refusal and in spill::stats, with a hint to set a Scratch Size Limit or use a local disk. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
02c5ea8e68
commit
ed49cd9401
7 files changed
+240
-74
No files matched your search
Generated
+1
@@ -5504,6 +5504,7 @@ dependencies = [
|
||||
"photocraft-geom",
|
||||
"proptest",
|
||||
"rayon",
|
||||
"rustix 1.1.5",
|
||||
"serde",
|
||||
"sysinfo",
|
||||
"winsafe",
|
||||
|
||||
@@ -23,7 +23,7 @@ pub enum EngineError {
|
||||
PsdApprovalRequired { name: String, required: u64, soft_limit: u64, hard_limit: u64, available_ram: Option<u64> },
|
||||
/// The file's estimated memory cannot be admitted within the hard ceiling, which no approval
|
||||
/// can raise. The requirement may equal the ceiling when the estimate saturated.
|
||||
#[error("cannot open “{name}”: its estimated memory requirement of {required_text} ({required} bytes) cannot be admitted within the {limit_text} ({limit} byte) hard limit{scope}", required_text = bytes_text(.required), limit_text = bytes_text(.limit), scope = build_limit_scope(build_memory_limit()))]
|
||||
#[error("cannot open “{name}”: its estimated memory requirement of {required_text} ({required} bytes) cannot be admitted within the {limit_text} ({limit} byte) hard limit{scope}{scratch}", required_text = bytes_text(.required), limit_text = bytes_text(.limit), scope = build_limit_scope(build_memory_limit()), scratch = unmeasured_scratch_hint(scratch_room_unmeasured()))]
|
||||
PsdHardBudget { name: String, required: u64, limit: u64 },
|
||||
/// The file behind an opened handle is not the one whose memory estimate was approved.
|
||||
/// The document is discarded and is not opened.
|
||||
@@ -76,6 +76,21 @@ fn build_limit_scope(limit: BuildMemoryLimit) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// Exactly when spilling is on but gives an import no room: see `spill::scratch_capacity`.
|
||||
fn scratch_room_unmeasured() -> bool {
|
||||
let stats = photocraft_raster::spill::stats();
|
||||
stats.free_space_unmeasured && stats.size_cap_bytes.is_none()
|
||||
}
|
||||
|
||||
/// The hint that follows the scope when the scratch disk's free space can't be measured.
|
||||
fn unmeasured_scratch_hint(unmeasured: bool) -> &'static str {
|
||||
if unmeasured {
|
||||
". The scratch disk's free space can't be measured, so it adds no room for this file: set a Scratch Size Limit in Preferences > Scratch Disks, or use a local disk"
|
||||
} else {
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
/// A size for people, next to the exact byte count: "21.5 GiB", "900 MiB", "17 B".
|
||||
fn bytes_text(bytes: &u64) -> String {
|
||||
const GIB: u64 = 1 << 30;
|
||||
@@ -144,6 +159,13 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unmeasured_scratch_hint_only_when_unmeasured() {
|
||||
assert_eq!(unmeasured_scratch_hint(false), "");
|
||||
let hint = unmeasured_scratch_hint(true);
|
||||
assert!(hint.starts_with(". ") && hint.contains("Scratch Size Limit") && hint.contains("local disk"), "{hint}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn hard_budget_message_names_file_numbers_and_scope() {
|
||||
let text = EngineError::PsdHardBudget { name: "big.psd".into(), required: 23_049_071_616, limit: 2_147_483_648 }.to_string();
|
||||
|
||||
@@ -15,11 +15,19 @@ crc32fast = "1"
|
||||
lz4_flex = { version = "0.11", default-features = false, features = ["std", "safe-encode", "safe-decode"] }
|
||||
|
||||
# Native only: converting a region's tiles is independent per tile, so it runs on all cores;
|
||||
# sysinfo reads the physical RAM size for the memory limit and the scratch volume's free space.
|
||||
# sysinfo reads the physical RAM size for the memory limit.
|
||||
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||
rayon = { workspace = true }
|
||||
sysinfo = { version = "=0.40.1", default-features = false, features = ["system"] }
|
||||
|
||||
# macOS reports capacity including purgeable space only through sysinfo's volume properties.
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
sysinfo = { version = "=0.40.1", default-features = false, features = ["system", "disk"] }
|
||||
|
||||
# statvfs on the scratch directory.
|
||||
[target.'cfg(unix)'.dependencies]
|
||||
rustix = { version = "1.1", default-features = false, features = ["std", "fs"] }
|
||||
|
||||
# Available physical memory and commit headroom (memory/system.rs) through winsafe's safe
|
||||
# `GlobalMemoryStatusEx` wrapper.
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
|
||||
+188
-64
@@ -235,6 +235,8 @@ struct Manager {
|
||||
next_space_check: AtomicU64,
|
||||
/// A sweep wrote successfully since the last resume: reset the retry backoff.
|
||||
recovering: AtomicBool,
|
||||
/// The last free-space query for the scratch directory got no answer.
|
||||
space_unmeasured: AtomicBool,
|
||||
registry: Mutex<Registry>,
|
||||
config: Mutex<Config>,
|
||||
evictions: AtomicU64,
|
||||
@@ -284,6 +286,7 @@ static M: Manager = Manager {
|
||||
space_limit: AtomicU64::new(u64::MAX),
|
||||
next_space_check: AtomicU64::new(0),
|
||||
recovering: AtomicBool::new(false),
|
||||
space_unmeasured: AtomicBool::new(false),
|
||||
registry: Mutex::new(Registry { cells: Vec::new(), hand: 0 }),
|
||||
config: Mutex::new(Config { dir: None, file: None, last_error: None, budget: 0, paused: None, backoff: RETRY_FIRST, size_cap: None }),
|
||||
evictions: AtomicU64::new(0),
|
||||
@@ -488,9 +491,16 @@ impl Manager {
|
||||
}
|
||||
}
|
||||
|
||||
/// [`free_space`], remembering whether it got an answer for [`free_space_unmeasured`].
|
||||
fn measure_free_space(dir: &Path) -> Option<(u64, u64)> {
|
||||
let space = free_space(dir);
|
||||
M.space_unmeasured.store(space.is_none(), Ordering::Relaxed);
|
||||
space
|
||||
}
|
||||
|
||||
/// Free space on the volume holding `dir`, minus the reserve, sets how far the file may grow.
|
||||
fn refresh_space(c: &Config, dir: &Path, used: u64) {
|
||||
let room = free_space(dir).map_or(u64::MAX, |(available, total)| used.saturating_add(available.saturating_sub(RESERVE_MIN.max(total / 20))));
|
||||
let room = measure_free_space(dir).map_or(u64::MAX, |(available, total)| used.saturating_add(available.saturating_sub(RESERVE_MIN.max(total / 20))));
|
||||
let limit = c.size_cap.map_or(room, |cap| cap.min(room));
|
||||
M.space_limit.store(limit, Ordering::Relaxed);
|
||||
M.next_space_check.store(used.saturating_add(SPACE_CHECK_EVERY), Ordering::Relaxed);
|
||||
@@ -503,64 +513,102 @@ fn no_room(dir: &Path, cap: Option<u64>) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// (available, total) bytes of the volume holding `dir`: the mount point that is its longest
|
||||
/// prefix. `None` if unknown, which disables only the free-space check, not spilling. On Windows a
|
||||
/// network scratch folder isn't listed, so it reports `None` (no free-space reserve; import
|
||||
/// allowance only up to a Scratch Size Limit, if one is set). On Linux an unlisted network mount
|
||||
/// matches its listed parent mount, such as `/`, and uses that volume's numbers.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
/// (available, total) bytes of the volume holding `dir`, asked of the directory itself so that a
|
||||
/// network folder or any other mount reports its own numbers: `GetDiskFreeSpaceEx` on Windows,
|
||||
/// `statvfs` on Unix. Available is what the current user can write (per-user quotas on Windows, the
|
||||
/// root reserve on Unix). `None` if the system can't say (the query failed, or it reports a total
|
||||
/// of zero, as some FUSE and WebDAV mounts do), which disables only the free-space check, not
|
||||
/// spilling; [`free_space_unmeasured`] tells the user.
|
||||
#[cfg(any(unix, windows))]
|
||||
fn free_space(dir: &Path) -> Option<(u64, u64)> {
|
||||
let dir = std::fs::canonicalize(dir).ok()?;
|
||||
let dir = without_verbatim_disk_prefix(&dir).unwrap_or(dir);
|
||||
let disks = sysinfo::Disks::new_with_refreshed_list_specifics(sysinfo::DiskRefreshKind::nothing().with_storage()).ok()?;
|
||||
disks
|
||||
.iter()
|
||||
.filter(|d| dir.starts_with(d.mount_point()))
|
||||
.max_by_key(|d| d.mount_point().as_os_str().len())
|
||||
.and_then(|d| known_space(available_to_caller(d.mount_point()).unwrap_or_else(|| d.available_space()), d.total_space()))
|
||||
let (available, total) = volume_space(&dir)?;
|
||||
known_space(with_purgeable_space(&dir, available, total), total)
|
||||
}
|
||||
|
||||
/// sysinfo keeps a volume whose space query failed, with both numbers zero; treating that as an
|
||||
/// empty disk would pause spilling, so it counts as unknown.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
/// A zero total means the system could not say (a failed query, or a mount that reports no
|
||||
/// capacity); treating that as an empty disk would pause spilling, so it counts as unknown.
|
||||
#[cfg(any(unix, windows))]
|
||||
fn known_space(available: u64, total: u64) -> Option<(u64, u64)> {
|
||||
(total != 0).then_some((available, total))
|
||||
}
|
||||
|
||||
/// Bytes the current user can write to the volume at `mount`, which a per-user disk quota can make
|
||||
/// less than the volume's free space that sysinfo reports. `None` if the query fails.
|
||||
/// (available, total) bytes of the volume holding `dir`, from `statvfs`.
|
||||
#[cfg(unix)]
|
||||
fn volume_space(dir: &Path) -> Option<(u64, u64)> {
|
||||
let vfs = rustix::io::retry_on_intr(|| rustix::fs::statvfs(dir)).ok()?;
|
||||
Some((vfs.f_bavail.saturating_mul(vfs.f_frsize), vfs.f_blocks.saturating_mul(vfs.f_frsize)))
|
||||
}
|
||||
|
||||
/// (available, total) bytes of the volume holding `dir`, from `GetDiskFreeSpaceEx`. winsafe takes
|
||||
/// `&str`, so a non-UTF-8 folder name uses its nearest UTF-8 ancestor (the same volume in practice).
|
||||
#[cfg(windows)]
|
||||
fn available_to_caller(mount: &Path) -> Option<u64> {
|
||||
let mut available = 0;
|
||||
winsafe::GetDiskFreeSpaceEx(Some(mount.to_str()?), Some(&mut available), None, None).ok()?;
|
||||
Some(available)
|
||||
fn volume_space(dir: &Path) -> Option<(u64, u64)> {
|
||||
let verbatim = dir.ancestors().find_map(Path::to_str)?;
|
||||
// The plain form first: a plain path over MAX_PATH fails, so the verbatim form is the fallback.
|
||||
without_verbatim_prefix(Path::new(verbatim)).and_then(|plain| disk_free_space(plain.to_str()?)).or_else(|| disk_free_space(verbatim))
|
||||
}
|
||||
|
||||
/// Elsewhere sysinfo's figure already is what the user can write.
|
||||
#[cfg(all(not(windows), not(target_arch = "wasm32")))]
|
||||
fn available_to_caller(_mount: &Path) -> Option<u64> {
|
||||
None
|
||||
#[cfg(windows)]
|
||||
fn disk_free_space(dir: &str) -> Option<(u64, u64)> {
|
||||
// GetDiskFreeSpaceEx requires the trailing backslash on UNC paths.
|
||||
let arg = if dir.ends_with('\\') { dir.to_string() } else { format!("{dir}\\") };
|
||||
let (mut available, mut total) = (0, 0);
|
||||
winsafe::GetDiskFreeSpaceEx(Some(&arg), Some(&mut available), Some(&mut total), None).ok()?;
|
||||
Some((available, total))
|
||||
}
|
||||
|
||||
/// The plain form of a verbatim disk path (`\\?\C:\x` to `C:\x`), or `None` to keep the path as
|
||||
/// is. `canonicalize` returns `\\?\C:\x` on Windows, whose prefix never equals a mount point's
|
||||
/// plain `C:\`. Unix paths never have a prefix component, so this is `None` there.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
fn without_verbatim_disk_prefix(path: &Path) -> Option<PathBuf> {
|
||||
/// `statvfs` doesn't count purgeable space (local snapshots and caches macOS frees on demand) but
|
||||
/// sysinfo does: when the listed disk with the longest mount point holding `dir` is this volume,
|
||||
/// recognised by an equal total (APFS firmlinks give `/Users` and `/` different device ids, so ids
|
||||
/// can't be compared), use its available figure. Never fails.
|
||||
#[cfg(target_os = "macos")]
|
||||
fn with_purgeable_space(dir: &Path, available: u64, total: u64) -> u64 {
|
||||
sysinfo::Disks::new_with_refreshed_list_specifics(sysinfo::DiskRefreshKind::nothing().with_storage())
|
||||
.ok()
|
||||
.and_then(|disks| {
|
||||
disks
|
||||
.iter()
|
||||
.filter(|d| dir.starts_with(d.mount_point()))
|
||||
.max_by_key(|d| d.mount_point().as_os_str().len())
|
||||
.filter(|d| d.total_space() == total)
|
||||
.map(|d| d.available_space())
|
||||
})
|
||||
.unwrap_or(available)
|
||||
}
|
||||
|
||||
#[cfg(all(any(unix, windows), not(target_os = "macos")))]
|
||||
fn with_purgeable_space(_dir: &Path, available: u64, _total: u64) -> u64 {
|
||||
available
|
||||
}
|
||||
|
||||
/// The plain form of a verbatim path, or `None` to keep the path as is. `canonicalize` returns
|
||||
/// `\\?\C:\x` and `\\?\UNC\server\share\x` on Windows, whose plain forms are `C:\x` and
|
||||
/// `\\server\share\x`.
|
||||
#[cfg(windows)]
|
||||
fn without_verbatim_prefix(path: &Path) -> Option<PathBuf> {
|
||||
use std::ffi::OsString;
|
||||
use std::path::{Component, Prefix};
|
||||
let mut components = path.components();
|
||||
let Some(Component::Prefix(prefix)) = components.next() else {
|
||||
return None;
|
||||
};
|
||||
let Prefix::VerbatimDisk(letter) = prefix.kind() else {
|
||||
return None;
|
||||
let mut out = match prefix.kind() {
|
||||
Prefix::VerbatimDisk(letter) => PathBuf::from(format!("{}:", char::from(letter))),
|
||||
Prefix::VerbatimUNC(server, share) => {
|
||||
let mut unc = OsString::from(r"\\");
|
||||
unc.push(server);
|
||||
unc.push("\\");
|
||||
unc.push(share);
|
||||
PathBuf::from(unc)
|
||||
}
|
||||
_ => return None,
|
||||
};
|
||||
let mut out = PathBuf::from(format!("{}:", char::from(letter)));
|
||||
out.extend(components);
|
||||
Some(out)
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
#[cfg(not(any(unix, windows)))]
|
||||
fn free_space(_dir: &Path) -> Option<(u64, u64)> {
|
||||
None
|
||||
}
|
||||
@@ -714,6 +762,8 @@ pub struct SpillStats {
|
||||
pub paused: bool,
|
||||
/// Scratch file size limit ([`set_size_cap`]); `None` = only the free-space reserve.
|
||||
pub size_cap_bytes: Option<u64>,
|
||||
/// Spilling is on but the scratch directory's volume won't report its free space ([`free_space_unmeasured`]).
|
||||
pub free_space_unmeasured: bool,
|
||||
}
|
||||
|
||||
pub fn stats() -> SpillStats {
|
||||
@@ -730,6 +780,7 @@ pub fn stats() -> SpillStats {
|
||||
last_error: c.last_error.clone(),
|
||||
paused: c.paused.is_some(),
|
||||
size_cap_bytes: c.size_cap,
|
||||
free_space_unmeasured: free_space_unmeasured(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -751,7 +802,7 @@ pub fn scratch_capacity() -> Option<u64> {
|
||||
let c = M.config();
|
||||
(c.dir.clone()?, c.file.as_ref().map_or(0, |f| f.used()), c.size_cap)
|
||||
};
|
||||
let room = free_space(&dir).map(|(available, total)| available.saturating_sub(RESERVE_MIN.max(total / 20)));
|
||||
let room = measure_free_space(&dir).map(|(available, total)| available.saturating_sub(RESERVE_MIN.max(total / 20)));
|
||||
let room = match (room, cap) {
|
||||
(Some(room), Some(cap)) => room.min(cap.saturating_sub(used)),
|
||||
(Some(room), None) => room,
|
||||
@@ -761,6 +812,13 @@ pub fn scratch_capacity() -> Option<u64> {
|
||||
Some(room - room / 64)
|
||||
}
|
||||
|
||||
/// Whether spilling is on but the scratch directory's volume won't report its free space, so the
|
||||
/// reserve doesn't apply and imports earn scratch room only up to a size limit. A plain atomic
|
||||
/// read, safe to call every frame.
|
||||
pub fn free_space_unmeasured() -> bool {
|
||||
enabled() && M.space_unmeasured.load(Ordering::Relaxed)
|
||||
}
|
||||
|
||||
/// Whether spilling is on (tiles beyond the budget go to disk).
|
||||
pub fn enabled() -> bool {
|
||||
M.budget.load(Ordering::Relaxed) > 0
|
||||
@@ -834,41 +892,35 @@ mod tests {
|
||||
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn verbatim_disk_prefix_is_stripped_only_for_disks() {
|
||||
fn verbatim_prefix_is_stripped_for_disks_and_unc_shares() {
|
||||
let cases: &[(&str, Option<&str>)] = &[
|
||||
(r"\\?\C:\x\y", Some(r"C:\x\y")),
|
||||
(r"\\?\C:\", Some(r"C:\")),
|
||||
(r"\\?\UNC\server\share\x", None),
|
||||
(r"\\?\UNC\server\share\x", Some(r"\\server\share\x")),
|
||||
(r"\\?\UNC\server\share\", Some(r"\\server\share\")),
|
||||
(r"\\?\Volume{0000-1}\x", None),
|
||||
(r"C:\x", None),
|
||||
(r"\\server\share\x", None),
|
||||
];
|
||||
for (input, want) in cases {
|
||||
assert_eq!(without_verbatim_disk_prefix(Path::new(input)).as_deref(), want.map(Path::new), "{input}");
|
||||
assert_eq!(without_verbatim_prefix(Path::new(input)).as_deref(), want.map(Path::new), "{input}");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn verbatim_disk_prefix_keeps_non_utf8_names() {
|
||||
fn verbatim_prefix_keeps_non_utf8_names() {
|
||||
use std::os::windows::ffi::OsStringExt;
|
||||
let mut wide: Vec<u16> = r"\\?\C:\a".encode_utf16().collect();
|
||||
wide.push(0xD800);
|
||||
let path = PathBuf::from(std::ffi::OsString::from_wide(&wide));
|
||||
let plain = without_verbatim_disk_prefix(&path).unwrap();
|
||||
let plain = without_verbatim_prefix(&path).unwrap();
|
||||
assert!(plain.starts_with(r"C:\"));
|
||||
assert!(plain.to_str().is_none());
|
||||
}
|
||||
|
||||
#[cfg(not(any(windows, target_arch = "wasm32")))]
|
||||
#[test]
|
||||
fn verbatim_disk_prefix_is_none_on_unix() {
|
||||
assert_eq!(without_verbatim_disk_prefix(Path::new("/tmp/x")), None);
|
||||
assert_eq!(without_verbatim_disk_prefix(Path::new(r"\\?\C:\x")), None);
|
||||
}
|
||||
|
||||
// `free_space` returned `None` on Windows before the fix: `canonicalize` gives `\\?\C:\..`,
|
||||
// which never started with the mount point `C:\`.
|
||||
// `free_space` returned `None` on Windows before: `canonicalize` gives `\\?\C:\..`, which never
|
||||
// started with the mount point `C:\`.
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn free_space_finds_the_temp_volume_on_windows() {
|
||||
@@ -881,7 +933,91 @@ mod tests {
|
||||
assert_eq!(total, temp_volume_total);
|
||||
}
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
// The real redirector path: the administrative share of this machine's system drive.
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn free_space_reads_a_unc_path() {
|
||||
let unc = Path::new(r"\\localhost\C$\Windows");
|
||||
if std::fs::canonicalize(unc).is_err() {
|
||||
eprintln!("the administrative share {} isn't reachable; skipping", unc.display());
|
||||
return;
|
||||
}
|
||||
let (_, unc_total) = free_space(unc).unwrap();
|
||||
let (_, local_total) = free_space(Path::new(r"C:\")).unwrap();
|
||||
assert_eq!(unc_total, local_total);
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn free_space_reads_a_folder_past_max_path() {
|
||||
let base = std::fs::canonicalize(std::env::temp_dir()).unwrap().join(format!("photocraft-long-{}", std::process::id()));
|
||||
let mut deep = base.clone();
|
||||
while deep.as_os_str().len() <= 300 {
|
||||
deep.push("a".repeat(40));
|
||||
}
|
||||
if std::fs::create_dir_all(&deep).is_err() {
|
||||
let _ = std::fs::remove_dir_all(&base);
|
||||
return;
|
||||
}
|
||||
let space = free_space(&deep);
|
||||
let _ = std::fs::remove_dir_all(&base);
|
||||
assert!(space.is_some());
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn free_space_reads_a_non_utf8_folder() {
|
||||
use std::os::windows::ffi::OsStringExt;
|
||||
let mut wide: Vec<u16> = format!("photocraft-nonutf8-{}-", std::process::id()).encode_utf16().collect();
|
||||
wide.push(0xD800);
|
||||
let dir = std::env::temp_dir().join(std::ffi::OsString::from_wide(&wide));
|
||||
if std::fs::create_dir_all(&dir).is_err() {
|
||||
return;
|
||||
}
|
||||
let space = free_space(&dir);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
assert!(space.is_some());
|
||||
}
|
||||
|
||||
// `/dev/shm` is tmpfs, which sysinfo never lists: the same situation as an unlisted NFS mount.
|
||||
// Before the directory itself was asked, it reported the numbers of `/`.
|
||||
#[cfg(target_os = "linux")]
|
||||
#[test]
|
||||
fn free_space_reads_an_unlisted_mount() {
|
||||
let shm = Path::new("/dev/shm");
|
||||
if !shm.is_dir() {
|
||||
return;
|
||||
}
|
||||
let (available, total) = free_space(shm).unwrap();
|
||||
assert!(available <= total);
|
||||
assert_ne!(total, free_space(Path::new("/")).unwrap().1);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[test]
|
||||
fn free_space_keeps_purgeable_space_on_the_temp_volume() {
|
||||
let temp = std::fs::canonicalize(std::env::temp_dir()).unwrap();
|
||||
let (available, _) = free_space(&temp).unwrap();
|
||||
assert!(available >= volume_space(&temp).unwrap().0);
|
||||
}
|
||||
|
||||
#[cfg(target_os = "macos")]
|
||||
#[test]
|
||||
fn free_space_reads_an_unlisted_mount_on_macos() {
|
||||
// `/dev` is devfs; a zero total counts as unknown, so compare only when it is known.
|
||||
if let Some((_, total)) = free_space(Path::new("/dev")) {
|
||||
assert_ne!(total, free_space(Path::new("/")).unwrap().1);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(any(unix, windows))]
|
||||
#[test]
|
||||
fn free_space_of_a_missing_directory_is_unknown() {
|
||||
let missing = std::env::temp_dir().join(format!("photocraft-missing-{}", std::process::id()));
|
||||
assert_eq!(free_space(&missing), None);
|
||||
}
|
||||
|
||||
#[cfg(any(unix, windows))]
|
||||
#[test]
|
||||
fn a_volume_with_no_total_is_unknown() {
|
||||
assert_eq!(known_space(0, 0), None);
|
||||
@@ -890,18 +1026,6 @@ mod tests {
|
||||
assert_eq!(known_space(5, 10), Some((5, 10)));
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
#[test]
|
||||
fn available_to_caller_reads_the_temp_volume() {
|
||||
let temp = std::fs::canonicalize(std::env::temp_dir()).unwrap();
|
||||
let temp = without_verbatim_disk_prefix(&temp).unwrap_or(temp);
|
||||
let root = temp.ancestors().last().unwrap();
|
||||
let mut temp_volume_total = 0;
|
||||
winsafe::GetDiskFreeSpaceEx(Some(temp.to_str().unwrap()), None, Some(&mut temp_volume_total), None).unwrap();
|
||||
assert!(temp_volume_total > 0);
|
||||
assert!(available_to_caller(root).unwrap() <= temp_volume_total);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn failed_read_retains_backing_and_blocks_commit_until_repaired() {
|
||||
let dir = std::env::temp_dir().join(format!("photocraft-read-failure-{}", std::process::id()));
|
||||
|
||||
@@ -15,6 +15,8 @@ fn scratch_capacity_follows_spilling_the_size_limit_and_pauses() {
|
||||
|
||||
spill::configure(Some(&dir), 1 << 20).unwrap();
|
||||
assert!(spill::enabled() && !spill::paused());
|
||||
// A test machine's temp volume always reports its space.
|
||||
assert!(!spill::free_space_unmeasured());
|
||||
// The free-space reserve applies; an unknown volume without a size limit promises nothing.
|
||||
if let Some(room) = spill::scratch_capacity() {
|
||||
assert!(room < u64::MAX / 2, "the reserve and margin are applied: {room}");
|
||||
@@ -36,5 +38,6 @@ fn scratch_capacity_follows_spilling_the_size_limit_and_pauses() {
|
||||
spill::set_size_cap(None);
|
||||
spill::configure(None, 0).unwrap();
|
||||
assert_eq!(spill::scratch_capacity(), None);
|
||||
assert!(!spill::free_space_unmeasured());
|
||||
let _ = std::fs::remove_dir_all(&root);
|
||||
}
|
||||
@@ -522,6 +522,9 @@ fn field_rows(ui: &mut egui::Ui, section: &str, obj: &mut Map<String, Value>, ke
|
||||
if ui.small_button(tl!("Add disk")).clicked() {
|
||||
items.push(json!({"enabled": true, "path": ""}));
|
||||
}
|
||||
if photocraft_raster::spill::free_space_unmeasured() {
|
||||
ui.add(egui::Label::new(RichText::new(tl!("This scratch disk doesn't report its free space, so PhotoCraft can't stop before it fills up, and large files get no extra room from it without a Scratch Size Limit. Set a limit or use a local disk.")).color(t.warning)).wrap());
|
||||
}
|
||||
});
|
||||
obj.insert(k, Value::Array(items));
|
||||
}
|
||||
|
||||
+13
-8
@@ -33,8 +33,8 @@ until the file is dropped or the next sweep.
|
||||
The engine owns a shared, stoppable residency supervisor and joins it when its last session
|
||||
is dropped. `photocraft-raster` only exposes synchronous measurement and bounded eviction
|
||||
operations; standalone callers work without a background thread. `sysinfo` is native-only
|
||||
with its default features disabled and only the `system` (RAM) and `disk` (free space)
|
||||
features enabled.
|
||||
with its default features disabled and only the `system` (RAM) feature enabled, plus `disk` on
|
||||
macOS only, for purgeable space.
|
||||
|
||||
An unavailable or full scratch disk never loses pixels or turns spilling off for the session.
|
||||
A failed scratch write or file creation, or a volume about to run low (free space is checked
|
||||
@@ -46,12 +46,17 @@ spilling resumes on its own once the directory is usable and has room, and chang
|
||||
preferences retries at once. Preferences → Scratch Disks → Scratch Size Limit
|
||||
(`scratchDisks.sizeLimitMb`, 0 = no limit; `spill::set_size_cap`) caps the scratch file:
|
||||
reaching it pauses spilling the same way, and the free-space reserve applies regardless.
|
||||
On Windows, network scratch folders aren't listed as disks, so their free space isn't
|
||||
measured: the free-space reserve doesn't apply to them, and they earn a scratch allowance for
|
||||
large imports only up to the Scratch Size Limit, if one is set. On Linux, an unlisted network
|
||||
mount (NFS or CIFS) counts the free space of the listed mount above it, such as `/`, for both
|
||||
the allowance and the reserve. With neither free space nor a size limit known, imports get no
|
||||
scratch allowance.
|
||||
Free space is asked of the scratch folder itself (`GetDiskFreeSpaceEx` on Windows, `statvfs` on
|
||||
Unix), so a network folder (UNC path, mapped drive, NFS or CIFS mount) reports its own volume's
|
||||
numbers, for both the large-import allowance and the reserve. On macOS a volume sysinfo lists
|
||||
also counts its purgeable space. A mount that doesn't report its space (the query fails, or the
|
||||
total is zero, as with some FUSE and WebDAV mounts) counts as unknown: the free-space reserve
|
||||
doesn't apply, imports earn a scratch allowance only up to the Scratch Size Limit, and
|
||||
Preferences → Scratch Disks and the hard-limit refusal say so, with the hint to set a limit or
|
||||
use a local disk; `spill::stats` exposes it as `freeSpaceUnmeasured`. With neither free space nor
|
||||
a size limit known, imports get no scratch allowance. The query runs on the thread that checks
|
||||
room, as creating the scratch file does, so a dead hard-mounted network folder can block it the
|
||||
same way its scratch I/O would.
|
||||
A failed read retains its backing extent and blocks editing, saving and exporting of the
|
||||
document that holds the tile until it is readable again; other open documents keep working.
|
||||
Each commit checks the health of its own document (before and after an edit, the document a
|
||||
|
||||
Reference in new issue
Block a user