Skip to content

Commit 348a155

Browse files
committed
improve comments, remove stale inode entries when recalucating
Signed-off-by: Zen <[email protected]>
1 parent 2b7028e commit 348a155

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/pycpio/cpio/archive.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,30 @@ def _update_inodes(self, entry):
5656
"""
5757
if entry.header.ino in self.inodes:
5858
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
5960
if isinstance(entry, CPIO_File) and self[self.inodes[entry.header.ino][0]].data == entry.data:
6061
self.logger.info("[%s] New hardlink detected, removing data." % entry.header.name)
6162
# Remove the data from the current entry
6263
entry.data = b""
64+
# If it's a file, but has no data, it's already a hardlink
6365
elif isinstance(entry, CPIO_File) and entry.data == b"":
6466
self.logger.debug("[%s] Hardlink detected." % entry.header.name)
6567
else:
6668
from .common import get_new_inode
6769

68-
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
6971
self.logger.warning("[%s] Inode already exists: %s" % (entry.header.name, entry.header.ino))
72+
73+
old_inode = entry.header.ino
7074
entry.header.ino = get_new_inode(self.inodes)
7175
if self.reproducible:
7276
self.logger.debug("[%s] Inode recalculated: %s" % (entry.header.name, entry.header.ino))
7377
else:
7478
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
7580
self.inodes[entry.header.ino] = []
81+
if len(self.inodes[old_inode]) == 0:
82+
del self.inodes[old_inode]
7683
else:
7784
self.inodes[entry.header.ino] = []
7885
self.inodes[entry.header.ino].append(entry.header.name)

0 commit comments

Comments
 (0)