Path::parent() returns Some("") for relative paths with a single component. The simplest fix is to just canonicalize the paths first.
So I actually had a few misconceptions about this issue, at first I thought it
was because I was doing bcachefs subvolume create my-subvol within a bind
mount because it worked when I gave the absolute path from the real mount. Then
I thought it was about CString lifetime in FFI, which was also incorrect.
In the end it's pretty simple. The Path::parent() API doesn't take into
account any side effects from the file system or check the real path. It just
works on the bytes of the Path and gives us a slice into the Path.
Path::parent()
returnsSome("")
for relative paths with a single component. The simplest fix is to just canonicalize the paths first.So I actually had a few misconceptions about this issue, at first I thought it was because I was doing
bcachefs subvolume create my-subvol
within a bind mount because it worked when I gave the absolute path from the real mount. Then I thought it was aboutCString
lifetime in FFI, which was also incorrect.In the end it's pretty simple. The
Path::parent()
API doesn't take into account any side effects from the file system or check the real path. It just works on the bytes of thePath
and gives us a slice into thePath
.