| 476 | } |
| 477 | |
| 478 | func (self *Shell) CopyFile(source string, destination string) *Shell { |
| 479 | absSourcePath := filepath.Join(self.dir, source) |
| 480 | absDestPath := filepath.Join(self.dir, destination) |
| 481 | sourceFile, err := os.Open(absSourcePath) |
| 482 | if err != nil { |
| 483 | self.fail(err.Error()) |
| 484 | } |
| 485 | defer sourceFile.Close() |
| 486 | |
| 487 | destinationFile, err := os.Create(absDestPath) |
| 488 | if err != nil { |
| 489 | self.fail(err.Error()) |
| 490 | } |
| 491 | defer destinationFile.Close() |
| 492 | |
| 493 | _, err = io.Copy(destinationFile, sourceFile) |
| 494 | if err != nil { |
| 495 | self.fail(err.Error()) |
| 496 | } |
| 497 | |
| 498 | // copy permissions to destination file too |
| 499 | sourceFileInfo, err := os.Stat(absSourcePath) |
| 500 | if err != nil { |
| 501 | self.fail(err.Error()) |
| 502 | } |
| 503 | |
| 504 | err = os.Chmod(absDestPath, sourceFileInfo.Mode()) |
| 505 | if err != nil { |
| 506 | self.fail(err.Error()) |
| 507 | } |
| 508 | |
| 509 | return self |
| 510 | } |
| 511 | |
| 512 | // The final value passed to Chdir() during setup |
| 513 | // will be the directory the test is run from. |