-
Notifications
You must be signed in to change notification settings - Fork 1
refactor(flowctl): merge 4 crates into 2 (core + cli) #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -599,21 +599,21 @@ pub fn cmd_lock(json: bool, task: String, files: String, mode: String) { | |||||||||||||||||||||||||||||||
| error_exit("No files specified for locking."); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| let store = flowctl_db::FlowStore::new(flow_dir); | ||||||||||||||||||||||||||||||||
| let lock_store = store.locks(); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| let mut locked = Vec::new(); | ||||||||||||||||||||||||||||||||
| let mut already_locked = Vec::new(); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| for file in &file_list { | ||||||||||||||||||||||||||||||||
| match lock_store.acquire(file, &task, &mode) { | ||||||||||||||||||||||||||||||||
| Ok(()) => locked.push(file.to_string()), | ||||||||||||||||||||||||||||||||
| Err(flowctl_db::DbError::Constraint(msg)) => { | ||||||||||||||||||||||||||||||||
| let holder = lock_store.check(file).ok().flatten().unwrap_or_default(); | ||||||||||||||||||||||||||||||||
| already_locked.push(json!({"file": file, "owners": [format!("{}({mode})", holder)], "detail": msg})); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| Err(e) => { | ||||||||||||||||||||||||||||||||
| error_exit(&format!("Failed to lock {}: {}", file, e)); | ||||||||||||||||||||||||||||||||
| // Check for conflict: another task holding the file. | ||||||||||||||||||||||||||||||||
| let locks = flowctl_core::json_store::locks_read(&flow_dir).unwrap_or_default(); | ||||||||||||||||||||||||||||||||
| let conflict = locks.iter().find(|l| l.file_path == *file && l.task_id != task); | ||||||||||||||||||||||||||||||||
| if let Some(holder) = conflict { | ||||||||||||||||||||||||||||||||
| already_locked.push(json!({"file": file, "owners": [format!("{}({mode})", holder.task_id)], "detail": format!("file '{}' already locked by task '{}'", file, holder.task_id)})); | ||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||
| match flowctl_core::json_store::lock_acquire(&flow_dir, file, &task, &mode) { | ||||||||||||||||||||||||||||||||
| Ok(()) => locked.push(file.to_string()), | ||||||||||||||||||||||||||||||||
|
Comment on lines
605
to
+613
|
||||||||||||||||||||||||||||||||
| Err(e) => { | ||||||||||||||||||||||||||||||||
| error_exit(&format!("Failed to lock {}: {}", file, e)); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
@@ -641,11 +641,8 @@ pub fn cmd_lock(json: bool, task: String, files: String, mode: String) { | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| pub fn cmd_unlock(json: bool, task: Option<String>, _files: Option<String>, all: bool) { | ||||||||||||||||||||||||||||||||
| let flow_dir = ensure_flow_exists(); | ||||||||||||||||||||||||||||||||
| let store = flowctl_db::FlowStore::new(flow_dir); | ||||||||||||||||||||||||||||||||
| let lock_store = store.locks(); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| if all { | ||||||||||||||||||||||||||||||||
| match lock_store.release_all() { | ||||||||||||||||||||||||||||||||
| match flowctl_core::json_store::locks_clear(&flow_dir) { | ||||||||||||||||||||||||||||||||
| Ok(count) => { | ||||||||||||||||||||||||||||||||
| if json { | ||||||||||||||||||||||||||||||||
| json_output(json!({ | ||||||||||||||||||||||||||||||||
|
|
@@ -668,7 +665,7 @@ pub fn cmd_unlock(json: bool, task: Option<String>, _files: Option<String>, all: | |||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| match lock_store.release_for_task(&task_id) { | ||||||||||||||||||||||||||||||||
| match flowctl_core::json_store::lock_release_task(&flow_dir, &task_id) { | ||||||||||||||||||||||||||||||||
| Ok(count) => { | ||||||||||||||||||||||||||||||||
| if json { | ||||||||||||||||||||||||||||||||
| json_output(json!({ | ||||||||||||||||||||||||||||||||
|
|
@@ -686,39 +683,31 @@ pub fn cmd_unlock(json: bool, task: Option<String>, _files: Option<String>, all: | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| pub fn cmd_lock_check(json: bool, file: Option<String>) { | ||||||||||||||||||||||||||||||||
| let flow_dir = ensure_flow_exists(); | ||||||||||||||||||||||||||||||||
| let store = flowctl_db::FlowStore::new(flow_dir); | ||||||||||||||||||||||||||||||||
| let lock_store = store.locks(); | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| match file { | ||||||||||||||||||||||||||||||||
| Some(f) => { | ||||||||||||||||||||||||||||||||
| match lock_store.check(&f) { | ||||||||||||||||||||||||||||||||
| Ok(Some(task_id)) => { | ||||||||||||||||||||||||||||||||
| if json { | ||||||||||||||||||||||||||||||||
| json_output(json!({ | ||||||||||||||||||||||||||||||||
| "file": f, | ||||||||||||||||||||||||||||||||
| "locked": true, | ||||||||||||||||||||||||||||||||
| "locks": [{"task_id": task_id, "mode": "write"}], | ||||||||||||||||||||||||||||||||
| })); | ||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||
| println!("{}: locked by {}", f, task_id); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| Ok(None) => { | ||||||||||||||||||||||||||||||||
| if json { | ||||||||||||||||||||||||||||||||
| json_output(json!({ | ||||||||||||||||||||||||||||||||
| "file": f, | ||||||||||||||||||||||||||||||||
| "locked": false, | ||||||||||||||||||||||||||||||||
| })); | ||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||
| println!("{}: not locked", f); | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| let locks = flowctl_core::json_store::locks_read(&flow_dir).unwrap_or_default(); | ||||||||||||||||||||||||||||||||
| let holder = locks.iter().find(|l| l.file_path == f).map(|l| l.task_id.clone()); | ||||||||||||||||||||||||||||||||
| if let Some(task_id) = holder { | ||||||||||||||||||||||||||||||||
| if json { | ||||||||||||||||||||||||||||||||
| json_output(json!({ | ||||||||||||||||||||||||||||||||
| "file": f, | ||||||||||||||||||||||||||||||||
| "locked": true, | ||||||||||||||||||||||||||||||||
| "locks": [{"task_id": task_id, "mode": "write"}], | ||||||||||||||||||||||||||||||||
|
Comment on lines
+689
to
+695
|
||||||||||||||||||||||||||||||||
| let holder = locks.iter().find(|l| l.file_path == f).map(|l| l.task_id.clone()); | |
| if let Some(task_id) = holder { | |
| if json { | |
| json_output(json!({ | |
| "file": f, | |
| "locked": true, | |
| "locks": [{"task_id": task_id, "mode": "write"}], | |
| let holder = locks.iter().find(|l| l.file_path == f); | |
| if let Some(lock) = holder { | |
| let task_id = lock.task_id.clone(); | |
| if json { | |
| json_output(json!({ | |
| "file": f, | |
| "locked": true, | |
| "locks": [{"task_id": task_id, "mode": lock.mode.clone()}], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When reporting an already-locked conflict, the code formats the owner as
holder.task_idwith the requested{mode}rather than the actual mode stored in the existing lock entry. This can misreport the current lock state; useholder.mode(and/or include it in the detail string) instead of the input mode.