@@ -50,38 +50,42 @@ def __setitem__(self, name, value):
5050 self ._update_nlinks (value )
5151
5252 def _update_inodes (self , entry ):
53+ """ Checks if an entry exists with the same inode.
54+
55+ If the inode exists and has entries, check if the data matches.
56+ If it does, it's a hardlink - update the inode list and remove the data.
57+ If it's a file but has no data, treat it as a hardlink and continue.
58+ Otherwise, if the inode exists but the data doesn't match, generate a new inode.
59+
60+ Adds the updated entry to the inode list.
5361 """
54- Checks if an entry exists with the same inode,
55- if it's a hardlink, remove the data in the copy.
56- """
57- if entry .header .ino in self .inodes :
62+ if entry_inodes := self .inodes .get (entry .header .ino , []):
5863 self .logger .log (5 , "[%s] Inode already exists: %s" % (entry .header .name , entry .header .ino ))
64+
5965 # For regular files, check if the existing entry has the same data, if so, clear it before making a hardlink
60- if isinstance (entry , CPIO_File ) and self [self . inodes [ entry . header . ino ] [0 ]].data == entry .data :
66+ if isinstance (entry , CPIO_File ) and self [entry_inodes [0 ]].data == entry .data :
6167 self .logger .info ("[%s] New hardlink detected, removing data." % entry .header .name )
62- # Remove the data from the current entry
68+ # Remove the data from the current entry, as it now links to an existing entry
6369 entry .data = b""
6470 # If it's a file, but has no data, it's already a hardlink
6571 elif isinstance (entry , CPIO_File ) and entry .data == b"" :
72+ # No need to do anything, it's already a hardlink and has no data
6673 self .logger .debug ("[%s] Hardlink detected." % entry .header .name )
67- else :
74+ else : # If there is a collision, generate a new inode
6875 from .common import get_new_inode
6976
7077 if entry .header .ino == 0 and not self .reproducible : # Warn for another inode of 0 for non-reproducible archives
7178 self .logger .warning ("[%s] Inode already exists: %s" % (entry .header .name , entry .header .ino ))
7279
73- old_inode = entry .header .ino
7480 entry .header .ino = get_new_inode (self .inodes )
7581 if self .reproducible :
7682 self .logger .debug ("[%s] Inode recalculated: %s" % (entry .header .name , entry .header .ino ))
7783 else :
7884 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
80- self .inodes [entry .header .ino ] = []
81- if len (self .inodes [old_inode ]) == 0 :
82- del self .inodes [old_inode ]
83- else :
85+
86+ if entry .header .ino not in self .inodes :
8487 self .inodes [entry .header .ino ] = []
88+
8589 self .inodes [entry .header .ino ].append (entry .header .name )
8690
8791 def _update_nlinks (self , entry ):
0 commit comments