CL 661595 added TestRootRemoveDot which fails on Plan 9:
=== RUN TestRootRemoveDot
root_test.go:1845: root.Remove(".") = <nil>, want error
root_test.go:1851: root.Remove(All)?(".") removed the root
--- FAIL: TestRootRemoveDot (0.01s)
@neild, what is the purpose of this test? It appears to be checking that file "." can't be removed, in the context of os.Root
where file dot means the directory opened by OpenRoot
(not the current working directory as one might normally expect).
I can't find anything in the package documentation for Root
that says dot can't be removed. On linux, it seems to be the case as a side effect of the implementation holding an open file descriptor for dot, but on Plan 9 there are no restrictions on deleting an open directory. So it seems to me that this test is checking for an operating system artefact, not checking for correct go behaviour.
CC @golang/plan9.
Comment From: neild
I think the right behavior is for Root.Remove(".")
to return an error on all platforms.
The general guarantee for Root is that operations can't escape the root's directory. We do permit operations that reference the root's directory, such as Root.Open(".")
, but I think that actually removing the root is too surprising.
I'll make a CL to fix it. Sorry for the breakage.
Comment From: millerresearch
I'll make a CL to fix it. Sorry for the breakage
Thank you. Maybe also update the documentation for (Root*).Remove() to clarify that it's forbidden to remove "." ?
Comment From: gopherbot
Change https://go.dev/cl/679377 mentions this issue: os: disallow Root.Remove(".") on Plan 9