Skip to content

Commit

Permalink
Add changes-since command to eden notify subcommand
Browse files Browse the repository at this point in the history
Summary:
# Context

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

# This Diff

Adds a new command (`changes-since`) to the `eden nofity` subcommand. This command will return all of the changes since the provided position for the given mount.

# Technical Details

Added new module for changes since command that does nothing - yet

# Next Steps

Implement the `changes-since` command to `eden notify` then iterate on the `streamChangesSinceV2` Thrift endpoint.

# Discussion Points

None

Differential Revision: D65774220

fbshipit-source-id: 0ef4005345c5c5f8ab7dd50c599371b259b4ec84
  • Loading branch information
jdelliot authored and facebook-github-bot committed Nov 12, 2024
1 parent b891d3e commit e4baaef
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
3 changes: 3 additions & 0 deletions eden/fs/cli_rs/edenfs-commands/src/notify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use clap::Parser;
use crate::ExitCode;
use crate::Subcommand;

mod changes_since;
mod get_position;

#[derive(Parser, Debug)]
Expand All @@ -26,6 +27,7 @@ pub struct NotifyCmd {
#[derive(Parser, Debug)]
pub enum NotifySubcommand {
GetPosition(get_position::GetPositionCmd),
ChangesSince(changes_since::ChangesSinceCmd),
}

#[async_trait]
Expand All @@ -34,6 +36,7 @@ impl Subcommand for NotifyCmd {
use NotifySubcommand::*;
let sc: &(dyn Subcommand + Send + Sync) = match &self.subcommand {
GetPosition(cmd) => cmd,
ChangesSince(cmd) => cmd,
};
sc.run().await
}
Expand Down
64 changes: 64 additions & 0 deletions eden/fs/cli_rs/edenfs-commands/src/notify/changes_since.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This software may be used and distributed according to the terms of the
* GNU General Public License version 2.
*/

//! edenfsctl notify changes-since

use std::path::PathBuf;

use anyhow::anyhow;
use anyhow::Context;
use anyhow::Result;
use async_trait::async_trait;
use clap::Parser;
use edenfs_client::EdenFsInstance;
use edenfs_utils::bytes_from_path;
use hg_util::path::expand_path;

use crate::util::locate_repo_root;
use crate::ExitCode;

// TODO: add a --json flag to print the output in JSON format
#[derive(Parser, Debug)]
#[clap(about = "Returns the changes since the given EdenFS journal position")]
pub struct ChangesSinceCmd {
#[clap(parse(from_str = expand_path))]
/// Path to the mount point
mount_point: Option<PathBuf>,
}

impl ChangesSinceCmd {
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"))
}
}
}

#[async_trait]
impl crate::Subcommand for ChangesSinceCmd {
#[cfg(not(fbcode_build))]
async fn run(&self) -> Result<ExitCode> {
eprintln!("not supported in non-fbcode build");
Ok(1)
}

#[cfg(fbcode_build)]
async fn run(&self) -> Result<ExitCode> {
let instance = EdenFsInstance::global();
let _client = instance.connect(None).await?;
let mount_point_path = self.get_mount_point()?;
let _mount_point = bytes_from_path(mount_point_path)?;

Ok(0)
}
}

0 comments on commit e4baaef

Please sign in to comment.