mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-23 01:08:28 +02:00
Ensure fs_sync always writes to current state's path (even if Yaak changes the default)
This commit is contained in:
@@ -15,9 +15,9 @@ use ts_rs::TS;
|
|||||||
use yaak_models::models::{SyncState, Workspace};
|
use yaak_models::models::{SyncState, Workspace};
|
||||||
use yaak_models::queries::{
|
use yaak_models::queries::{
|
||||||
delete_environment, delete_folder, delete_grpc_request, delete_http_request, delete_sync_state,
|
delete_environment, delete_folder, delete_grpc_request, delete_http_request, delete_sync_state,
|
||||||
delete_workspace, get_workspace_export_resources,
|
delete_workspace, get_workspace_export_resources, list_sync_states_for_workspace,
|
||||||
list_sync_states_for_workspace, upsert_environment, upsert_folder, upsert_grpc_request,
|
upsert_environment, upsert_folder, upsert_grpc_request, upsert_http_request, upsert_sync_state,
|
||||||
upsert_http_request, upsert_sync_state, upsert_workspace, UpdateSource,
|
upsert_workspace, UpdateSource,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
|
#[derive(Debug, Clone, Serialize, Deserialize, TS)]
|
||||||
@@ -129,11 +129,11 @@ pub(crate) async fn get_db_candidates<R: Runtime>(
|
|||||||
|
|
||||||
// 2. Add SyncState-only candidates (deleted)
|
// 2. Add SyncState-only candidates (deleted)
|
||||||
candidates.extend(sync_states.values().filter_map(|sync_state| {
|
candidates.extend(sync_states.values().filter_map(|sync_state| {
|
||||||
let already_added = models.contains_key(&sync_state.model_id);
|
if models.contains_key(&sync_state.model_id) {
|
||||||
if already_added {
|
None
|
||||||
return None;
|
} else {
|
||||||
|
Some(DbCandidate::Deleted(sync_state.to_owned()))
|
||||||
}
|
}
|
||||||
Some(DbCandidate::Deleted(sync_state.to_owned()))
|
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Ok(candidates)
|
Ok(candidates)
|
||||||
@@ -351,15 +351,16 @@ async fn apply_sync_op<R: Runtime>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
SyncOp::FsUpdate { model, state } => {
|
SyncOp::FsUpdate { model, state } => {
|
||||||
let rel_path = derive_model_filename(&model);
|
// Always write the existing path
|
||||||
let abs_path = derive_full_model_path(workspace, &model)?;
|
let rel_path = Path::new(&state.rel_path);
|
||||||
|
let abs_path = Path::new(&state.sync_dir).join(&rel_path);
|
||||||
let (content, checksum) = model.to_file_contents(&rel_path)?;
|
let (content, checksum) = model.to_file_contents(&rel_path)?;
|
||||||
let mut f = File::create(&abs_path).await?;
|
let mut f = File::create(&abs_path).await?;
|
||||||
f.write_all(&content).await?;
|
f.write_all(&content).await?;
|
||||||
SyncStateOp::Update {
|
SyncStateOp::Update {
|
||||||
state: state.to_owned(),
|
state: state.to_owned(),
|
||||||
checksum,
|
checksum,
|
||||||
rel_path,
|
rel_path: rel_path.to_owned(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SyncOp::FsDelete {
|
SyncOp::FsDelete {
|
||||||
@@ -369,8 +370,10 @@ async fn apply_sync_op<R: Runtime>(
|
|||||||
None => SyncStateOp::Delete {
|
None => SyncStateOp::Delete {
|
||||||
state: state.to_owned(),
|
state: state.to_owned(),
|
||||||
},
|
},
|
||||||
Some(fs_candidate) => {
|
Some(_) => {
|
||||||
let abs_path = derive_full_model_path(workspace, &fs_candidate.model)?;
|
// Always delete the existing path
|
||||||
|
let rel_path = Path::new(&state.rel_path);
|
||||||
|
let abs_path = Path::new(&state.sync_dir).join(&rel_path);
|
||||||
fs::remove_file(&abs_path).await?;
|
fs::remove_file(&abs_path).await?;
|
||||||
SyncStateOp::Delete {
|
SyncStateOp::Delete {
|
||||||
state: state.to_owned(),
|
state: state.to_owned(),
|
||||||
@@ -474,7 +477,7 @@ fn derive_full_model_path(workspace: &Workspace, m: &SyncModel) -> Result<PathBu
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn derive_model_filename(m: &SyncModel) -> PathBuf {
|
fn derive_model_filename(m: &SyncModel) -> PathBuf {
|
||||||
let rel = format!("{}.yaml", m.id());
|
let rel = format!("yaak.2.{}.yaml", m.id());
|
||||||
let rel = Path::new(&rel).to_path_buf();
|
let rel = Path::new(&rel).to_path_buf();
|
||||||
|
|
||||||
// Ensure parent dir exists
|
// Ensure parent dir exists
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export function useSyncWorkspace(
|
|||||||
} = {},
|
} = {},
|
||||||
) {
|
) {
|
||||||
const sync = useCallback(async () => {
|
const sync = useCallback(async () => {
|
||||||
if (workspace == null || workspace.settingSyncDir) return;
|
if (workspace == null || !workspace.settingSyncDir) return;
|
||||||
|
|
||||||
const ops = await calculateSync(workspace) ?? [];
|
const ops = await calculateSync(workspace) ?? [];
|
||||||
if (ops.length === 0) {
|
if (ops.length === 0) {
|
||||||
@@ -31,6 +31,8 @@ export function useSyncWorkspace(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("Filesystem changes detected", dbChanges);
|
||||||
|
|
||||||
const confirmed = await showConfirm({
|
const confirmed = await showConfirm({
|
||||||
id: 'commit-sync',
|
id: 'commit-sync',
|
||||||
title: 'Filesystem Changes Detected',
|
title: 'Filesystem Changes Detected',
|
||||||
|
|||||||
@@ -29,8 +29,6 @@ async function sync() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('Syncing model stores', args);
|
|
||||||
|
|
||||||
// Set the things we need first, first
|
// Set the things we need first, first
|
||||||
jotaiStore.set(httpRequestsAtom, await invokeCmd('cmd_list_http_requests', args));
|
jotaiStore.set(httpRequestsAtom, await invokeCmd('cmd_list_http_requests', args));
|
||||||
jotaiStore.set(grpcRequestsAtom, await invokeCmd('cmd_list_grpc_requests', args));
|
jotaiStore.set(grpcRequestsAtom, await invokeCmd('cmd_list_grpc_requests', args));
|
||||||
|
|||||||
Reference in New Issue
Block a user