MCPcopy
hub / github.com/syncthing/syncthing / CreateFileInfo

Function CreateFileInfo

lib/scanner/walk.go:733–767  ·  view source on GitHub ↗
(fi fs.FileInfo, name string, filesystem fs.Filesystem, scanOwnership bool, scanXattrs bool, xattrFilter XattrFilter)

Source from the content-addressed store, hash-verified

731}
732
733func 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}

Callers 8

createEmptyFileInfoFunction · 0.92
TestDeleteIgnorePermsFunction · 0.92
renameFileMethod · 0.92
scanIfItemChangedMethod · 0.92
walkRegularMethod · 0.85
walkDirMethod · 0.85
walkSymlinkMethod · 0.85

Calls 7

PlatformDataMethod · 0.65
IsSymlinkMethod · 0.65
ReadSymlinkMethod · 0.65
ModeMethod · 0.65
ModTimeMethod · 0.65
IsDirMethod · 0.65
SizeMethod · 0.65

Tested by 2

createEmptyFileInfoFunction · 0.74
TestDeleteIgnorePermsFunction · 0.74