
Previously hardlinking to an unmodified file or linking to a file which was touched by not detected as modified caused a new file to be created on unpack. This new file and the original source file were not linked since no link record was created in the tar. This change addresses this by adding links for all hardlinks to a file when it is detected as changed. These links will be written after the source file is written and may occur out of order in regard to file name. Signed-off-by: Derek McGowan <derek@mcgstyle.net>
28 lines
752 B
Go
28 lines
752 B
Go
package fs
|
|
|
|
import "os"
|
|
|
|
// GetLinkID returns an identifier representing the node a hardlink is pointing
|
|
// to. If the file is not hard linked then 0 will be returned.
|
|
func GetLinkInfo(fi os.FileInfo) (uint64, bool) {
|
|
return getLinkInfo(fi)
|
|
}
|
|
|
|
// getLinkSource returns a path for the given name and
|
|
// file info to its link source in the provided inode
|
|
// map. If the given file name is not in the map and
|
|
// has other links, it is added to the inode map
|
|
// to be a source for other link locations.
|
|
func getLinkSource(name string, fi os.FileInfo, inodes map[uint64]string) (string, error) {
|
|
inode, isHardlink := getLinkInfo(fi)
|
|
if !isHardlink {
|
|
return "", nil
|
|
}
|
|
|
|
path, ok := inodes[inode]
|
|
if !ok {
|
|
inodes[inode] = name
|
|
}
|
|
return path, nil
|
|
}
|