Fix errors when calling create_buf with a file instead of a dir. Fix a few exceptions that to_rel_path can raise on Windows.