| 1 | package fs |
| 2 | |
| 3 | import "os" |
| 4 | |
| 5 | // GetLinkInfo returns an identifier representing the node a hardlink is pointing |
| 6 | // to. If the file is not hard linked then 0 will be returned. |
| 7 | func GetLinkInfo(fi os.FileInfo) (uint64, bool) { |
| 8 | return getLinkInfo(fi) |
| 9 | } |
| 10 | |
| 11 | // getLinkSource returns a path for the given name and |
| 12 | // file info to its link source in the provided inode |
| 13 | // map. If the given file name is not in the map and |
| 14 | // has other links, it is added to the inode map |
| 15 | // to be a source for other link locations. |
| 16 | func getLinkSource(name string, fi os.FileInfo, inodes map[uint64]string) (string, error) { |
| 17 | inode, isHardlink := getLinkInfo(fi) |
| 18 | if !isHardlink { |
| 19 | return "", nil |
| 20 | } |
| 21 | |
| 22 | path, ok := inodes[inode] |
| 23 | if !ok { |
| 24 | inodes[inode] = name |
| 25 | } |
| 26 | return path, nil |
| 27 | } |