* claim: #4086 * Raise the largest file SolidCraft opens with a setting or launch flag (#4086) * Translate the file size limit strings * Size limits: design files are .sc now, .solidcraft still read
This commit is contained in:
@@ -163,8 +163,9 @@ fn read_link(file: &Path, own: Option<&str>) -> Result<Vec<u8>> {
|
||||
}
|
||||
// A network location only when its server is allowed, a device never: judged from the text
|
||||
// before anything is read (on Windows, reading `\\host\share\x` connects to the host).
|
||||
solidcraft_io::vfs::read_design_path(&shown, own, solidcraft_io::MAX_DESIGN_BYTES).map_err(|e| {
|
||||
let e = e.to_string();
|
||||
let design = solidcraft_io::limits::Kind::Design;
|
||||
solidcraft_io::vfs::read_design_path(&shown, own, solidcraft_io::limits::max_design_bytes()).map_err(|e| {
|
||||
let e = solidcraft_io::limits::explain(design, e).to_string();
|
||||
EngineError::Other(if e.starts_with(&shown) { e } else { format!("{shown}: {e}") })
|
||||
})
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ fn step_options(p: &Value, cmd: &str) -> Result<StepOptions> {
|
||||
|
||||
/// Read a STEP file as an Import feature.
|
||||
fn read_step(path: &str, names: solidcraft_io::StepNames) -> Result<solidcraft_io::StepFeature> {
|
||||
let bytes = solidcraft_io::vfs::read(path, solidcraft_io::MAX_STEP_BYTES).map_err(|e| EngineError::Other(format!("{path}: {e}")))?;
|
||||
let bytes = solidcraft_io::limits::read(path, solidcraft_io::limits::Kind::Step).map_err(|e| EngineError::Other(format!("{path}: {e}")))?;
|
||||
solidcraft_io::step_import_feature_named(&bytes, path, names).map_err(|e| EngineError::Other(format!("{path}: {e}")))
|
||||
}
|
||||
|
||||
|
||||
@@ -162,7 +162,7 @@ pub fn load(dir: &Path, id: &str) -> Result<(Document, Entry)> {
|
||||
}
|
||||
let entry = read_entry(&file(dir, id, "json")).filter(|e| e.id == id).ok_or_else(|| EngineError::Other(format!("no recovered design `{id}`")))?;
|
||||
let path = design_file(dir, id);
|
||||
let bytes = solidcraft_io::vfs::read(&path.to_string_lossy(), solidcraft_io::MAX_DESIGN_BYTES)
|
||||
let bytes = solidcraft_io::limits::read(&path.to_string_lossy(), solidcraft_io::limits::Kind::Design)
|
||||
.map_err(|e| EngineError::Other(format!("recovered design `{id}`: {e}")))?;
|
||||
Ok((solidcraft_io::read_design(&bytes)?, entry))
|
||||
}
|
||||
|
||||
@@ -112,3 +112,49 @@ fn a_cancelled_preview_import_leaves_no_failure_in_the_shared_cache() {
|
||||
assert!(result.error.is_none() && !result.skipped, "the design imports in full: {:?}", result.error);
|
||||
let _ = std::fs::remove_file(path);
|
||||
}
|
||||
|
||||
/// The largest files read (#4086). Over the default limits a STEP file and a design file are
|
||||
/// refused before anything is read, saying how to raise the limit; with the limits raised (the
|
||||
/// preference, or `--max-file-size` for one run, which wins) the same reads go ahead.
|
||||
#[test]
|
||||
fn raised_file_limits_let_larger_step_and_design_files_be_read() {
|
||||
use solidcraft_io::limits::{self, FileLimits, GB, Kind, MB};
|
||||
/// Puts the defaults back however the test ends.
|
||||
struct Defaults;
|
||||
impl Drop for Defaults {
|
||||
fn drop(&mut self) {
|
||||
let _ = limits::set_override(None);
|
||||
let _ = limits::set_preferred(FileLimits::DEFAULT);
|
||||
}
|
||||
}
|
||||
let _defaults = Defaults;
|
||||
let dir = std::env::temp_dir().join(format!("solidcraft-4086-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
// Sparse files: nothing is written, and a refusal reads nothing either.
|
||||
let sparse = |name: &str, len: u64| {
|
||||
let path = dir.join(name);
|
||||
std::fs::File::create(&path).unwrap().set_len(len).unwrap();
|
||||
path.to_string_lossy().to_string()
|
||||
};
|
||||
let step = sparse("big.step", 512 * MB + 1);
|
||||
let design = sparse("big.solidcraft", 256 * MB + 1);
|
||||
let mut s = Session::default();
|
||||
assert_eq!(limits::effective(), FileLimits::DEFAULT);
|
||||
for path in [&step, &design] {
|
||||
let error = s.execute("doc.open", &json!({"path": path})).unwrap_err().to_string();
|
||||
assert!(error.contains("too large") && error.contains("Largest file to open") && error.contains("--max-file-size"), "{error}");
|
||||
}
|
||||
// The preference raises both limits; the design is now read (and refused only for not being one).
|
||||
limits::set_preferred(FileLimits { step: GB, design: GB }).unwrap();
|
||||
assert_eq!((limits::max_step_bytes(), limits::max_design_bytes()), (1 << 30, 1 << 30));
|
||||
assert!(limits::check(Kind::Step, 512 * MB + 1).is_ok());
|
||||
let error = s.execute("doc.open", &json!({"path": design})).unwrap_err().to_string();
|
||||
assert!(!error.contains("too large"), "{error}");
|
||||
// The flag overrides the preference for the run, and the ceiling holds for both.
|
||||
limits::set_override(Some(2 * GB)).unwrap();
|
||||
assert_eq!(limits::effective(), FileLimits { step: 2 * GB, design: 2 * GB });
|
||||
assert!(limits::set_override(Some(16 * GB + 1)).is_err());
|
||||
assert!(limits::set_preferred(FileLimits { step: 17 * GB, design: GB }).is_err());
|
||||
assert_eq!(limits::preferred(), FileLimits { step: GB, design: GB }, "a refused value changes nothing");
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user