8000 [pull] master from jhspetersson:master by pull[bot] · Pull Request #67 · SINHASantos/fselect · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[pull] master from jhspetersson:master #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 14, 2025
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Find files with SQL-like queries
While it doesn't tend to fully replace traditional `find` and `ls`, **fselect** has these nice features:

* SQL-like (not real SQL, but highly relaxed!) grammar easily understandable by humans
* complex queries
* complex queries, limited subqueries support
* aggregate, statistics, date, and other functions
* search within archives
* `.gitignore`, `.hgignore`, and `.dockerignore` support (experimental)
Expand Down
2 changes: 1 addition & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Subqueries have only limited support.
|----------------------------------------------|------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------|
| `name` | Returns the name (with extension) of the file | |
| `extension` or `ext` | Returns the extension of the file | |
| `path` | Returns the path of the file | |
| `path` | Returns the relative path of the file | |
| `abspath` | Returns the absolute path of the file | |
| `directory` or `dirname` or `dir` | Returns the directory of the file | |
| `absdir` | Returns the absolute directory of the file | |
Expand Down
2 changes: 1 addition & 1 deletion src/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ fields! {

#[text = ["path"]]
@for_archived = true
@description = "Returns the path of the file"
@description = "Returns the relative path of the file"
Path,

#[text = ["abspath"]]
Expand Down
77 changes: 54 additions & 23 deletions src/searcher.rs
EDBE
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ impl<'a> Searcher<'a> {
true,
#[cfg(unix)]
hardlinks,
root_dir,
);
}

