]> andersk Git - openssh.git/blobdiff - sftp-server.c
- jmc@cvs.openbsd.org 2005/03/01 18:15:56
[openssh.git] / sftp-server.c
index 8349c176396d7f3441e499e555fc7e254ea057c0..e82280057534a57a4eeb6dcba955b5d5e620bf31 100644 (file)
@@ -14,7 +14,7 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 #include "includes.h"
-RCSID("$OpenBSD: sftp-server.c,v 1.46 2004/06/21 17:36:31 avsm Exp $");
+RCSID("$OpenBSD: sftp-server.c,v 1.47 2004/06/25 05:38:48 dtucker Exp $");
 
 #include "buffer.h"
 #include "bufaux.h"
@@ -31,11 +31,7 @@ RCSID("$OpenBSD: sftp-server.c,v 1.46 2004/06/21 17:36:31 avsm Exp $");
 #define get_string(lenp)               buffer_get_string(&iqueue, lenp);
 #define TRACE                          debug
 
-#ifdef HAVE___PROGNAME
 extern char *__progname;
-#else
-char *__progname;
-#endif
 
 /* input and output queue */
 Buffer iqueue;
@@ -839,9 +835,29 @@ process_rename(void)
                status = errno_to_portable(errno);
        else if (S_ISREG(sb.st_mode)) {
                /* Race-free rename of regular files */
-               if (link(oldpath, newpath) == -1)
-                       status = errno_to_portable(errno);
-               else if (unlink(oldpath) == -1) {
+               if (link(oldpath, newpath) == -1) {
+                       if (errno == EOPNOTSUPP
+#ifdef LINK_OPNOTSUPP_ERRNO
+                           || errno == LINK_OPNOTSUPP_ERRNO
+#endif
+                           ) {
+                               struct stat st;
+
+                               /*
+                                * fs doesn't support links, so fall back to
+                                * stat+rename.  This is racy.
+                                */
+                               if (stat(newpath, &st) == -1) {
+                                       if (rename(oldpath, newpath) == -1)
+                                               status =
+                                                   errno_to_portable(errno);
+                                       else
+                                               status = SSH2_FX_OK;
+                               }
+                       } else {
+                               status = errno_to_portable(errno);
+                       }
+               } else if (unlink(oldpath) == -1) {
                        status = errno_to_portable(errno);
                        /* clean spare link */
                        unlink(newpath);
This page took 0.035665 seconds and 4 git commands to generate.