openssh: Do not try link(2) for sftp-server rename
authorFredrik Fornwall <fredrik@fornwall.net>
Mon, 6 Jun 2016 22:19:47 +0000 (18:19 -0400)
committerFredrik Fornwall <fredrik@fornwall.net>
Mon, 6 Jun 2016 22:23:11 +0000 (18:23 -0400)
Hard links are not supported on Android from 6.0 on.

Fixes #293.

packages/openssh/build.sh
packages/openssh/sftp-server.c.patch [new file with mode: 0644]

index 7428e1f..e907ded 100755 (executable)
@@ -1,7 +1,7 @@
 TERMUX_PKG_HOMEPAGE=http://www.openssh.com/
 TERMUX_PKG_DESCRIPTION="Secure shell for logging into a remote machine"
 TERMUX_PKG_VERSION=7.2p2
-TERMUX_PKG_BUILD_REVISION=2
+TERMUX_PKG_BUILD_REVISION=3
 TERMUX_PKG_SRCURL=http://ftp.eu.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-${TERMUX_PKG_VERSION}.tar.gz
 TERMUX_PKG_DEPENDS="libandroid-support, ldns, openssl"
 # --disable-strip to prevent host "install" command to use "-s", which won't work for target binaries:
diff --git a/packages/openssh/sftp-server.c.patch b/packages/openssh/sftp-server.c.patch
new file mode 100644 (file)
index 0000000..fcdf0bd
--- /dev/null
@@ -0,0 +1,37 @@
+diff -u -r ../openssh-7.2p2/sftp-server.c ./sftp-server.c
+--- ../openssh-7.2p2/sftp-server.c     2016-03-09 13:04:48.000000000 -0500
++++ ./sftp-server.c    2016-06-06 18:13:28.141236751 -0400
+@@ -1190,7 +1190,9 @@
+       if (lstat(oldpath, &sb) == -1)
+               status = errno_to_portable(errno);
+       else if (S_ISREG(sb.st_mode)) {
++#ifndef __ANDROID__
+               /* Race-free rename of regular files */
++              /* Do not try this for Android which does not support links */
+               if (link(oldpath, newpath) == -1) {
+                       if (errno == EOPNOTSUPP || errno == ENOSYS
+ #ifdef EXDEV
+@@ -1200,6 +1202,7 @@
+                           || errno == LINK_OPNOTSUPP_ERRNO
+ #endif
+                           ) {
++#endif
+                               struct stat st;
+                               /*
+@@ -1213,6 +1216,7 @@
+                                       else
+                                               status = SSH2_FX_OK;
+                               }
++#ifndef __ANDROID__
+                       } else {
+                               status = errno_to_portable(errno);
+                       }
+@@ -1222,6 +1226,7 @@
+                       unlink(newpath);
+               } else
+                       status = SSH2_FX_OK;
++#endif
+       } else if (stat(newpath, &sb) == -1) {
+               if (rename(oldpath, newpath) == -1)
+                       status = errno_to_portable(errno);