Skip to content

Fix lakectl fs rm -r deleting siblings that share the path prefix - #10600

Closed
RyoKusnadi wants to merge 1 commit into
treeverse:masterfrom
RyoKusnadi:fix/lakectl-rm-recursive-keep-siblings
Closed

RyoKusnadi wants to merge 1 commit into
treeverse:masterfrom
RyoKusnadi:fix/lakectl-rm-recursive-keep-siblings

Conversation

@RyoKusnadi

Copy link
Copy Markdown
Contributor

Closes #10582

Change Description

Background

lakectl fs rm -r should delete a folder. fs download -r already adds a trailing / to the path, but fs rm -r didn't.

Bug Fix

  1. Problem - lakectl fs rm -r lakefs://repo/main/logs also deletes logs.txt and logs-archive/3.txt, not just logs/1.txt and logs/2.txt.
    How it happens: run the command with a path that has no trailing slash and another object name starts with the same text.
    Steps: upload logs/1.txt, logs/2.txt, logs.txt, logs-archive/3.txt, then run lakectl fs rm -r lakefs://repo/main/logs.
    Expected: only logs/1.txt and logs/2.txt are deleted. Actual: all four are deleted.
  2. Root cause - cmd/lakectl/cmd/fs_rm.go passed the path unchanged as the list prefix, and the listing matches on a raw string prefix.
  3. Solution - new helper recursiveDeletePrefix adds a trailing / when the path is not empty and doesn't have one. An empty path (whole branch) is unchanged. This matches fs download -r. Fixing it in the one place the prefix is built covers every rm -r call.

Scope: fs ls -r is read-only and left as is, as the issue notes. fs download -r already does this.

Testing Details

Added TestRecursiveDeletePrefix (empty, with and without trailing slash, nested).
Before the fix it doesn't build (undefined: recursiveDeletePrefix); after, it passes.
Ran: go vet and go test ./cmd/lakectl/cmd/ -run 'TestRecursiveDeletePrefix|TestFsRm', gofmt -l, golangci-lint (no findings in the touched files).
Not run: esti system tests or a live lakeFS server, so the four-object steps above were not run end to end.
Environment: fix/lakectl-rm-recursive-keep-siblings @ 94dbbe2, go1.27.1, darwin/arm64.

Breaking Change?

Behavior change: rm -r on a path without / no longer removes siblings that share the prefix. Anyone relying on that would now need to list the sibling paths themselves.

Signed-off-by: Ryo Kusnadi <ryokusnadi@gmail.com>
@github-actions github-actions Bot added area/testing Improvements or additions to tests area/lakectl Issues related to lakeFS' command line interface (lakectl) labels Nov 8, 2026
@RyoKusnadi

Copy link
Copy Markdown
Contributor Author

Closing this for now, happy to reopen if it's useful.

@RyoKusnadi RyoKusnadi closed this Nov 8, 2026
@RyoKusnadi
RyoKusnadi deleted the fix/lakectl-rm-recursive-keep-siblings branch November 8, 2026 13:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/lakectl Issues related to lakeFS' command line interface (lakectl) area/testing Improvements or additions to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: lakectl fs rm -r on a path without a trailing slash also deletes sibling objects that share its name as a prefix

1 participant