Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions crates/data/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,13 +244,49 @@ mod native {
}
Ok(changed)
}

/// The names of the files that differ from this record by what metadata alone shows:
/// added, removed, or another length. Reads no file, so a change that keeps every length
/// isn't seen; [`FileSync::changed`] hashes them. An unreadable file counts as differing.
pub fn resized(&self, path: &Path) -> Vec<String> {
let now = parts(path);
let mut differ: Vec<String> =
now.iter().filter(|(name, p)| !self.files.iter().any(|(n, _)| n == name) && p.exists()).map(|(n, _)| n.clone()).collect();
for (name, was) in &self.files {
let is = now.iter().find(|(n, _)| n == name).map(|(_, p)| len(p));
let same = match (was, is) {
(None, None | Some(Ok(None))) => true,
(Some(was), Some(Ok(Some(len)))) => len == was.len,
_ => false,
};
if !same {
differ.push(name.clone());
}
}
differ
}
}
}

#[cfg(all(test, not(target_arch = "wasm32")))]
mod tests {
use super::*;

#[test]
fn resized_sees_lengths_and_presence_without_reading() {
let dir = tempfile::tempdir().unwrap();
let path = dir.path().join("a.geojson");
std::fs::write(&path, "{}").unwrap();
let record = FileSync::read(&path).unwrap();
assert!(record.resized(&path).is_empty());
std::fs::write(&path, "[]").unwrap();
assert!(record.resized(&path).is_empty(), "same length: only a hash tells");
std::fs::write(&path, "{ }").unwrap();
assert_eq!(record.resized(&path), ["a.geojson"]);
std::fs::remove_file(&path).unwrap();
assert_eq!(record.resized(&path), ["a.geojson"]);
}

#[test]
fn a_shapefile_set_records_its_companions_and_the_missing_ones() {
let dir = tempfile::tempdir().unwrap();
Expand Down
4 changes: 2 additions & 2 deletions crates/engine/src/cmd/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,8 @@ fn sync_state(s: &mut Session, p: &Value) -> CmdResult {
/// Whether `path` names a file on this computer a record is made for: a Shapefile or `.geojson`
/// file, not an address, a database or a network share (`\\host\share`, `//host/share`,
/// `/\host\share`, `\\?\UNC\host\share`). Windows' long form of a local path (`\\?\C:\…`) is one
/// on this computer.
fn local_file(path: &str) -> bool {
/// on this computer. The desktop's Layers pane marks the same layers this publishes.
pub fn local_file(path: &str) -> bool {
let b = rustgis_map::paths::local_path(path).as_bytes();
let sep = |i: usize| b.get(i).is_some_and(|c| matches!(c, b'/' | b'\\'));
// Windows takes any two leading separators, of either kind, for a network share, unless they
Expand Down
Loading
Loading