| 304 | } |
| 305 | |
| 306 | func copyFiles(sourcePath string, targetPath string, fileNames []string, t *testing.T) { |
| 307 | t.Helper() |
| 308 | targetDir, err := os.Open(targetPath) |
| 309 | if err != nil { |
| 310 | t.Fatalf("Can't open dir %v: %v", targetPath, err) |
| 311 | } |
| 312 | defer targetDir.Close() |
| 313 | names, err := targetDir.Readdirnames(-1) |
| 314 | if err != nil { |
| 315 | t.Fatalf("Can't read dir %v: %v", targetPath, err) |
| 316 | } |
| 317 | for _, name := range names { |
| 318 | err = os.RemoveAll(filepath.Join(targetPath, name)) |
| 319 | if err != nil { |
| 320 | t.Fatalf("Can't remove file %v: %v", name, err) |
| 321 | } |
| 322 | } |
| 323 | for _, fileName := range fileNames { |
| 324 | destinationPath := filepath.Join(targetPath, fileName) |
| 325 | |
| 326 | sourceFile, err := os.Open(filepath.Join(sourcePath, fileName)) |
| 327 | if err != nil { |
| 328 | t.Fatalf("Can't open file %v: %v", fileName, err) |
| 329 | } |
| 330 | defer sourceFile.Close() |
| 331 | |
| 332 | destinationFile, err := os.Create(destinationPath) |
| 333 | if err != nil { |
| 334 | t.Fatalf("Can't create file %v: %v", destinationFile, err) |
| 335 | } |
| 336 | defer destinationFile.Close() |
| 337 | |
| 338 | _, err = io.Copy(destinationFile, sourceFile) |
| 339 | if err != nil { |
| 340 | t.Fatalf("Can't copy file %v to %v: %v", sourceFile, destinationFile, err) |
| 341 | } |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | func createTmpDir(t *testing.T) string { |
| 346 | t.Helper() |