Open codeaholics opened 4 years ago
Thanks for the PR! Do posix systems all place mv under /bin
? Is it better to use the abs path rather than do a PATH
lookup?
I believe so, yes. I was surprised not to find it in /sbin
. I guess we could do a path search, but that would be a lot more effort for what I don't believe would be a huge gain.
I appreciate this is likely to be controversial, so I understand if you don't want to merge it.
This commit adds a new
mv
action (--action
). It simply execs/bin/mv
.The reason for this is that on BTRFS subvolumes (which my NAS uses), the Go
os.Rename()
call returns "invalid cross-device link", so themove()
function falls back to making a new copy of the file and then deleting the original.However, attempting the same move via the command line
mv
util works instantly. It turns out the BTRFS can make a copy-on-write copy of the file even though it's moving the file between sub-volumes. Themv
util initially attempts arename()
syscall (which is the same as Go'sos.Rename()
), but if it getsEXDEV
back then it falls back to making anioctl
call to make a copy-on-write copy.The impact of this is that when moving large (4K) movies or whole TV series between BTRFS subvolumes, media-sort can take a very long time, while
mv
works instantly.I've raised a bug report in Go (which has been effectively converted to an enhancement request): https://github.com/golang/go/issues/41487. In the meantime, this PR is a stop-gap measure.