Skip to content

Commit

Permalink
Merge pull request #31 from stakpak/feat/sync
Browse files Browse the repository at this point in the history
handle delete
  • Loading branch information
kajogo777 authored Feb 11, 2025
2 parents c0a5166 + ca0761a commit a723792
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/commands/flow/sync.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
collections::HashMap,
collections::{HashMap, HashSet},
hash::{DefaultHasher, Hash, Hasher},
path::Path,
sync::{
Expand Down Expand Up @@ -40,6 +40,7 @@ pub struct DocumentBuffer {
pub struct DocumentsChange {
pub flow_ref: String,
pub documents: Vec<Document>,
pub uris: HashSet<String>,
}

pub enum Change {
Expand Down Expand Up @@ -216,6 +217,13 @@ fn handle_remote_change(
watched_files: &mut HashMap<String, DocumentBuffer>,
) {
println!("🔄 Syncing changes...");
let document_uris: HashSet<String> = change.documents.iter().map(|d| d.uri.clone()).collect();
for uri in change.uris {
if !document_uris.contains(&uri) {
let absolute_path = Path::new(dir).join(uri.strip_prefix("file:///").unwrap_or(&uri));
std::fs::remove_file(&absolute_path).unwrap();
}
}
for doc in change.documents {
let uri = doc.uri.clone();
let absolute_path = Path::new(dir).join(uri.strip_prefix("file:///").unwrap_or(&uri));
Expand Down

0 comments on commit a723792

Please sign in to comment.