| 731 | } |
| 732 | |
| 733 | func CreateFileInfo(fi fs.FileInfo, name string, filesystem fs.Filesystem, scanOwnership bool, scanXattrs bool, xattrFilter XattrFilter) (protocol.FileInfo, error) { |
| 734 | f := protocol.FileInfo{Name: name} |
| 735 | if scanOwnership || scanXattrs { |
| 736 | if plat, err := filesystem.PlatformData(name, scanOwnership, scanXattrs, xattrFilter); err == nil { |
| 737 | f.Platform = plat |
| 738 | } else { |
| 739 | return protocol.FileInfo{}, fmt.Errorf("reading platform data: %w", err) |
| 740 | } |
| 741 | } |
| 742 | |
| 743 | if fi.IsSymlink() { |
| 744 | f.Type = protocol.FileInfoTypeSymlink |
| 745 | target, err := filesystem.ReadSymlink(name) |
| 746 | if err != nil { |
| 747 | return protocol.FileInfo{}, err |
| 748 | } |
| 749 | f.SymlinkTarget = []byte(target) |
| 750 | f.NoPermissions = true // Symlinks don't have permissions of their own |
| 751 | return f, nil |
| 752 | } |
| 753 | |
| 754 | f.Permissions = uint32(fi.Mode() & fs.ModePerm) |
| 755 | f.ModifiedS = fi.ModTime().Unix() |
| 756 | f.ModifiedNs = int32(fi.ModTime().Nanosecond()) |
| 757 | |
| 758 | if fi.IsDir() { |
| 759 | f.Type = protocol.FileInfoTypeDirectory |
| 760 | return f, nil |
| 761 | } |
| 762 | |
| 763 | f.Size = fi.Size() |
| 764 | f.Type = protocol.FileInfoTypeFile |
| 765 | |
| 766 | return f, nil |
| 767 | } |