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
23 changes: 23 additions & 0 deletions code-rs/core/src/review_coord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ fn state_dir() -> std::io::Result<PathBuf> {
Ok(dir)
}

fn state_dir_path() -> std::io::Result<PathBuf> {
let mut dir = crate::config::find_code_home()?;
dir.push("state");
dir.push("review");
Ok(dir)
}

fn scoped_dir(scope: Option<&Path>) -> std::io::Result<PathBuf> {
let mut dir = state_dir()?;
if let Some(scope) = scope {
Expand All @@ -42,10 +49,26 @@ fn scoped_dir(scope: Option<&Path>) -> std::io::Result<PathBuf> {
Ok(dir)
}

fn scoped_dir_path(scope: Option<&Path>) -> std::io::Result<PathBuf> {
let mut dir = state_dir_path()?;
if let Some(scope) = scope {
let normalized_scope = scope
.canonicalize()
.unwrap_or_else(|_| scope.to_path_buf());
let key = crc32fast::hash(normalized_scope.to_string_lossy().as_bytes());
dir.push(format!("repo-{key:08x}"));
}
Ok(dir)
}

pub fn scoped_review_state_dir(scope: &Path) -> std::io::Result<PathBuf> {
scoped_dir(Some(scope))
}

pub fn scoped_review_state_dir_path(scope: &Path) -> std::io::Result<PathBuf> {
scoped_dir_path(Some(scope))
}

fn epoch_path(scope: Option<&Path>) -> std::io::Result<PathBuf> {
let mut dir = scoped_dir(scope)?;
dir.push(EPOCH_FILENAME);
Expand Down
10 changes: 8 additions & 2 deletions code-rs/core/src/review_store.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::protocol::ReviewOutputEvent;
use crate::review_coord::scoped_review_state_dir;
use crate::review_coord::scoped_review_state_dir_path;
use serde::{Deserialize, Serialize};
use std::collections::BTreeMap;
use std::fs;
Expand Down Expand Up @@ -255,7 +256,7 @@ impl AutoReviewRunStore {
}

pub fn open_existing(scope: &Path) -> io::Result<Option<Self>> {
let root = auto_review_dir(scope)?;
let root = auto_review_dir_path(scope)?;
if !root.exists() {
return Ok(None);
}
Expand Down Expand Up @@ -412,6 +413,10 @@ pub fn auto_review_dir(scope: &Path) -> io::Result<PathBuf> {
Ok(scoped_review_state_dir(scope)?.join(AUTO_REVIEW_DIR))
}

pub fn auto_review_dir_path(scope: &Path) -> io::Result<PathBuf> {
Ok(scoped_review_state_dir_path(scope)?.join(AUTO_REVIEW_DIR))
}

fn read_runs_file(path: &Path) -> io::Result<BTreeMap<Uuid, AutoReviewRun>> {
if !path.exists() {
return Ok(BTreeMap::new());
Expand Down Expand Up @@ -1068,7 +1073,8 @@ mod tests {

let store = AutoReviewRunStore::open_existing(repo.path()).unwrap();
assert!(store.is_none());
assert!(!auto_review_dir(repo.path()).unwrap().exists());
assert!(!auto_review_dir_path(repo.path()).unwrap().exists());
assert!(!code_home.path().join("state").join("review").exists());
}

#[test]
Expand Down