Skip to content

Commit

Permalink
allow --sshfs-nonempty
Browse files Browse the repository at this point in the history
Signed-off-by: Akihiro Suda <[email protected]>
  • Loading branch information
AkihiroSuda committed May 10, 2021
1 parent 15a30be commit 56aa3c7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 21 deletions.
18 changes: 14 additions & 4 deletions cmd/sshocker/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ var (
Name: "p",
Usage: "Expose a port, e.g. `8080:80` to forward the port 8080 the client onto the port 80 on the server",
},
&cli.BoolFlag{
Name: "sshfs-nonempty",
Usage: "enable sshfs nonempty",
Value: false,
},
}
runCommand = &cli.Command{
Name: "run",
Expand Down Expand Up @@ -74,11 +79,16 @@ func runAction(clicontext *cli.Context) error {
if err != nil {
return err
}
var sshfsAdditionalArgs []string
if clicontext.Bool("sshfs-nonempty") {
sshfsAdditionalArgs = append(sshfsAdditionalArgs, "-o", "nonempty")
}
x := &sshocker.Sshocker{
SSHConfig: sshConfig,
Host: host,
Port: port,
Command: clicontext.Args().Tail(),
SSHConfig: sshConfig,
Host: host,
Port: port,
Command: clicontext.Args().Tail(),
SSHFSAdditionalArgs: sshfsAdditionalArgs,
}
if len(x.Command) > 0 && x.Command[0] == "--" {
x.Command = x.Command[1:]
Expand Down
14 changes: 8 additions & 6 deletions pkg/reversesshfs/reversesshfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import (

type ReverseSSHFS struct {
*ssh.SSHConfig
LocalPath string
Host string
Port int
RemotePath string
Readonly bool
sshCmd *exec.Cmd
LocalPath string
Host string
Port int
RemotePath string
Readonly bool
sshCmd *exec.Cmd
SSHFSAdditionalArgs []string
}

func (rsf *ReverseSSHFS) Prepare() error {
Expand Down Expand Up @@ -55,6 +56,7 @@ func (rsf *ReverseSSHFS) Start() error {
if rsf.Readonly {
sshArgs = append(sshArgs, "-o", "ro")
}
sshArgs = append(sshArgs, rsf.SSHFSAdditionalArgs...)
rsf.sshCmd = exec.Command(sshBinary, sshArgs...)
rsf.sshCmd.Stderr = os.Stderr
stdinPipe, err := rsf.sshCmd.StdinPipe()
Expand Down
24 changes: 13 additions & 11 deletions pkg/sshocker/sshocker.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ import (

type Sshocker struct {
*ssh.SSHConfig
Host string // Required
Port int // Required
Command []string // Optional
Mounts []mount.Mount
LForwards []string
Host string // Required
Port int // Required
Command []string // Optional
Mounts []mount.Mount
LForwards []string
SSHFSAdditionalArgs []string
}

func (x *Sshocker) Run() error {
Expand All @@ -43,12 +44,13 @@ func (x *Sshocker) Run() error {
switch m.Type {
case mount.MountTypeReverseSSHFS:
rsf := &reversesshfs.ReverseSSHFS{
SSHConfig: x.SSHConfig,
LocalPath: m.Source,
Host: x.Host,
Port: x.Port,
RemotePath: m.Destination,
Readonly: m.Readonly,
SSHConfig: x.SSHConfig,
LocalPath: m.Source,
Host: x.Host,
Port: x.Port,
RemotePath: m.Destination,
Readonly: m.Readonly,
SSHFSAdditionalArgs: x.SSHFSAdditionalArgs,
}
if err := rsf.Prepare(); err != nil {
return errors.Wrapf(err, "failed to prepare mounting %q (local) onto %q (remote)", rsf.LocalPath, rsf.RemotePath)
Expand Down

0 comments on commit 56aa3c7

Please sign in to comment.