Expand Down Expand Up @@ -442,6 +443,7 @@ impl<'a> Searcher<'a> {
self.get_column_expr_value(
None,
&None,
&Path::new(""),
&mut file_map,
Some(f.1),
column_expr
Expand Down Expand Up @@ -520,6 +522,7 @@ impl<'a> Searcher<'a> {
self.get_column_expr_value(
None,
&None,
&Path::new(""),
&mut HashMap::new(),
None,
column_expr
Expand Down Expand Up @@ -612,6 +615,7 @@ impl<'a> Searcher<'a> {
process_queue: bool,
#[cfg(unix)]
hardlinks: bool,
root_dir: &Path,
) -> io::Result<()> {
// Prevents infinite loops when following symlinks
if self.current_follow_symlinks {
Expand Down Expand Up @@ -694,7 +698,7 @@ impl<'a> Searcher<'a> {
// If the path passes the filters, process it
if pass_ignores {
if min_depth == 0 || depth >= min_depth {
let checked = self.check_file(&entry, &None)?;
let checked = self.check_file(&entry, root_dir, &None)?;
if !checked {
return Ok(());
}
Expand All @@ -714,7 +718,7 @@ impl<'a> Searcher<'a> {
if let Ok(afile) = archive.by_index(i) {
let file_info = to_file_info(&afile);
let checked = self
.check_file(&entry, &Some(file_info))?;
.check_file(&entry, root_dir, &Some(file_info))?;
if !checked {
return Ok(());
}
Expand Down Expand Up @@ -768,6 +772,7 @@ impl<'a> Searcher<'a> {
false,
#[cfg(unix)]
hardlinks,
root_dir,
);

if result.is_err() {
Expand Down Expand Up @@ -830,6 +835,7 @@ impl<'a> Searcher<'a> {
false,
#[cfg(unix)]
hardlinks,
root_dir,
);

if result.is_err() {
Expand Down Expand Up @@ -871,6 +877,7 @@ impl<'a> Searcher<'a> {
&mut self,
entry: Option<&DirEntry>,
file_info: &Option<FileInfo>,
root_path: &Path,
file_map: &mut HashMap<String, String>,
buffer_data: Option<&Vec<HashMap<String, String>>>,
column_expr: &Expr,
Expand All @@ -883,14 +890,14 @@ impl<'a> Searcher<'a> {

if let Some(ref _function) = column_expr.function {
let result =
self.get_function_value(entry, file_info, file_map, buffer_data, column_expr);
self.get_function_value(entry, file_info, root_path, file_map, buffer_data, column_expr);
file_map.insert(column_expr_str, result.to_string());
return result;
}

if let Some(ref field) = column_expr.field {
if entry.is_some() {
let result = self.get_field_value(entry.unwrap(), file_info, field);
let result = self.get_field_value(entry.unwrap(), file_info, root_path, field);
file_map.insert(column_expr_str, result.to_string());
return result;
} else if let Some(val) = file_map.get(&field.to_string()) {
Expand All @@ -908,12 +915,12 @@ impl<'a> Searcher<'a> {

if let Some(ref left) = column_expr.left {
let left_result =
self.get_column_expr_value(entry, file_info, file_map, buffer_data, left);
self.get_column_expr_value(entry, file_info, root_path, file_map, buffer_data, left);

if let Some(ref op) = column_expr.arithmetic_op {
if let Some(ref right) = column_expr.right {
let right_result =
self.get_column_expr_value(entry, file_info, file_map, buffer_data, right);
self.get_column_expr_value(entry, file_info, root_path, file_map, buffer_data, right);
result = op.calc(&left_result, &right_result);
file_map.insert(column_expr_str, result.to_string());
} else {
Expand All @@ -933,6 +940,7 @@ impl<'a> Searcher<'a> {
&mut self,
entry: Option<&DirEntry>,
file_info: &Option<FileInfo>,
root_path: &Path,
file_map: &mut HashMap<String, String>,
buffer_data: Option<&Vec<HashMap<String, String>>>,
column_expr: &Expr,
Expand All @@ -948,7 +956,7 @@ impl<'a> Searcher<'a> {
let function = &column_expr.function.as_ref().unwrap();

if function.is_aggregate_function() {
let _ = self.get_column_expr_value(entry, file_info, file_map, buffer_data, left_expr);
let _ = self.get_column_expr_value(entry, file_info, root_path, file_map, buffer_data, left_expr);
let buffer_key = left_expr.to_string();
let aggr_result = function::get_aggregate_value(
&column_expr.function,
Expand All @@ -959,12 +967,12 @@ impl<'a> Searcher<'a> {
Variant::from_string(&aggr_result)
} else {
let function_arg =
self.get_column_expr_value(entry, file_info, file_map, buffer_data, left_expr);
self.get_column_expr_value(entry, file_info, root_path, file_map, buffer_data, left_expr);
let mut function_args = vec![];
if let Some(args) = &column_expr.args {
for arg in args {
let arg_value =
self.get_column_expr_value(entry, file_info, file_map, buffer_data, arg);
self.get_column_expr_value(entry, file_info, root_path, file_map, buffer_data, arg);
function_args.push(arg_value.to_string());
}
}
Expand Down Expand Up @@ -1009,6 +1017,7 @@ impl<'a> Searcher<'a> {
&mut self,
entry: &DirEntry,
file_info: &Option<FileInfo>,
root_path: &Path,
field: &Field,
) -> Variant {
if file_info.is_some() && !field.is_available_for_archived_files() {
Expand Down Expand Up @@ -1046,16 +1055,26 @@ impl<'a> Searcher<'a> {
);
}
},
Field::Path => match file_info {
Field::Path => return match file_info {
Some(file_info) => {
return Variant::from_string(&format!(
Variant::from_st 1E0A ring(&format!(
"[{}] {}",
entry.path().to_string_lossy(),
file_info.name
));
))
}
_ => {
return Variant::from_string(&format!("{}", entry.path().to_string_lossy()));
match entry.path().strip_prefix(root_path) {
Ok(stripped_path) => {
Variant::from_string(&format!(
"{}",
stripped_path.to_string_lossy()
))
}
Err(_) => {
Variant::from_string(&format!("{}", entry.path().to_string_lossy()))
}
}
}
},
Field::AbsPath => match file_info {
Expand Down Expand Up @@ -1896,11 +1915,11 @@ impl<'a> Searcher<'a> {
return Variant::empty(VariantType::String);
}

fn check_file(&mut self, entry: &DirEntry, file_info: &Option<FileInfo>) -> io::Result<bool> {
fn check_file(&mut self, entry: &DirEntry, root_path: &Path, file_info: &Option<FileInfo>) -> io::Result<bool> {
self.fms.clear();

if let Some(ref expr) = self.query.expr {
let result = self.conforms(entry, file_info, expr);
let result = self.conforms(entry, file_info, root_path, expr);
if !result {
return Ok(true);
}
Expand All @@ -1916,7 +1935,7 @@ impl<'a> Searcher<'a> {
for field in self.query.get_all_fields() {
file_map.insert(
field.to_string(),
self.get_field_value(entry, file_info, &field).to_string(),
self.get_field_value(entry, file_info, root_path, &field).to_string(),
);
}

Expand All @@ -1928,7 +1947,7 @@ impl<'a> Searcher<'a> {

for field in self.query.fields.iter() {
let record =
self.get_column_expr_value(Some(entry), file_info, &mut file_map, None, field);
self.get_column_expr_value(Some(entry), file_info, root_path, &mut file_map, None, field);

let value = match self.use_colors && field.contains_colorized() {
true => self.colorize(&record.to_string()),
Expand All @@ -1939,15 +1958,15 @@ impl<'a> Searcher<'a> {

for field in self.query.grouping_fields.iter() {
if file_map.get(&field.to_string()).is_none() {
self.get_column_expr_value(Some(entry), file_info, &mut file_map, None, field);
self.get_column_expr_value(Some(entry), file_info, root_path, &mut file_map, None, field);
}
}

for (idx, field) in self.query.ordering_fields.iter().enumerate() {
criteria[idx] = match file_map.get(&field.to_string()) {
Some(record) => record.clone(),
None => self
.get_column_expr_value(Some(entry), file_info, &mut file_map, None, field)
.get_column_expr_value(Some(entry), file_info, root_path, &mut file_map, None, field)
.to_string(),
}
}
Expand Down Expand Up @@ -2018,15 +2037,15 @@ impl<'a> Searcher<'a> {
Variant::from_bool(false)
}

fn conforms(&mut self, entry: &DirEntry, file_info: &Option<FileInfo>, expr: &Expr) -> bool {
fn conforms(&mut self, entry: &DirEntry, file_info: &Option<FileInfo>, root_path: &Path, expr: &Expr) -> bool {
let mut result = false;

if let Some(ref logical_op) = expr.logical_op {
let mut left_result = false;
let mut right_result = false;

if let Some(ref left) = expr.left {
let left_res = self.conforms(entry, file_info, left);
let left_res = self.conforms(entry, file_info, root_path, left);
left_result = left_res;
}

Expand All @@ -2036,7 +2055,7 @@ impl<'a> Searcher<'a> {
result = false;
} else {
if let Some(ref right) = expr.right {
let right_res = self.conforms(entry, file_info, right);
let right_res = self.conforms(entry, file_info, root_path, right);
right_result = right_res;
}

Expand All @@ -2048,7 +2067,7 @@ impl<'a> Searcher<'a> {
result = true;
} else {
if let Some(ref right) = expr.right {
let right_res = self.conforms(entry, file_info, right);
let right_res = self.conforms(entry, file_info, root_path, right);
right_result = right_res;
}

Expand All @@ -2060,13 +2079,15 @@ impl<'a> Searcher<'a> {
let field_value = self.get_column_expr_value(
Some(entry),
file_info,
root_path,
&mut HashMap::new(),
None,
expr.left.as_ref().unwrap(),
);
let value = self.get_column_expr_value(
Some(entry),
file_info,
root_path,
&mut HashMap::new(),
None,
expr.right.as_ref().unwrap(),
Expand Down Expand Up @@ -2220,6 +2241,7 @@ impl<'a> Searcher<'a> {
for item in args.iter().map(|arg| self.get_column_expr_value(
Some(entry),
file_info,
root_path,
&mut HashMap::new(),
None,
arg,
Expand All @@ -2237,6 +2259,7 @@ impl<'a> Searcher<'a> {
for item in expr.clone().right.unwrap().args.unwrap().iter().map(|arg| self.get_column_expr_value(
Some(entry),
file_info,
root_path,
&mut HashMap::new(),
None,
arg,
Expand Down Expand Up @@ -2281,6 +2304,7 @@ impl<'a> Searcher<'a> {
for item in args.iter().map(|arg| self.get_column_expr_value(
Some(entry),
file_info,
root_path,
&mut HashMap::new(),
None,
arg,
Expand All @@ -2298,6 +2322,7 @@ impl<'a> Searcher<'a> {
for item in expr.clone().right.unwrap().args.unwrap().iter().map(|arg| self.get_column_expr_value(
Some(entry),
file_info,
root_path,
&mut HashMap::new(),
None,
arg,
Expand Down Expand Up @@ -2328,6 +2353,7 @@ impl<'a> Searcher<'a> {
for item in expr.clone().right.unwrap().args.unwrap().iter().map(|arg| self.get_column_expr_value(
Some(entry),
file_info,
root_path,
&mut HashMap::new(),
None,
arg,
Expand All @@ -2345,6 +2371,7 @@ impl<'a> Searcher<'a> {
for item in expr.clone().right.unwrap().args.unwrap().iter().map(|arg| self.get_column_expr_value(
Some(entry),
file_info,
root_path,
&mut HashMap::new(),
None,
arg,
Expand Down Expand Up @@ -2374,6 +2401,7 @@ impl<'a> Searcher<'a> {
for item in expr.clone().right.unwrap().args.unwrap().iter().map(|arg| self.get_column_expr_value(
Some(entry),
file_info,
root_path,
&mut HashMap::new(),
None,
arg,
Expand All @@ -2391,6 +2419,7 @@ impl<'a> Searcher<'a> {
for item in expr.clone().right.unwrap().args.unwrap().iter().map(|arg| self.get_column_expr_value(
Some(entry),
file_info,
root_path,
&mut HashMap::new(),
None,
arg,
Expand Down Expand Up @@ -2425,6 +2454,7 @@ impl<'a> Searcher<'a> {
for item in expr.clone().right.unwrap().args.unwrap().iter().map(|arg| self.get_column_expr_value(
Some(entry),
file_info,
root_path,
&mut HashMap::new(),
None,
arg,
Expand All @@ -2442,6 +2472,7 @@ impl<'a> Searcher<'a> {
for item in expr.clone().right.unwrap().args.unwrap().iter().map(|arg| self.get_column_expr_value(
Some(entry),
file_info,
root_path,
&mut HashMap::new(),
None,
arg,
Expand Down
Loading
0