Fix #119966: File rename fails on Mac with certain filesystems #120037
@ -475,31 +475,31 @@ int BLI_rename(const char *from, const char *to)
|
|||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
return urename(from, to, false);
|
return urename(from, to, false);
|
||||||
#elif defined(__APPLE__)
|
|
||||||
return renamex_np(from, to, RENAME_EXCL);
|
|
||||||
#else
|
#else
|
||||||
|
# if defined(__APPLE__)
|
||||||
|
int ret = renamex_np(from, to, RENAME_EXCL);
|
||||||
|
if (!(ret < 0 && errno == ENOTSUP)) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
# endif
|
||||||
|
|
||||||
# if defined(__GLIBC_PREREQ)
|
# if defined(__GLIBC_PREREQ)
|
||||||
# if __GLIBC_PREREQ(2, 28)
|
# if __GLIBC_PREREQ(2, 28)
|
||||||
/* Most common Linux case, use `RENAME_NOREPLACE` when available. */
|
/* Most common Linux case, use `RENAME_NOREPLACE` when available. */
|
||||||
{
|
int ret = renameat2(AT_FDCWD, from, AT_FDCWD, to, RENAME_NOREPLACE);
|
||||||
const int ret = renameat2(AT_FDCWD, from, AT_FDCWD, to, RENAME_NOREPLACE);
|
|
||||||
if (!(ret < 0 && errno == EINVAL)) {
|
if (!(ret < 0 && errno == EINVAL)) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
/* Most likely a file-system that doesn't support RENAME_NOREPLACE.
|
|
||||||
* (For example NFS, Samba, exFAT, NTFS, etc)
|
|
||||||
* Fall through to use the generic UNIX non atomic operation, see #116049. */
|
|
||||||
}
|
|
||||||
# endif /* __GLIBC_PREREQ(2, 28) */
|
# endif /* __GLIBC_PREREQ(2, 28) */
|
||||||
# endif /* __GLIBC_PREREQ */
|
# endif /* __GLIBC_PREREQ */
|
||||||
|
/* A naive non-atomic implementation, which is used for OS where atomic rename is not supported
|
||||||
/* All BSD's currently & fallback for Linux. */
|
* at all, or not implemented for specific file systems (for example NFS, Samba, exFAT, NTFS,
|
||||||
|
* etc). For those see #116049, #119966. */
|
||||||
if (BLI_exists(to)) {
|
if (BLI_exists(to)) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return rename(from, to);
|
return rename(from, to);
|
||||||
#endif /* !defined(WIN32) && !defined(__APPLE__) */
|
#endif /* !defined(WIN32) */
|
||||||
}
|
}
|
||||||
|
|
||||||
int BLI_rename_overwrite(const char *from, const char *to)
|
int BLI_rename_overwrite(const char *from, const char *to)
|
||||||
|
Loading…
Reference in New Issue
Block a user