serve/sftp: support empty "md5sum" and "sha1sum" commands
This is to enable the new command detection to work with the sftp backend.
This commit is contained in:
parent
6929f5d6e6
commit
71e172a139
1 changed files with 26 additions and 15 deletions
|
@ -97,6 +97,16 @@ func (c *conn) execCommand(ctx context.Context, out io.Writer, command string) (
|
|||
if binary == "sha1sum" {
|
||||
ht = hash.SHA1
|
||||
}
|
||||
var hashSum string
|
||||
if args == "" {
|
||||
// empty hash for no input
|
||||
if ht == hash.MD5 {
|
||||
hashSum = "d41d8cd98f00b204e9800998ecf8427e"
|
||||
} else {
|
||||
hashSum = "da39a3ee5e6b4b0d3255bfef95601890afd80709"
|
||||
}
|
||||
args = "-"
|
||||
} else {
|
||||
node, err := c.vfs.Stat(args)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "hash failed finding file %q", args)
|
||||
|
@ -108,11 +118,12 @@ func (c *conn) execCommand(ctx context.Context, out io.Writer, command string) (
|
|||
if !ok {
|
||||
return errors.New("unexpected non file")
|
||||
}
|
||||
hash, err := o.Hash(ctx, ht)
|
||||
hashSum, err = o.Hash(ctx, ht)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "hash failed")
|
||||
}
|
||||
_, err = fmt.Fprintf(out, "%s %s\n", hash, args)
|
||||
}
|
||||
_, err = fmt.Fprintf(out, "%s %s\n", hashSum, args)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "send output failed")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue