Closed twpayne closed 5 years ago
I’m not a fan of this change — the current code is more portable and determines eligibility by performing exactly the operations we need. I think that’s more elegant than checking whether files reside on the same device.
Given that performance-sensitive users are encouraged to explicitly call TempDir once and re-use the result, I don’t think performance is important here.
OK, fair enough.
I'm not sure if this is correct, but if it is then it's a simplification and speed improvement.
Basically, instead of creating a test temporary file and trying to rename it to determine if the return value of
os.TempDir()
can be used, we directly compare the device numbers and use the returned value if the device numbers are the same.The original code has some behaviors that are not reflected in this approach. For example, the original code would fallback to
filepath.Dir(dest)
if it encountered any errors. Errors that might be encountered include not having permission to write to either directory (os.TempDir()
orfilepath.Dir(dest)
) or disk full situations. Whether it is correct to fallback tofilepath.Dir(dest)
in these situations is debatable.