koverstreet / bcachefs-tools

http://bcachefs.org
GNU General Public License v2.0
116 stars 88 forks source link

fix(subvol): make cmds work with relative paths #293

Closed tmuehlbacher closed 2 months ago

tmuehlbacher commented 2 months ago

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.