diff --git a/src/pycpio/cpio/archive.py b/src/pycpio/cpio/archive.py index dff92c7..9cb3380 100644 --- a/src/pycpio/cpio/archive.py +++ b/src/pycpio/cpio/archive.py @@ -55,23 +55,31 @@ def _update_inodes(self, entry): if it's a hardlink, remove the data in the copy. """ if entry.header.ino in self.inodes: + self.logger.log(5, "[%s] Inode already exists: %s" % (entry.header.name, entry.header.ino)) + # For regular files, check if the existing entry has the same data, if so, clear it before making a hardlink if isinstance(entry, CPIO_File) and self[self.inodes[entry.header.ino][0]].data == entry.data: self.logger.info("[%s] New hardlink detected, removing data." % entry.header.name) # Remove the data from the current entry entry.data = b"" + # If it's a file, but has no data, it's already a hardlink elif isinstance(entry, CPIO_File) and entry.data == b"": self.logger.debug("[%s] Hardlink detected." % entry.header.name) else: from .common import get_new_inode - if entry.header.ino == 0 and not self.reproducible: + if entry.header.ino == 0 and not self.reproducible: # Warn for another inode of 0 for non-reproducible archives self.logger.warning("[%s] Inode already exists: %s" % (entry.header.name, entry.header.ino)) + + old_inode = entry.header.ino entry.header.ino = get_new_inode(self.inodes) if self.reproducible: self.logger.debug("[%s] Inode recalculated: %s" % (entry.header.name, entry.header.ino)) else: self.logger.info("[%s] New inode: %s" % (entry.header.name, entry.header.ino)) + # Create a new inode entry, clear the old one if it's empty self.inodes[entry.header.ino] = [] + if len(self.inodes[old_inode]) == 0: + del self.inodes[old_inode] else: self.inodes[entry.header.ino] = [] self.inodes[entry.header.ino].append(entry.header.name)