|
Lines 819-827
process_rename(void)
Link Here
|
| 819 |
status = errno_to_portable(errno); |
819 |
status = errno_to_portable(errno); |
| 820 |
else if (S_ISREG(sb.st_mode)) { |
820 |
else if (S_ISREG(sb.st_mode)) { |
| 821 |
/* Race-free rename of regular files */ |
821 |
/* Race-free rename of regular files */ |
| 822 |
if (link(oldpath, newpath) == -1) |
822 |
if (link(oldpath, newpath) == -1) { |
| 823 |
status = errno_to_portable(errno); |
823 |
if (errno == EOPNOTSUPP) { |
| 824 |
else if (unlink(oldpath) == -1) { |
824 |
struct stat st; |
|
|
825 |
|
| 826 |
/* |
| 827 |
* fs doesn't support links, so fall back to |
| 828 |
* stat+rename. This is racy. |
| 829 |
*/ |
| 830 |
if (stat(newpath, &st) == -1) { |
| 831 |
if (rename(oldpath, newpath) == -1) |
| 832 |
status = |
| 833 |
errno_to_portable(errno); |
| 834 |
else |
| 835 |
status = SSH2_FX_OK; |
| 836 |
} |
| 837 |
} else { |
| 838 |
status = errno_to_portable(errno); |
| 839 |
} |
| 840 |
} else if (unlink(oldpath) == -1) { |
| 825 |
status = errno_to_portable(errno); |
841 |
status = errno_to_portable(errno); |
| 826 |
/* clean spare link */ |
842 |
/* clean spare link */ |
| 827 |
unlink(newpath); |
843 |
unlink(newpath); |