Skip to content

Commit da6e166

Browse files
Allows SSHFS mount operation configuration
* Adds support for passing a custom list of arguments to `sshfs` program * Adds support for disabling "follow_symlinks" option (to prevent symlink loops from messing with Sublime folders refresh) * Enables by default `jail_symlinks`, `noappledouble` and `noapplexattr` options on macOS to avoid littering the mounted directory with dotfiles > see #54 Co-Authored-By: Samuel FORESTIER <[email protected]>
1 parent 8e11640 commit da6e166

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- SSHFS mount operation configuration (including disabling "follow_symlinks" option)
13+
1014
### Fixed
1115

1216
- Unmount on macOS

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ Open your command palette and type in `SSHubl` to select `Connect to server`. On
8181
"ssh_host_authentication_for_localhost": true,
8282
// Server keepalive interval (as recommended in sshfs documentation)
8383
"ssh_server_alive_interval": 15,
84+
// Custom arguments to pass to `sshfs` command.
85+
// Default to `["-ojail_symlinks", "-onoappledouble", "-onoapplexattr"]` on macOS
86+
"sshfs_arguments": [],
87+
// Whether sshfs mount should follow symlinks.
88+
// Set to `false` to avoid symlink loop issues (e.g. Sublime keeps refreshing folders).
89+
"sshfs_follow_symlinks": true,
8490
}
8591
```
8692

SSHubl.sublime-settings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,6 @@
88
"ssh_server_alive_interval": 15,
99
"ssh_login_timeout": 10,
1010
"ssh_host_authentication_for_localhost": true,
11+
"sshfs_arguments": [],
12+
"sshfs_mount_follow_symlinks": true,
1113
}

sshubl/ssh_utils.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def mount_sshfs(
252252
253253
Some options are passed to sshfs in order to :
254254
* enable (local) UNIX permissions check
255-
* follow remote symbolic links
255+
* follow remote symbolic links (if not disabled)
256256
* map remote user UID/GID to local user
257257
258258
:returns Path: local mount path on success , or `None` on error
@@ -261,15 +261,31 @@ def mount_sshfs(
261261
mount_path = mounts_path / str(identifier) / f"{remote_path.name}_{uuid.uuid4()}"
262262
mount_path.mkdir(parents=True, exist_ok=True)
263263

264+
sshfs_arguments = _settings().get("sshfs_arguments", []).copy()
265+
if not sshfs_arguments:
266+
if platform.system() == "Darwin":
267+
# See <https://github.com/macfuse/macfuse/wiki/Mount-Options> and
268+
# <https://github.com/macfuse/macfuse/issues/519> for implied Finder limitations.
269+
sshfs_arguments = [
270+
"-ojail_symlinks", # prefix absolute symbolic links by mount point
271+
"-onoappledouble", # deny access to Apple Double and .DS_Store files
272+
"-onoapplexattr", # deny access to xattr beginning with "com.apple." prefix
273+
]
274+
275+
# follow symbolic links by default
276+
# /!\ Symlink loops are known to break Sublime project folders scanning (see #54).
277+
if _settings().get("sshfs_mount_follow_symlinks", True):
278+
sshfs_arguments.append("-ofollow_symlinks")
279+
264280
try:
265281
subprocess.check_call(
266282
get_base_ssh_cmd(
267283
identifier,
268284
(
285+
# user supplied arguments (and optionally "follow_symlinks")
286+
*sshfs_arguments,
269287
# enable local permissions check
270288
"-odefault_permissions",
271-
# follow symlinks on the server
272-
"-ofollow_symlinks",
273289
# map remote user UID/GID to current user
274290
"-oidmap=user",
275291
f"-ouid={os.getuid()}",

0 commit comments

Comments
 (0)