Skip to content

fix(alist_v3): set child paths so nested directories resolve - #3019

Open
Elity wants to merge 2 commits into
OpenListTeam:mainfrom
Elity:fix/alist-v3-child-path
Open

fix(alist_v3): set child paths so nested directories resolve#3019
Elity wants to merge 2 commits into
OpenListTeam:mainfrom
Elity:fix/alist-v3-child-path

Conversation

@Elity

@Elity Elity commented Sep 1, 2026

Copy link
Copy Markdown

Summary / 摘要

AListV3.List never set Path on the objects it returns. op.Get resolves a
child by handing back the object from its parent's listing verbatim, so that
object is what the next List receives as dir — and with an empty Path, the
driver 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:

  • Subdirectories of an AList V3 mount now open correctly. Previously only the
    mount root worked, because op.Get builds the root object itself from
    IRootPath and that one does carry a Path.

Implementation change:

  • List now sets Path: path.Join(dir.GetPath(), f.Name) on each returned
    object, which is what drivers/openlist already does
    (drivers/openlist/driver.go:98).

This is a regression from 96cd7143refactor(op): remove automatic Path
assignment
(#1734). That commit removed the block in op.List that used to
fill in a child's Path:

- if s, ok := f.(model.SetPath); ok && f.GetPath() == "" && dir.GetPath() != "" {
-     s.SetPath(stdpath.Join(dir.GetPath(), f.GetName()))

on the stated grounds that "Path和Id只在驱动内使用,不应由op.List设置Path", and
migrated the affected drivers to set it themselves. drivers/alist_v3 was
missed in that migration; drivers/openlist, which is otherwise a near-identical
file, was not.

Scope notes:

  • ListArchive also returns objects without a Path, but drivers/openlist
    behaves identically there, so it is left untouched.
  • drivers/alist_v3 lacks PassRefreshFlagToUpsteam. That is a feature
    difference, not part of this defect.

No configuration, storage format, API or migration behavior is affected.

  • This PR has breaking changes.
    / 此 PR 包含破坏性变更。
  • This PR changes public API, config, storage format, or migration behavior.
    / 此 PR 修改了公开 API、配置、存储格式或迁移行为。
  • This PR requires corresponding changes in related repositories.
    / 此 PR 需要关联仓库同步修改。

Related repository PRs / 关联仓库 PR:

  • OpenList-Frontend: N/A
  • OpenList-Docs: N/A

Related Issues / 关联 Issue

Fixes #2077 — reported as "点击任意子目录继续进入时,发现会出现套娃". That issue was
closed after the reporter switched to the OpenList driver, but the AList V3
driver 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/openlist here is the intended direction.

Testing / 测试

  • go test ./...
  • Manual test / 手动测试:

go test ./... is not checked because it does not pass on main in this
environment, for reasons unrelated to this change:

  • go vet's printf analyzer, which go test runs by default, fails the build
    of drivers/123, drivers/189, drivers/189pc, drivers/chaoxing,
    drivers/google_drive, drivers/google_photo, drivers/lanzou and three
    internal/offline_download/* packages with non-constant format string.
  • drivers/onedrive_sharelink.TestNoRedirectClientUsesSharedSettings panics
    with a nil pointer dereference at internal/net/serve.go:289, because
    conf.Conf is nil outside a booted server.

What was run instead:

go build ./...
go vet ./drivers/alist_v3/...
gofmt -l drivers/alist_v3/
go test -race -count=1 ./drivers/alist_v3/...

Manual test: an OpenList v4 instance mounting another OpenList v4 instance over
AList V3. Before the fix, every directory below the mount point returned the
upstream 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 carries
    path.Join(dir.GetPath(), name).
  • TestListDoesNotLoopOnNestedDirectories — descends three levels, feeding each
    listing's object back into List the way op.Get does, and asserts both the
    listings 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:

--- FAIL: TestListSetsChildPaths
    child "concerts" has path "", want "/drive/concerts"
--- FAIL: TestListDoesNotLoopOnNestedDirectories
    listing under "/drive/concerts" is [drive public], want [live-in-tokyo]

Mutation-checked: Path: f.Name, Path: dir.GetPath() and Path: "" are each
caught by the tests.

The new tests install their own resty client rather than calling
base.InitClient(), to avoid the same nil conf.Conf dereference that makes
drivers/onedrive_sharelink panic.

Checklist / 检查清单

  • I have read CONTRIBUTING.
    / 我已阅读 CONTRIBUTING
  • I confirm this contribution follows the repository license, contribution policy, and code of conduct.
    / 我确认此贡献符合仓库许可证、贡献规范和行为准则。
  • I have formatted the changed code with gofmt, go fmt, or prettier where applicable.
    / 我已按适用情况使用 gofmtgo fmtprettier 格式化变更代码。
  • I have requested review from relevant maintainers or code owners where applicable.
    / 我已在适用情况下请求相关维护者或代码所有者审查。

AI Disclosure / AI 使用声明

  • This PR includes AI-assisted content.
    / 此 PR 包含 AI 辅助内容。

Tools used / 使用工具:

  • ChatGPT
  • Codex
  • GitHub Copilot
  • Claude
  • Gemini
  • Other (please specify) / 其他(请注明):

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-By attribution.
    / 我已确保所有 AI 辅助提交都包含 Co-Authored-By 归属信息。

  • I can reproduce all AI-assisted content included in this PR without any AI tools.
    / 我可以在没有任何 AI 工具的情况下重现此 PR 中包含的所有 AI 辅助内容。

- 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>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@Elity
Elity force-pushed the fix/alist-v3-child-path branch from 248c2d9 to 41736cf Compare September 2, 2026 04:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Alist v3驱动挂载无法访问

2 participants