summaryrefslogtreecommitdiff
path: root/sftp-server.c
diff options
context:
space:
mode:
authorDarren Tucker <dtucker@zip.com.au>2004-06-25 17:06:02 +1000
committerDarren Tucker <dtucker@zip.com.au>2004-06-25 17:06:02 +1000
commitaedc1d6a3ed351d11514b9bdf52456ff27dc16bc (patch)
tree3bb82de7aa937caedf432531f58966d54304d9c0 /sftp-server.c
parent17c5d03ad3bcb782b5b3768b3e70a050d86d5fa1 (diff)
- dtucker@cvs.openbsd.org 2004/06/25 05:38:48
[sftp-server.c] Fall back to stat+rename if filesystem doesn't doesn't support hard links. bz#823, ok djm@
Diffstat (limited to 'sftp-server.c')
-rw-r--r--sftp-server.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/sftp-server.c b/sftp-server.c
index 8349c1763..39a6bdab4 100644
--- a/sftp-server.c
+++ b/sftp-server.c
@@ -14,7 +14,7 @@
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */ 15 */
16#include "includes.h" 16#include "includes.h"
17RCSID("$OpenBSD: sftp-server.c,v 1.46 2004/06/21 17:36:31 avsm Exp $"); 17RCSID("$OpenBSD: sftp-server.c,v 1.47 2004/06/25 05:38:48 dtucker Exp $");
18 18
19#include "buffer.h" 19#include "buffer.h"
20#include "bufaux.h" 20#include "bufaux.h"
@@ -839,9 +839,25 @@ process_rename(void)
839 status = errno_to_portable(errno); 839 status = errno_to_portable(errno);
840 else if (S_ISREG(sb.st_mode)) { 840 else if (S_ISREG(sb.st_mode)) {
841 /* Race-free rename of regular files */ 841 /* Race-free rename of regular files */
842 if (link(oldpath, newpath) == -1) 842 if (link(oldpath, newpath) == -1) {
843 status = errno_to_portable(errno); 843 if (errno == EOPNOTSUPP) {
844 else if (unlink(oldpath) == -1) { 844 struct stat st;
845
846 /*
847 * fs doesn't support links, so fall back to
848 * stat+rename. This is racy.
849 */
850 if (stat(newpath, &st) == -1) {
851 if (rename(oldpath, newpath) == -1)
852 status =
853 errno_to_portable(errno);
854 else
855 status = SSH2_FX_OK;
856 }
857 } else {
858 status = errno_to_portable(errno);
859 }
860 } else if (unlink(oldpath) == -1) {
845 status = errno_to_portable(errno); 861 status = errno_to_portable(errno);
846 /* clean spare link */ 862 /* clean spare link */
847 unlink(newpath); 863 unlink(newpath);