--- /usr/lib64/python3.4/site-packages/portage/dbapi/vartree.py.orig 2017-01-13 19:37:12.225969685 +0100 +++ /usr/lib64/python3.4/site-packages/portage/dbapi/vartree.py 2017-01-15 18:56:37.784906406 +0100 @@ -4528,6 +4528,17 @@ mode='w', encoding=_encodings['repo.content'], errors='backslashreplace') + + # open INTEGRITY file (possibly overwriting old one) for recording + # Use atomic_ofstream for automatic coercion of raw bytes to + # unicode, in order to prevent TypeError when writing raw bytes + # to TextIOWrapper with python2. + intfile = atomic_ofstream(_unicode_encode( + os.path.join(self.dbtmpdir, 'INTEGRITY'), + encoding=_encodings['fs'], errors='strict'), + mode='w', encoding=_encodings['repo.content'], + errors='backslashreplace') + # Don't bump mtimes on merge since some application require # preservation of timestamps. This means that the unmerge phase must # check to see if file belongs to an installed instance in the same @@ -4540,7 +4551,7 @@ # we do a first merge; this will recurse through all files in our srcroot but also build up a # "second hand" of symlinks to merge later - if self.mergeme(srcroot, destroot, outfile, secondhand, + if self.mergeme(srcroot, destroot, outfile, intfile, secondhand, self.settings["EPREFIX"].lstrip(os.sep), cfgfiledict, mymtime): return 1 @@ -4552,7 +4563,7 @@ # couldn't get merged will be added to thirdhand. thirdhand = [] - if self.mergeme(srcroot, destroot, outfile, thirdhand, + if self.mergeme(srcroot, destroot, outfile, intfile, thirdhand, secondhand, cfgfiledict, mymtime): return 1 @@ -4566,7 +4577,7 @@ if len(secondhand): # force merge of remaining symlinks (broken or circular; oh well) - if self.mergeme(srcroot, destroot, outfile, None, + if self.mergeme(srcroot, destroot, outfile, intfile, None, secondhand, cfgfiledict, mymtime): return 1 @@ -4577,6 +4588,10 @@ outfile.flush() outfile.close() + #if we opened it, close it + intfile.flush() + intfile.close() + # write out our collection of md5sums if cfgfiledict != cfgfiledict_orig: cfgfiledict.pop("IGNORE", None) @@ -4588,7 +4603,7 @@ return os.EX_OK - def mergeme(self, srcroot, destroot, outfile, secondhand, stufftomerge, cfgfiledict, thismtime): + def mergeme(self, srcroot, destroot, outfile, intfile, secondhand, stufftomerge, cfgfiledict, thismtime): """ This function handles actual merging of the package contents to the livefs. @@ -4600,6 +4615,8 @@ @type destroot: String (Path) @param outfile: File to log operations to @type outfile: File Object + @param intfile: File to log integrity info to + @type intfile: File Object @param secondhand: A set of items to merge in pass two (usually or symlinks that point to non-existing files that may get merged later) @type secondhand: List @@ -4740,6 +4757,26 @@ # confmem rejected this update zing = "---" + srcobj = srcroot+relative_path + destobj = destroot+relative_path + hashtype = self.settings["INTEGRITY_HASH"] + + line = "" + if stat.S_ISREG(mymode): + line = "mode:"+'{:o}'.format(mymode & stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)+" " + if hashtype.lower() == "sha1" or hashtype.lower() == "sha256" or hashtype.lower() == "sha512": + line += hashtype.lower()+":"+portage.checksum.perform_checksum(srcobj, hashtype.upper(), 0)[0]+" " + line += "file:"+destobj+"\n" + elif stat.S_ISDIR(mymode): + if not os.path.exists(destobj): + line = "mode:"+'{:o}'.format(mymode & stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)+" " + line += "file:"+destobj+"\n" + else: #LINK, FIFO, DEV + line = "mode:"+'{:o}'.format(mymode & stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)+" " + line += "file:"+destobj+"\n" + + intfile.write(line) + if stat.S_ISLNK(mymode): # we are merging a symbolic link # Pass in the symlink target in order to bypass the