(t *testing.T)
| 653 | } |
| 654 | |
| 655 | func TestCopyOwner(t *testing.T) { |
| 656 | // Verifies that owner and group are copied from the parent, for both |
| 657 | // files and directories. |
| 658 | |
| 659 | if build.IsWindows { |
| 660 | t.Skip("copying owner not supported on Windows") |
| 661 | } |
| 662 | |
| 663 | const ( |
| 664 | expOwner = 1234 |
| 665 | expGroup = 5678 |
| 666 | ) |
| 667 | |
| 668 | // This test hung on a regression, taking a long time to fail - speed that up. |
| 669 | ctx, cancel := context.WithTimeout(t.Context(), 2*time.Second) |
| 670 | defer cancel() |
| 671 | go func() { |
| 672 | <-ctx.Done() |
| 673 | if errors.Is(ctx.Err(), context.DeadlineExceeded) { |
| 674 | pprof.Lookup("goroutine").WriteTo(os.Stdout, 2) |
| 675 | panic("timed out before test finished") |
| 676 | } |
| 677 | }() |
| 678 | |
| 679 | // Set up a folder with the CopyParentOwner bit and backed by a fake |
| 680 | // filesystem. |
| 681 | |
| 682 | m, f := setupSendReceiveFolder(t) |
| 683 | f.folder.FolderConfiguration = newFolderConfiguration(m.cfg, f.ID, f.Label, config.FilesystemTypeFake, "/TestCopyOwner") |
| 684 | f.folder.FolderConfiguration.CopyOwnershipFromParent = true |
| 685 | |
| 686 | // Create a parent dir with a certain owner/group. |
| 687 | |
| 688 | f.mtimefs.Mkdir("foo", 0o755) |
| 689 | f.mtimefs.Lchown("foo", strconv.Itoa(expOwner), strconv.Itoa(expGroup)) |
| 690 | |
| 691 | dir := protocol.FileInfo{ |
| 692 | Name: "foo/bar", |
| 693 | Type: protocol.FileInfoTypeDirectory, |
| 694 | Permissions: 0o755, |
| 695 | } |
| 696 | |
| 697 | // Have the folder create a subdirectory, verify that it's the correct |
| 698 | // owner/group. |
| 699 | |
| 700 | dbUpdateChan := make(chan dbUpdateJob, 1) |
| 701 | scanChan := make(chan string) |
| 702 | defer close(dbUpdateChan) |
| 703 | f.handleDir(dir, dbUpdateChan, scanChan) |
| 704 | select { |
| 705 | case <-dbUpdateChan: // empty the channel for later |
| 706 | case toScan := <-scanChan: |
| 707 | t.Fatal("Unexpected receive on scanChan:", toScan) |
| 708 | } |
| 709 | |
| 710 | info, err := f.mtimefs.Lstat("foo/bar") |
| 711 | if err != nil { |
| 712 | t.Fatal("Unexpected error (dir):", err) |
nothing calls this directly
no test coverage detected