Skip to content

Commit 56aa3c7

Browse files
committed
allow --sshfs-nonempty
Signed-off-by: Akihiro Suda <[email protected]>
1 parent 15a30be commit 56aa3c7

File tree

3 files changed

+35
-21
lines changed

3 files changed

+35
-21
lines changed

cmd/sshocker/run.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ var (
3636
Name: "p",
3737
Usage: "Expose a port, e.g. `8080:80` to forward the port 8080 the client onto the port 80 on the server",
3838
},
39+
&cli.BoolFlag{
40+
Name: "sshfs-nonempty",
41+
Usage: "enable sshfs nonempty",
42+
Value: false,
43+
},
3944
}
4045
runCommand = &cli.Command{
4146
Name: "run",
@@ -74,11 +79,16 @@ func runAction(clicontext *cli.Context) error {
7479
if err != nil {
7580
return err
7681
}
82+
var sshfsAdditionalArgs []string
83+
if clicontext.Bool("sshfs-nonempty") {
84+
sshfsAdditionalArgs = append(sshfsAdditionalArgs, "-o", "nonempty")
85+
}
7786
x := &sshocker.Sshocker{
78-
SSHConfig: sshConfig,
79-
Host: host,
80-
Port: port,
81-
Command: clicontext.Args().Tail(),
87+
SSHConfig: sshConfig,
88+
Host: host,
89+
Port: port,
90+
Command: clicontext.Args().Tail(),
91+
SSHFSAdditionalArgs: sshfsAdditionalArgs,
8292
}
8393
if len(x.Command) > 0 && x.Command[0] == "--" {
8494
x.Command = x.Command[1:]

pkg/reversesshfs/reversesshfs.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@ import (
1818

1919
type ReverseSSHFS struct {
2020
*ssh.SSHConfig
21-
LocalPath string
22-
Host string
23-
Port int
24-
RemotePath string
25-
Readonly bool
26-
sshCmd *exec.Cmd
21+
LocalPath string
22+
Host string
23+
Port int
24+
RemotePath string
25+
Readonly bool
26+
sshCmd *exec.Cmd
27+
SSHFSAdditionalArgs []string
2728
}
2829

2930
func (rsf *ReverseSSHFS) Prepare() error {
@@ -55,6 +56,7 @@ func (rsf *ReverseSSHFS) Start() error {
5556
if rsf.Readonly {
5657
sshArgs = append(sshArgs, "-o", "ro")
5758
}
59+
sshArgs = append(sshArgs, rsf.SSHFSAdditionalArgs...)
5860
rsf.sshCmd = exec.Command(sshBinary, sshArgs...)
5961
rsf.sshCmd.Stderr = os.Stderr
6062
stdinPipe, err := rsf.sshCmd.StdinPipe()

pkg/sshocker/sshocker.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ import (
1414

1515
type Sshocker struct {
1616
*ssh.SSHConfig
17-
Host string // Required
18-
Port int // Required
19-
Command []string // Optional
20-
Mounts []mount.Mount
21-
LForwards []string
17+
Host string // Required
18+
Port int // Required
19+
Command []string // Optional
20+
Mounts []mount.Mount
21+
LForwards []string
22+
SSHFSAdditionalArgs []string
2223
}
2324

2425
func (x *Sshocker) Run() error {
@@ -43,12 +44,13 @@ func (x *Sshocker) Run() error {
4344
switch m.Type {
4445
case mount.MountTypeReverseSSHFS:
4546
rsf := &reversesshfs.ReverseSSHFS{
46-
SSHConfig: x.SSHConfig,
47-
LocalPath: m.Source,
48-
Host: x.Host,
49-
Port: x.Port,
50-
RemotePath: m.Destination,
51-
Readonly: m.Readonly,
47+
SSHConfig: x.SSHConfig,
48+
LocalPath: m.Source,
49+
Host: x.Host,
50+
Port: x.Port,
51+
RemotePath: m.Destination,
52+
Readonly: m.Readonly,
53+
SSHFSAdditionalArgs: x.SSHFSAdditionalArgs,
5254
}
5355
if err := rsf.Prepare(); err != nil {
5456
return errors.Wrapf(err, "failed to prepare mounting %q (local) onto %q (remote)", rsf.LocalPath, rsf.RemotePath)

0 commit comments

Comments
 (0)