mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge PR #15824: fix(automation): preserve native filenames in saved manifests
This commit is contained in:
commit
36acabbc3b
2 files changed
+30
-1
No files matched your search
@@ -146,7 +146,11 @@ pub fn save_with_renderer_keeping(
|
||||
.or_else(|| path.extension().map(|e| e.to_string_lossy().to_ascii_lowercase()))
|
||||
.ok_or_else(|| AutomationError::BadRequest(format!("cannot tell the format of `{}`; pass a format", path.display())))?;
|
||||
if ext == photocraft_format::EXTENSION {
|
||||
let named = named_for_output(doc, &path.to_string_lossy());
|
||||
let mut named = doc.clone();
|
||||
// Native filenames may contain a literal backslash on Unix.
|
||||
if let Some(name) = path.file_name() {
|
||||
named.name = name.to_string_lossy().into_owned();
|
||||
}
|
||||
let mut local = PcraftWriter::new();
|
||||
let w = writer.unwrap_or(&mut local);
|
||||
w.save_path(&named, path, &native_options(&named, opts)?)?;
|
||||
|
||||
@@ -38,3 +38,28 @@ fn workspace_encoded_native_bundle_uses_requested_name_without_mutating_source()
|
||||
assert_eq!(reopened.name, "Renamed.pcraft");
|
||||
assert_eq!(doc.name, "Original", "a copy should not retarget the open document");
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn native_save_preserves_backslashes_in_the_written_filename() {
|
||||
let dir = std::env::temp_dir().join(format!(
|
||||
"pc-native-backslash-name-{}-{}",
|
||||
std::process::id(),
|
||||
std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_nanos()
|
||||
));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let filename = r"Renamed\Copy.pcraft";
|
||||
let path = dir.join(filename);
|
||||
let mut headless = Headless::trusted_local();
|
||||
headless.handle("doc.new", json!({"width": 8, "height": 8, "name": "Original"})).unwrap();
|
||||
let doc = &headless.session.active().unwrap().doc;
|
||||
|
||||
files::save(doc, &path, None, &Default::default(), None).unwrap();
|
||||
|
||||
let manifest = photocraft_format::read_manifest(&std::fs::read(&path).unwrap()).unwrap();
|
||||
assert_eq!(manifest.document.name, filename);
|
||||
assert_eq!(files::open(&path).unwrap().document.name, filename);
|
||||
assert_eq!(doc.name, "Original", "saving a snapshot must not rename the source");
|
||||
drop(headless);
|
||||
std::fs::remove_dir_all(dir).unwrap();
|
||||
}
|
||||
Reference in new issue
Block a user