Skip to content

Commit eac4207

Browse files
billziss-ghNikratio
authored andcommitted
Port SSHFS to Cygwin
1 parent 6480b66 commit eac4207

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

ChangeLog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ Unreleased Changes
22
------------------
33

44
* Fixed error code returned by rename(), allowing proper fallback.
5+
* Port to Cygwin.
56

67
Release 3.4.0 (2018-06-29)
78
--------------------------

sshfs.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include <fuse.h>
1313
#include <fuse_opt.h>
1414
#if !defined(__CYGWIN__)
15-
#include <fuse_lowlevel.h>
15+
# include <fuse_lowlevel.h>
1616
#endif
1717
#ifdef __APPLE__
1818
# include <fuse_darwin.h>
@@ -3452,7 +3452,39 @@ static int sshfs_opt_proc(void *data, const char *arg, int key,
34523452
return 0;
34533453
}
34543454
else if (!sshfs.mountpoint) {
3455+
#if defined(__CYGWIN__)
3456+
/*
3457+
* On FUSE for Cygwin the mountpoint may be a drive or directory.
3458+
* Furthermore the mountpoint must NOT exist prior to mounting.
3459+
* So we cannot use realpath(3).
3460+
*/
3461+
if ((('A' <= arg[0] && arg[0] <= 'Z') || ('a' <= arg[0] && arg[0] <= 'z'))
3462+
&& ':' == arg[1] && '\0' == arg[2]) {
3463+
/* drive: make a copy */
3464+
sshfs.mountpoint = strdup(arg);
3465+
} else {
3466+
/* path: split into dirname, basename and check dirname */
3467+
char *dir;
3468+
const char *base;
3469+
const char *slash = strrchr(arg, '/');
3470+
if (slash) {
3471+
char *tmp = strndup(arg, slash == arg ? 1 : slash - arg);
3472+
dir = tmp ? realpath(tmp, NULL) : 0;
3473+
base = slash + 1;
3474+
free(tmp);
3475+
} else {
3476+
dir = realpath(".", NULL);
3477+
base = arg;
3478+
}
3479+
if (dir) {
3480+
slash = '/' == dir[0] && '\0' == dir[1] ? "" : "/";
3481+
asprintf(&sshfs.mountpoint, "%s%s%s", dir, slash, base);
3482+
free(dir);
3483+
}
3484+
}
3485+
#else
34553486
sshfs.mountpoint = realpath(arg, NULL);
3487+
#endif
34563488
if (!sshfs.mountpoint) {
34573489
fprintf(stderr, "sshfs: bad mount point `%s': %s\n",
34583490
arg, strerror(errno));
@@ -3912,7 +3944,9 @@ int main(int argc, char *argv[])
39123944
if (sshfs.show_version) {
39133945
printf("SSHFS version %s\n", PACKAGE_VERSION);
39143946
printf("FUSE library version %s\n", fuse_pkgversion());
3947+
#if !defined(__CYGWIN__)
39153948
fuse_lowlevel_version();
3949+
#endif
39163950
exit(0);
39173951
}
39183952

0 commit comments

Comments
 (0)