Skip to content

Commit

Permalink
Move get_mount_point logic into edenfs-client, stub out wait and subs…
Browse files Browse the repository at this point in the history
…cribe common path

Summary:
# Context

We are introducing EdenFS notifications to support scalable and ergonomic file system notifications for EdenFS mounts.

# This Diff
This diff implements some setup for the subscribe functionality

# Technical Details
get_mount_point, which looks up the current mount point if not provided, is moved to edenfs-client. Some processing for OS specific handling has been copied over from debug subscribe

# Discussion Points
Other functions, such as get-position, are just using bytes_from_path(mount_point_path) rather than doing OS specific conversions. Should this be a concern?

Reviewed By: jdelliot

Differential Revision: D68588494

fbshipit-source-id: e5bb8fe7a96d297da6e7e0cd133c97025cc0acee
  • Loading branch information
Chris Dinh authored and facebook-github-bot committed Jan 28, 2025
1 parent 70c0129 commit f32d47d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 26 deletions.
20 changes: 2 additions & 18 deletions eden/fs/cli_rs/edenfs-commands/src/debug/subscribe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ use std::path::Path;
use std::path::PathBuf;
use std::sync::Arc;

use anyhow::anyhow;
use anyhow::Context;
use anyhow::Result;
use async_trait::async_trait;
use clap::Parser;
use edenfs_client::types::JournalPosition;
use edenfs_client::utils::locate_repo_root;
use edenfs_client::utils::get_mount_point;
use edenfs_client::EdenFsInstance;
use hg_util::path::expand_path;
use serde::Serialize;
Expand Down Expand Up @@ -151,20 +149,6 @@ pub struct SubscribeCmd {
guard: u64,
}

impl SubscribeCmd {
fn get_mount_point(&self) -> Result<PathBuf> {
if let Some(path) = &self.mount_point {
Ok(path.clone())
} else {
locate_repo_root(
&std::env::current_dir().context("Unable to retrieve current working directory")?,
)
.map(|p| p.to_path_buf())
.ok_or_else(|| anyhow!("Unable to locate repository root"))
}
}
}

fn have_non_hg_changes(changes: &[edenfs_thrift::PathString]) -> bool {
changes.iter().any(|f| !f.starts_with(b".hg"))
}
Expand Down Expand Up @@ -273,7 +257,7 @@ impl crate::Subcommand for SubscribeCmd {
async fn run(&self) -> Result<ExitCode> {
let instance = EdenFsInstance::global();

let mount_point_path = self.get_mount_point()?;
let mount_point_path = get_mount_point(&self.mount_point)?;
#[cfg(unix)]
let mount_point = <Path as AsRef<OsStr>>::as_ref(&mount_point_path)
.to_os_string()
Expand Down
17 changes: 9 additions & 8 deletions eden/fs/cli_rs/edenfs-commands/src/notify/changes_since.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,11 @@ impl crate::Subcommand for ChangesSinceCmd {
#[cfg(fbcode_build)]
async fn run(&self) -> Result<ExitCode> {
let instance = EdenFsInstance::global();
let position = match &self.position {
Some(result) => result.clone(),
None => {
instance
.get_journal_position(&self.mount_point, None)
.await?
}
};
let position = self.position.clone().unwrap_or(
instance
.get_journal_position(&self.mount_point, None)
.await?,
);
let result = instance
.get_changes_since(
&self.mount_point,
Expand All @@ -112,6 +109,10 @@ impl crate::Subcommand for ChangesSinceCmd {
result.to_string()
}
);

if self.subscribe {
println!("Getting changes since {}", result.to_position);
}
Ok(0)
}
}

0 comments on commit f32d47d

Please sign in to comment.