|
1 | 1 | package archives |
2 | 2 |
|
3 | 3 | import ( |
| 4 | +"context" |
4 | 5 | "fmt" |
5 | 6 | "os" |
6 | 7 | "path/filepath" |
7 | 8 | "reflect" |
8 | 9 | "runtime" |
| 10 | +"sort" |
9 | 11 | "strings" |
10 | 12 | "testing" |
11 | 13 | ) |
@@ -510,3 +512,46 @@ func TestFollowSymlink(t *testing.T) { |
510 | 512 | } |
511 | 513 | }) |
512 | 514 | } |
| 515 | + |
| 516 | +func TestFilesFromDisk_SymlinkOutsideFileNamesMap(t *testing.T) { |
| 517 | +tmpDir := t.TempDir() |
| 518 | +otherTmpDir := t.TempDir() |
| 519 | + |
| 520 | +testDirName := "test_dir" |
| 521 | +testDir := filepath.Join(otherTmpDir, testDirName) |
| 522 | +if err := os.Mkdir(testDir, 0755); err != nil { |
| 523 | +t.Fatal(err) |
| 524 | +} |
| 525 | + |
| 526 | +testFileName := "test.txt" |
| 527 | +testFile := filepath.Join(testDir, testFileName) |
| 528 | +if err := os.WriteFile(testFile, []byte("test content"), 0644); err != nil { |
| 529 | +t.Fatal(err) |
| 530 | +} |
| 531 | + |
| 532 | +symlinkDirName := "symlink_dir" |
| 533 | +symlinkDir := filepath.Join(tmpDir, symlinkDirName) |
| 534 | +if err := os.Symlink(testDir, symlinkDir); err != nil { |
| 535 | +t.Fatal(err) |
| 536 | +} |
| 537 | + |
| 538 | +files, err := FilesFromDisk(context.Background(), &FromDiskOptions{ |
| 539 | +FollowSymlinks: true, |
| 540 | +}, map[string]string{symlinkDir: ""}) |
| 541 | +if err != nil { |
| 542 | +t.Fatal(err) |
| 543 | +} |
| 544 | + |
| 545 | +sort.Slice(files, func(i, j int) bool { |
| 546 | +return files[i].NameInArchive < files[j].NameInArchive |
| 547 | +}) |
| 548 | + |
| 549 | +if files[0].NameInArchive != symlinkDirName { |
| 550 | +t.Fatalf("expected file name '%s', got '%s'", symlinkDirName, files[0].NameInArchive) |
| 551 | +} |
| 552 | + |
| 553 | +testFilePath := filepath.Join(symlinkDirName, testFileName) |
| 554 | +if files[1].NameInArchive != testFilePath { |
| 555 | +t.Fatalf("expected file name '%s', got '%s'", testFilePath, files[1].NameInArchive) |
| 556 | +} |
| 557 | +} |
0 commit comments