You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "PDGGK (via GitHub)" <gi...@apache.org> on 2026/08/20 17:37:15 UTC
[PR] fix(services/b2): resolve stat and copy by exact name, not by prefix [opendal]
PDGGK opened a new pull request, #8124:
URL: https://github.com/apache/opendal/pull/8124
# Which issue does this PR close?
None.
# Rationale for this change
`stat` and `copy` both resolve a path through `get_file_info`, which asks B2 for
a *prefix* listing and then takes whatever came back first:
```rust
// core.rs:486-510
let resp = self
.list_file_names_raw(ctx, Some(path), delimiter, None, None, Operation::Stat)
.await?;
...
if resp.files.is_empty() {
return Err(Error::new(ErrorKind::NotFound, "no such file or directory"));
}
Ok(resp.files.swap_remove(0))
```
The path goes out as `prefix`:
```rust
// core.rs:541-546
if let Some(prefix) = prefix {
let prefix = build_abs_path(&self.root, prefix);
if !prefix.is_empty() {
url = url.push("prefix", &percent_encode_path(&prefix));
}
}
```
`b2_list_file_names` returns every file whose name begins with that prefix, so a
lookup for `abc` also returns `abcd`. Nothing then checks that the entry's name
is the name that was asked for. With only `abcd` in the bucket:
| call | today | expected |
|---|---|---|
| `stat("abc")` | a `FILE` carrying `abcd`'s length, mtime and md5 | `NotFound` |
| `exists("abc")` | `true` | `false` |
| `copy("abc", dst)` | **copies `abcd` to `dst`**, returns `Ok` | `NotFound` |
The copy case is the sharp one. `copy` takes the `file_id` off the same
`get_file_info` result and hands it to `b2_copy_file` as the source:
```rust
// backend.rs:328-334
let file_info = core.get_file_info(&ctx, &from, None).await?;
let source_file_id = file_info.file_id;
```
so it silently copies a different object and reports success.
# What changes are included in this PR?
`get_file_info` now takes the entry whose name matches exactly, and reports
`NotFound` when the prefix listing contains no such entry. The comparison is the
one `lister.rs:99` already makes in this crate:
```rust
build_abs_path(&self.core.root, &start_after) == file.file_name
```
Directory lookups are deliberately left alone. A directory `stat` passes a
delimiter and lists what is *under* the prefix rather than the prefix itself, so
requiring an exact match there would change behaviour on a path I cannot test.
The guard is therefore `if delimiter.is_none()`, which covers file `stat` and
`copy` — the two callers that are wrong today.
# Are there any user-facing changes?
Yes. `stat`, `exists`, `read` and `copy` against a B2 path that is a proper
prefix of another object now return `NotFound` instead of silently resolving to
that other object.
# Note on evidence
The service-side fact this rests on is B2's documented behaviour for
`b2_list_file_names` — `prefix` limits the listing to files whose names start
with it — not on something I observed on a live account. I do not have a B2
bucket and am not claiming to have run this against one.
Everything else is decidable from the tree: the missing name comparison, the two
callers, and the identical comparison already performed in `lister.rs`. The same
class of bug was fixed for sqlite in #8085, where a path was matched as a `LIKE`
pattern instead of an exact prefix.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(services/b2): resolve stat and copy by exact name, not by prefix [opendal]
Posted by "PDGGK (via GitHub)" <gi...@apache.org>.
PDGGK commented on PR #8124:
URL: https://github.com/apache/opendal/pull/8124#issuecomment-5419253108
Good catch, and it is the half I left implicit. `b2_list_file_names` returns names in alphabetical order, and an exact name sorts before every longer name that shares it as a prefix, so the match is always the first entry — it can never be stranded on a page this call did not fetch. That is what makes `limit = None` and B2's default `maxFileCount` irrelevant here, and it is worth stating because without it the open question is whether the failure mode is "wrong file" or "spurious NotFound".
I will fold that into the code comment when I next push. Thanks for checking both arms of the delimiter split independently — the `dir/` reasoning is exactly why I scoped the guard to `delimiter.is_none()` rather than applying it everywhere.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(services/b2): resolve stat and copy by exact name, not by prefix [opendal]
Posted by "PDGGK (via GitHub)" <gi...@apache.org>.
PDGGK commented on PR #8124:
URL: https://github.com/apache/opendal/pull/8124#issuecomment-5419296808
Folded in as `48bb39d` — the ordering argument now sits next to the check rather than only in this thread.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(services/b2): resolve stat and copy by exact name, not by prefix [opendal]
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo closed pull request #8124: fix(services/b2): resolve stat and copy by exact name, not by prefix
URL: https://github.com/apache/opendal/pull/8124
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] fix(services/b2): resolve stat and copy by exact name, not by prefix [opendal]
Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on PR #8124:
URL: https://github.com/apache/opendal/pull/8124#issuecomment-5427303464
It's the expect behavior.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org