diff --git a/crates/turborepo-filewatch/src/cookies.rs b/crates/turborepo-filewatch/src/cookies.rs index 3e75a1773e6d8..3b644b3601556 100644 --- a/crates/turborepo-filewatch/src/cookies.rs +++ b/crates/turborepo-filewatch/src/cookies.rs @@ -68,7 +68,8 @@ pub enum CookieError { /// for a downstream, filewatching-backed service. #[derive(Clone)] pub struct CookieWriter { - root: AbsoluteSystemPathBuf, + // Where we put the cookie files, usually `/.turbo/cookies` + cookie_root: AbsoluteSystemPathBuf, timeout: Duration, cookie_request_sender_lazy: OptionalWatch>>>, @@ -112,7 +113,8 @@ impl Ord for CookiedRequest { /// CookieWatcher is used by downstream filewatching-backed services to /// know when it is safe to handle a particular request. pub(crate) struct CookieWatcher { - root: AbsoluteSystemPathBuf, + // Where we expect to find the cookie files, usually `/.turbo/cookies` + cookie_root: AbsoluteSystemPathBuf, // We don't necessarily get requests in serial-order, but we want to keep them // in order so we don't have to scan all requests every time we get a new cookie. pending_requests: BinaryHeap>, @@ -120,9 +122,9 @@ pub(crate) struct CookieWatcher { } impl CookieWatcher { - pub(crate) fn new(root: AbsoluteSystemPathBuf) -> Self { + pub(crate) fn new(cookie_root: AbsoluteSystemPathBuf) -> Self { Self { - root, + cookie_root, pending_requests: BinaryHeap::new(), latest: 0, } @@ -153,7 +155,7 @@ impl CookieWatcher { if !matches!(event_kind, EventKind::Create(_)) { return None; } - if let Some(serial) = serial_for_path(&self.root, path) { + if let Some(serial) = serial_for_path(&self.cookie_root, path) { self.latest = serial; let mut ready_requests = Vec::new(); while let Some(cookied_request) = self.pending_requests.pop() { @@ -181,15 +183,24 @@ fn serial_for_path(root: &AbsoluteSystemPath, path: &AbsoluteSystemPath) -> Opti } impl CookieWriter { + pub fn new_with_default_cookie_dir( + repo_root: &AbsoluteSystemPath, + timeout: Duration, + recv: OptionalWatch>>, + ) -> Self { + let cookie_root = repo_root.join_components(&[".turbo", "cookies"]); + Self::new(&cookie_root, timeout, recv) + } + pub fn new( - root: &AbsoluteSystemPath, + cookie_root: &AbsoluteSystemPath, timeout: Duration, mut recv: OptionalWatch>>, ) -> Self { let (cookie_request_sender_tx, cookie_request_sender_lazy) = OptionalWatch::new(); let (exit_ch, exit_signal) = mpsc::channel(16); tokio::spawn({ - let root = root.to_owned(); + let root = cookie_root.to_owned(); async move { if recv.get().await.is_err() { // here we need to wait for confirmation that the watching end is ready @@ -213,7 +224,7 @@ impl CookieWriter { } }); Self { - root: root.to_owned(), + cookie_root: cookie_root.to_owned(), timeout, cookie_request_sender_lazy, _exit_ch: exit_ch, @@ -221,7 +232,7 @@ impl CookieWriter { } pub(crate) fn root(&self) -> &AbsoluteSystemPath { - &self.root + &self.cookie_root } /// Sends a request to make a cookie file to the @@ -421,7 +432,7 @@ impl CookiedOptionalWatch { .await? .serial; self.ready(next_id).await; - tracing::debug!("waiting for data"); + tracing::debug!("got cookie, waiting for data"); Ok(self.get_inner().await?) }