Skip to content
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
1 change: 1 addition & 0 deletions agents/reference/product-principles.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Path globbing matches `bash -O globstar` with `dotglob` off, exactly. That is th
- `'./'` and a named directory list one level.
- `node_modules` is skipped unless the path names it.
- Files only; no directory rows.
- A folder that exists but cannot be listed is an error, not an empty folder.

To check a glob change, compare its output with `bash -O globstar -O nullglob` on the same tree. A divergence with no written reason is a bug.

Expand Down
1 change: 1 addition & 0 deletions docs/reference/glob.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ A test runs every row against dirsql as a path-table and, with the leading
| `gitignore` | Inside a git repo, `.gitignore` files hide files and directories a wildcard matches, never one the pattern spells out. `--no-ignore` turns it off. | A query over a repo should not drown in build output. |
| `directory-name` | A pattern's last component that names a directory lists the files directly inside it, like `ls docs`. A trailing `/` is `*` appended. | A table is rows of files, and `ls` is the shell habit. |
| `files-only` | A pattern that matches a directory but no file returns nothing. | Every row is a file. |
| `unlistable` | A folder the pattern reaches that exists but cannot be listed is an error naming it: a config table fails its build and a parsed path-table its query. Bash skips it silently. A folder that does not exist still holds nothing. | An empty result that is really a failed read looks like a true answer. |

`.git` needs no rule of its own: the dotfile rule hides it.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"command": "uv run python -m pytest tests/e2e/on_file_query_test.py tests/e2e/on_file_failure_test.py tests/e2e/query_contract_test.py tests/e2e/glob_speed_recursive_test.py tests/e2e/glob_speed_symlink_test.py tests/e2e/many_dirs_speed_test.py tests/e2e/parent_then_child_test.py -x -q",
"ran_at": 1795021146,
"exit_code": 0,
"commit": "57438a24cfe8bee2dfe32f8258722fc028c2e34c",
"branch": "bot/1740-unlistable-folder-fails-1118"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
**Changed**

- **A folder a glob reaches that exists but cannot be listed is now an error naming it, for config tables and parsed path-tables.** A config table's build fails, and so does a query over a parsed path-table (one read through `--on-file`), with `cannot list folder '<path>': <reason>`. Before, the folder was read as empty and the result came back short with exit status 0. A folder that does not exist still holds nothing. Bash skips such a folder silently, so this is a listed divergence from bash. `scanner::scan_directory_reporting`, `scanner::scan_glob` and `scanner::scan_glob_checking_root` now return `Result<_, scanner::UnlistableFolder>`.
32 changes: 32 additions & 0 deletions packages/rust/migrations.d/2026-11-18-unlistable-folder-fails.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
### A folder that cannot be listed fails config tables and parsed path-tables

#### Summary

A folder a glob reaches that exists but cannot be listed (its open fails, or a read fails part-way) used to be read as empty. It now fails a config table's build and a parsed path-table's query with an error naming the folder; the CLI exits non-zero and the SDKs raise. A missing folder still holds nothing. Three public Rust scanner functions now return a `Result`.

#### Required changes

| Surface | Before | After |
| --- | --- | --- |
| `dirsql::scanner::scan_directory_reporting` | returns `Vec<Found>` | returns `Result<Vec<Found>, UnlistableFolder>` |
| `dirsql::scanner::scan_glob` | returns `Vec<PathBuf>` | returns `Result<Vec<PathBuf>, UnlistableFolder>` |
| `dirsql::scanner::scan_glob_checking_root` | returns `Vec<PathBuf>` | returns `Result<Vec<PathBuf>, UnlistableFolder>` |

#### Deprecations removed

_None._

#### Behavior changes without code changes

`DirSQL::builder().build()` over a config table, and `query` over a parsed path-table, fail with `cannot list folder '<path>': <reason>` where they used to return the rows of every other folder. In the Rust SDK the build error is `DirSqlError::Io` carrying the OS error kind; the query error is a SQLite module error.

#### Verification

```bash
mkdir -p data/open data/locked
echo '{"k":1}' > data/open/a.ndjson
chmod 311 data/locked
dirsql --on-file cat "SELECT * FROM './data/**/*.ndjson'"
```

