Skip to content

Commit 4648db9

Browse files
authored
Merge pull request #14 from desultory/dev
fix stale inodes not being removed for hardlink creation
2 parents 60facf5 + 348a155 commit 4648db9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/pycpio/cpio/archive.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,31 @@ def _update_inodes(self, entry):
5555
if it's a hardlink, remove the data in the copy.
5656
"""
5757
if entry.header.ino in self.inodes:
58+
self.logger.log(5, "[%s] Inode already exists: %s" % (entry.header.name, entry.header.ino))
59+
# For regular files, check if the existing entry has the same data, if so, clear it before making a hardlink
5860
if isinstance(entry, CPIO_File) and self[self.inodes[entry.header.ino][0]].data == entry.data:
5961
self.logger.info("[%s] New hardlink detected, removing data." % entry.header.name)
6062
# Remove the data from the current entry
6163
entry.data = b""
64+
# If it's a file, but has no data, it's already a hardlink
6265
elif isinstance(entry, CPIO_File) and entry.data == b"":
6366
self.logger.debug("[%s] Hardlink detected." % entry.header.name)
6467
else:
6568
from .common import get_new_inode
6669

67-
if entry.header.ino == 0 and not self.reproducible:
70+
if entry.header.ino == 0 and not self.reproducible: # Warn for another inode of 0 for non-reproducible archives
6871
self.logger.warning("[%s] Inode already exists: %s" % (entry.header.name, entry.header.ino))
72+
73+
old_inode = entry.header.ino
6974
entry.header.ino = get_new_inode(self.inodes)
7075
if self.reproducible:
7176
self.logger.debug("[%s] Inode recalculated: %s" % (entry.header.name, entry.header.ino))
7277
else:
7378
self.logger.info("[%s] New inode: %s" % (entry.header.name, entry.header.ino))
79+
# Create a new inode entry, clear the old one if it's empty
7480
self.inodes[entry.header.ino] = []
81+
if len(self.inodes[old_inode]) == 0:
82+
del self.inodes[old_inode]
7583
else:
7684
self.inodes[entry.header.ino] = []
7785
self.inodes[entry.header.ino].append(entry.header.name)

0 commit comments

Comments
 (0)