# whether config protection or not, we merge the new file the
# same way. Unless moveme=0 (blocking directory)
if moveme:
- # Do not hardlink files unless they are in the same
- # directory, since otherwise tar may not be able to
- # extract a tarball of the resulting hardlinks due to
- # 'Invalid cross-device link' errors (depends on layout of
- # mount points). Also, don't hardlink zero-byte files since
- # it doesn't save any space, and don't hardlink
- # CONFIG_PROTECTed files since config files shouldn't be
- # hardlinked to eachother (for example, shadow installs
- # several identical config files inside /etc/pam.d/).
- parent_dir = os.path.dirname(myrealdest)
- hardlink_key = (parent_dir, mymd5, mystat.st_size,
- mystat.st_mode, mystat.st_uid, mystat.st_gid)
-
- hardlink_candidates = None
- if not protected and mystat.st_size != 0:
- hardlink_candidates = self._md5_merge_map.get(hardlink_key)
- if hardlink_candidates is None:
- hardlink_candidates = []
- self._md5_merge_map[hardlink_key] = hardlink_candidates
+ # Create hardlinks only for source files that already exist
+ # as hardlinks (having identical st_dev and st_ino).
+ hardlink_key = (mystat.st_dev, mystat.st_ino)
+
+ hardlink_candidates = self._md5_merge_map.get(hardlink_key)
+ if hardlink_candidates is None:
+ hardlink_candidates = []
+ self._md5_merge_map[hardlink_key] = hardlink_candidates
mymtime = movefile(mysrc, mydest, newmtime=thismtime,
sstat=mystat, mysettings=self.settings,