Expected (as a non-root user): exit status 1 and an error containing `cannot list folder` and `data/locked`.
96 changes: 78 additions & 18 deletions packages/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ use crate::persist::{
resolve_persist_path, upsert_file, write_meta,
};
use crate::progress::Progress;
use crate::scanner::{Found, scan_directory_reporting};
use crate::scanner::{Found, UnlistableFolder, scan_directory_reporting};
use crate::watcher::{FileEvent, WatchFault, WatchScope, Watcher};
use futures_channel::mpsc::{UnboundedReceiver, UnboundedSender, unbounded};
use std::collections::{BTreeMap, HashMap, HashSet};
Expand Down Expand Up @@ -702,7 +702,7 @@ type ScanFn<'a> = &'a dyn Fn(
&mut dyn FnMut(u64),
&mut dyn FnMut(&Path, &str),
&(dyn Fn(&Path) + Sync),
) -> Vec<Found>;
) -> std::result::Result<Vec<Found>, UnlistableFolder>;

impl DirSQL {
/// Start building a `DirSQL`. See [`DirSQLBuilder`] for the available
Expand Down Expand Up @@ -2032,7 +2032,7 @@ impl DirSQL {
// The walk reports a running count rather than a fraction: it does
// not know how many files there are until it has found them all.
let mut progress = Progress::scanning();
let (scanned, seen) = scan_groups(
let scanned = scan_groups(
&groups,
scan,
&mut progress,
Expand All @@ -2049,6 +2049,7 @@ impl DirSQL {
},
);
drop(feeds);
let (scanned, seen) = scanned.map_err(std::io::Error::from)?;
progress.finish(seen);
for warning in empty_table_warnings(&tables, &anchors, &scanned) {
eprintln!("{warning}");
Expand Down Expand Up @@ -2979,7 +2980,7 @@ fn scan_groups(
progress: &mut Progress,
on_match: &mut dyn FnMut(&Path, &str),
on_link: &(dyn Fn(&Path) + Sync),
) -> (Vec<Found>, u64) {
) -> std::result::Result<(Vec<Found>, u64), UnlistableFolder> {
let mut seen = 0;
let mut scanned = Vec::new();
for group in groups {
Expand All @@ -2993,9 +2994,9 @@ fn scan_groups(
},
on_match,
on_link,
));
)?);
}
(scanned, seen)
Ok((scanned, seen))
}

fn compile_groups(
Expand Down Expand Up @@ -4198,12 +4199,12 @@ mod internal_tests {
_matcher: &TableMatcher,
on_file: &mut dyn FnMut(u64),
_on_match: &mut dyn FnMut(&Path, &str),
) -> Vec<Found> {
) -> std::result::Result<Vec<Found>, UnlistableFolder> {
self.calls.set(self.calls.get() + 1);
for (index, _) in self.found.iter().enumerate() {
on_file(index as u64 + 1);
}
self.found.clone()
Ok(self.found.clone())
}
}

Expand Down Expand Up @@ -4250,7 +4251,7 @@ mod internal_tests {
wait_for_db.recv_timeout(Duration::from_secs(5)).is_ok(),
"database creation must finish before the scan completes"
);
Vec::new()
Ok(Vec::new())
};
let new_db = move || {
wait_for_scan.recv_timeout(Duration::from_secs(5)).unwrap();
Expand Down Expand Up @@ -4285,7 +4286,7 @@ mod internal_tests {
wait_for_ddl.recv_timeout(Duration::from_secs(5)).is_ok(),
"table DDL must finish before the scan completes"
);
Vec::new()
Ok(Vec::new())
};
let ddl = move |db: &Db, tables: &[Table]| {
wait_for_scan.recv_timeout(Duration::from_secs(5)).unwrap();
Expand Down Expand Up @@ -4319,7 +4320,7 @@ mod internal_tests {
let called = Arc::clone(&ddl_called);
let prepared = DirSQL::prepare_resolved_with_setup(
resolved,
&|_, _, _, _, _| Vec::new(),
&|_, _, _, _, _| Ok(Vec::new()),
Db::new,
move |_, _| {
called.store(true, Ordering::SeqCst);
Expand Down Expand Up @@ -4392,7 +4393,7 @@ mod internal_tests {
let called = Arc::clone(&ddl_called);
let prepared = DirSQL::prepare_resolved_with_setup(
resolved,
&|_, _, _, _, _| Vec::new(),
&|_, _, _, _, _| Ok(Vec::new()),
Db::new,
move |_, _| {
called.store(true, Ordering::SeqCst);
Expand Down Expand Up @@ -4529,11 +4530,11 @@ mod internal_tests {
.recv_timeout(std::time::Duration::from_secs(5))
.is_ok(),
);
vec![Found {
Ok(vec![Found {
path: found.clone(),
rel_path: "a.txt".into(),
table_name: "items".into(),
}]
}])
})
.unwrap();
assert!(hook_saw_it_mid_walk.get());
Expand All @@ -4549,7 +4550,7 @@ mod internal_tests {
resolved.no_ignore = no_ignore;
DirSQL::prepare_resolved_with(resolved, &|_, matcher, _, _, _| {
honored.set(Some(matcher.respects_gitignore()));
Vec::new()
Ok(Vec::new())
})
.unwrap();
assert_eq!(honored.get(), Some(!no_ignore));
Expand Down Expand Up @@ -5085,7 +5086,7 @@ mod internal_tests {
_: &mut dyn FnMut(&Path, &str),
_: &(dyn Fn(&Path) + Sync)| {
report(3);
vec![found_at(anchor, &anchor.join("f.txt"), "t")]
Ok(vec![found_at(anchor, &anchor.join("f.txt"), "t")])
};

let (scanned, seen) = scan_groups(
Expand All @@ -5094,12 +5095,71 @@ mod internal_tests {
&mut Progress::scanning(),
&mut |_, _| {},
&|_| {},
);
)
.unwrap();

assert_eq!(seen, 6);
assert_eq!(scanned.len(), 2);
}

#[test]
fn scan_groups_fails_on_a_folder_a_scan_could_not_list() {
let tables = vec![
anchored_table("a", "*.txt", "/one"),
anchored_table("b", "*.txt", "/two"),
];
let (groups, _, _) = compile_groups(&tables, &[], Path::new("/idx")).unwrap();
let scan = |anchor: &Path,
_: &TableMatcher,
_: &mut dyn FnMut(u64),
_: &mut dyn FnMut(&Path, &str),
_: &(dyn Fn(&Path) + Sync)| {
if anchor.ends_with("two") {
return Err(unlistable(anchor));
}
Ok(vec![found_at(anchor, &anchor.join("f.txt"), "t")])
};

let failed = scan_groups(
&groups,
&scan,
&mut Progress::scanning(),
&mut |_, _| {},
&|_| {},
)
.unwrap_err();

assert!(failed.path.ends_with("two"), "{failed}");
}

fn unlistable(path: &Path) -> UnlistableFolder {
UnlistableFolder {
path: path.to_path_buf(),
source: std::io::Error::from(std::io::ErrorKind::PermissionDenied),
}
}

#[test]
fn a_build_fails_naming_a_folder_its_scan_could_not_list() {
let dir = TempDir::new().unwrap();
let locked = dir.path().join("locked");
let failed = DirSQL::prepare_resolved_with(
resolved_over(dir.path(), vec![txt_table()], false),
&|_, _, _, _, _| Err(unlistable(&locked)),
)
.err()
.unwrap();

let DirSqlError::Io(io) = &failed else {
panic!("not an io error: {failed:?}");
};
assert_eq!(io.kind(), std::io::ErrorKind::PermissionDenied);
assert!(
failed.to_string().contains(&locked.display().to_string()),
"{failed}"
);
}

#[test]
fn delete_subtree_surfaces_db_poison() {
let (_dir, db, _abs, _rel) = upsert_fixture();
Expand Down Expand Up @@ -9359,7 +9419,7 @@ mod internal_tests {
let link = dir.path().join("link");
let prepared = DirSQL::prepare_resolved_with(resolved, &|_, _, _, _, on_link| {
on_link(&link);
Vec::new()
Ok(Vec::new())
})
.unwrap();
assert_eq!(prepared.links, vec![link.clone()]);
Expand Down
Loading
Loading