Fixing #2033 by adding a small check on the input

If the input begins with a shebang, we’ll leave it as is. If not we’ll
add a default shebang…
This commit is contained in:
Sander van Harmelen 2015-05-21 23:36:54 +02:00
parent ec06e81cf3
commit f146a31ded
1 changed files with 12 additions and 3 deletions

View File

@ -222,10 +222,19 @@ func (c *Communicator) Upload(path string, input io.Reader) error {
// UploadScript implementation of communicator.Communicator interface // UploadScript implementation of communicator.Communicator interface
func (c *Communicator) UploadScript(path string, input io.Reader) error { func (c *Communicator) UploadScript(path string, input io.Reader) error {
script := bytes.NewBufferString(DefaultShebang) reader := bufio.NewReader(input)
script.ReadFrom(input) prefix, err := reader.Peek(2)
if err != nil {
return fmt.Errorf("Error reading script: %s", err)
}
if err := c.Upload(path, script); err != nil { var script bytes.Buffer
if string(prefix) != "#!" {
script.WriteString(DefaultShebang)
}
script.ReadFrom(reader)
if err := c.Upload(path, &script); err != nil {
return err return err
} }