fix(alist_v3): set child paths so nested directories resolve - #3019
fix(alist_v3): set child paths so nested directories resolve#3019Elity wants to merge 2 commits into
Conversation
- Set `Path` on every object returned by `List`, matching the OpenList driver. `op.Get` hands a child object straight back to `List`, so a child without a path made the driver request `""` from the upstream server, which answered with its own root: every directory below the mount point served the same listing back, endlessly. - Add tests covering the child paths and a three-level descent. Co-authored-by: Claude <81847+claude@users.noreply.github.com>
There was a problem hiding this comment.
I suggest reducing the test code from 173 lines to around 20–50 lines, or just remove it. There’s no need to introduce an entire fake server just to cover a single line of production code.
There was a problem hiding this comment.
Cut to a single test: 65 lines, 46 of them code. Dropped the second test, the recorder type and the helper funcs, and inlined the driver setup.
I kept the httptest server rather than removing the file. List does its work over HTTP, so there is no seam to exercise it without a server — the alternative here is no test at all. The fake upstream falls back to its own root for unknown paths, which is what makes the loop reproduce; without the one-line fix it fails with:
child of "/drive" has path "", want "/drive/concerts"
Happy to drop the file entirely if you would rather this package stay test-free.
Collapse the two tests into one two-level descent, drop the recorder type and the helper funcs, and inline the driver setup. 173 -> 65 lines. Co-authored-by: Claude <81847+claude@users.noreply.github.com>
248c2d9 to
41736cf
Compare
Summary / 摘要
AListV3.Listnever setPathon the objects it returns.op.Getresolves achild by handing back the object from its parent's listing verbatim, so that
object is what the next
Listreceives asdir— and with an emptyPath, thedriver asked the upstream server for
"".An OpenList/AList server resolves an empty path to its own root, so the request
did not fail; it returned the wrong directory. Every level below the mount point
served the upstream root back, producing an endless self-similar directory: you
click into a folder, get the same listing again, and the breadcrumb grows one
segment each time.
User-visible behavior change:
AList V3mount now open correctly. Previously only themount root worked, because
op.Getbuilds the root object itself fromIRootPathand that one does carry aPath.Implementation change:
Listnow setsPath: path.Join(dir.GetPath(), f.Name)on each returnedobject, which is what
drivers/openlistalready does(
drivers/openlist/driver.go:98).This is a regression from
96cd7143— refactor(op): remove automatic Pathassignment (#1734). That commit removed the block in
op.Listthat used tofill in a child's
Path:on the stated grounds that "Path和Id只在驱动内使用,不应由op.List设置Path", and
migrated the affected drivers to set it themselves.
drivers/alist_v3wasmissed in that migration;
drivers/openlist, which is otherwise a near-identicalfile, was not.
Scope notes:
ListArchivealso returns objects without aPath, butdrivers/openlistbehaves identically there, so it is left untouched.
drivers/alist_v3lacksPassRefreshFlagToUpsteam. That is a featuredifference, not part of this defect.
No configuration, storage format, API or migration behavior is affected.
/ 此 PR 包含破坏性变更。
/ 此 PR 修改了公开 API、配置、存储格式或迁移行为。
/ 此 PR 需要关联仓库同步修改。
Related repository PRs / 关联仓库 PR:
Related Issues / 关联 Issue
Fixes #2077 — reported as "点击任意子目录继续进入时,发现会出现套娃". That issue was
closed after the reporter switched to the
OpenListdriver, but theAList V3driver bug itself was never fixed.
cc @xrgzs — you triaged #2077 and noted that this driver is a copy kept for
newer AList API compatibility, so you are probably the right person to check
that aligning it with
drivers/openlisthere is the intended direction.Testing / 测试
go test ./...go test ./...is not checked because it does not pass onmainin thisenvironment, for reasons unrelated to this change:
go vet's printf analyzer, whichgo testruns by default, fails the buildof
drivers/123,drivers/189,drivers/189pc,drivers/chaoxing,drivers/google_drive,drivers/google_photo,drivers/lanzouand threeinternal/offline_download/*packages withnon-constant format string.drivers/onedrive_sharelink.TestNoRedirectClientUsesSharedSettingspanicswith a nil pointer dereference at
internal/net/serve.go:289, becauseconf.Confis nil outside a booted server.What was run instead:
Manual test: an OpenList v4 instance mounting another OpenList v4 instance over
AList V3. Before the fix, every directory below the mount point returned theupstream server's root. After the fix, a 384-entry directory and its children
list correctly, three levels deep.
Two tests are added in
drivers/alist_v3/driver_test.go:TestListSetsChildPaths— every returned object carriespath.Join(dir.GetPath(), name).TestListDoesNotLoopOnNestedDirectories— descends three levels, feeding eachlisting's object back into
Listthe wayop.Getdoes, and asserts both thelistings and the exact paths the upstream server was asked for.
The fake upstream deliberately falls back to its own root for an unknown path
instead of returning 404, because that is what a real server does. Answering 404
would turn the defect into a loud error and the loop would not reproduce.
Both tests fail on
main:Mutation-checked:
Path: f.Name,Path: dir.GetPath()andPath: ""are eachcaught by the tests.
The new tests install their own
restyclient rather than callingbase.InitClient(), to avoid the same nilconf.Confdereference that makesdrivers/onedrive_sharelinkpanic.Checklist / 检查清单
/ 我已阅读 CONTRIBUTING。
/ 我确认此贡献符合仓库许可证、贡献规范和行为准则。
gofmt,go fmt, orprettierwhere applicable./ 我已按适用情况使用
gofmt、go fmt或prettier格式化变更代码。/ 我已在适用情况下请求相关维护者或代码所有者审查。
AI Disclosure / AI 使用声明
/ 此 PR 包含 AI 辅助内容。
Tools used / 使用工具:
Usage scope / 使用范围:
Code generation / 代码生成
Refactoring / 重构
Documentation / 文档
Tests / 测试
Translation / 翻译
Review assistance / 审查辅助
I have reviewed and validated all AI-assisted content included in this PR.
/ 我已审核并验证此 PR 中的所有 AI 辅助内容。
I have ensured that all AI-assisted commits include
Co-Authored-Byattribution./ 我已确保所有 AI 辅助提交都包含
Co-Authored-By归属信息。I can reproduce all AI-assisted content included in this PR without any AI tools.
/ 我可以在没有任何 AI 工具的情况下重现此 PR 中包含的所有 AI 辅助内容。