Skip to content

Commit 097dbc8

Browse files
jdelliotfacebook-github-bot
authored andcommitted
Fixed some compat issue with GlobCmd
Summary: # This Diff Fixed some compat issue with GlobCmd # Context We are doing some Oxidation (Python->Rust) migration of the EdenFS CLI. This is an ongoing BE activity that will complete when all CLI commands have been moved. Reviewed By: genevievehelsel Differential Revision: D75334849 fbshipit-source-id: 7c33bb8f5d6f3e196629f5a40f529a9ba6230a59
1 parent 8618778 commit 097dbc8

File tree

1 file changed

+24
-19
lines changed
  • eden/fs/cli_rs/edenfs-commands/src/glob_and_prefetch

1 file changed

+24
-19
lines changed

eden/fs/cli_rs/edenfs-commands/src/glob_and_prefetch/glob.rs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
//! edenfsctl glob
99
10-
use std::path::Path;
1110
use std::path::PathBuf;
1211

1312
use anyhow::Context;
@@ -16,6 +15,7 @@ use async_trait::async_trait;
1615
use clap::Parser;
1716
use edenfs_client::glob_files::Glob;
1817
use edenfs_client::glob_files::dtype_to_str;
18+
use edenfs_client::utils::get_mount_point;
1919
use edenfs_client::utils::locate_repo_root;
2020
use edenfs_utils::path_from_bytes;
2121

@@ -94,36 +94,41 @@ impl crate::Subcommand for GlobCmd {
9494
let instance = get_edenfs_instance();
9595
let client = instance.get_client();
9696

97-
// Get cwd mount_point if not provided.
98-
let current_dir: PathBuf;
99-
let mount_point = match &self.common.mount_point {
100-
Some(ref mount_point) => mount_point,
101-
None => {
102-
current_dir = std::env::current_dir()
103-
.context("Unable to retrieve current working directory")?;
104-
&current_dir
105-
}
106-
};
107-
108-
// Get mount_point as just repo root
109-
let repo_root = locate_repo_root(mount_point);
97+
// Use absolute mount_point if provided (i.e. no search_root) else use
98+
// cwd as mount_point and compute search_root.
99+
let mount_point = get_mount_point(&self.common.mount_point)?;
100+
let mut search_root = PathBuf::new();
110101

111-
// Get relative root (search root)
112-
let repo_root = repo_root.unwrap_or_else(|| Path::new(""));
113-
let search_root = mount_point.strip_prefix(repo_root)?;
102+
// If mount_point is based on cwd - compute search_root
103+
if self.common.mount_point.is_none() {
104+
let cwd = std::env::current_dir()
105+
.with_context(|| "Unable to retrieve current working directory")?;
106+
search_root = cwd.strip_prefix(&mount_point)?.to_path_buf();
107+
} else {
108+
// validate absolute mount_point is point to root
109+
let repo_root =
110+
locate_repo_root(&mount_point).with_context(|| "Unable to locate repo root")?;
111+
if mount_point != repo_root {
112+
eprintln!(
113+
"{} is not the root of an EdenFS repo",
114+
mount_point.display()
115+
);
116+
return Ok(1);
117+
}
118+
}
114119

115120
// Load patterns
116121
let patterns = self.common.load_patterns()?;
117122

118123
let glob = client
119124
.glob_files(
120-
repo_root,
125+
&mount_point,
121126
patterns,
122127
self.common.include_dot_files,
123128
false,
124129
false,
125130
self.dtype,
126-
search_root,
131+
&search_root,
127132
false,
128133
self.common.list_only_files,
129134
)

0 commit comments

Comments
 (0)