diff --git a/glibc.spec b/glibc.spec index accfa75ae1cad1b68ebca5983db60d96804ee73a..a8db5419b33bf956beb8ddd6aabd8111790e9ea8 100644 --- a/glibc.spec +++ b/glibc.spec @@ -60,7 +60,7 @@ ############################################################################## Name: glibc Version: 2.33 -Release: 2 +Release: 3 Summary: The GNU libc libraries License: %{all_license} URL: http://www.gnu.org/software/glibc/ @@ -72,6 +72,7 @@ Source3: bench.mk Source4: glibc-bench-compare Source5: LanguageList Source6: LicenseList +Source7: replace_same_file_to_hard_link.py Patch0: glibc-1070416.patch Patch1: glibc-c-utf8-locale.patch @@ -481,14 +482,12 @@ make -j1 install_root=$RPM_BUILD_ROOT install -C build-%{target} pushd build-%{target} -# notice: we can't use parallel compilation because the localedata will use "localedef" command -# to create locales such as LC_CTYPE, LC_TIME etc, and this command will create a file, -# or create a hard link if there already has a output file who's input is the same, -# so when we use parallel compilation, it will lead to different results, and this will cause BEP inconsistence. -make -j1 install_root=$RPM_BUILD_ROOT \ +make %{?_smp_mflags} install_root=$RPM_BUILD_ROOT \ install-locale-files -C ../localedata objdir=`pwd` popd +python3 %{SOURCE7} $PRM_BUILD_ROOT/usr/lib/locale + rm -f $RPM_BUILD_ROOT/%{_libdir}/libNoVersion* rm -f $RPM_BUILD_ROOT/%{_lib}/libNoVersion* rm -f $RPM_BUILD_ROOT/%{_lib}/libnss1-* @@ -1171,6 +1170,10 @@ fi %doc hesiod/README.hesiod %changelog +* Tue Apr 27 2021 xuhuijie - 2.33-3 +- Fix locales BEP inconsistence, use python to replace same file + to hard link + * Wed Apr 7 2021 xieliuhua - 2.33-2 - Fix-the-inaccuracy-of-j0f-j1f-y0f-y1f-BZ.patch diff --git a/replace_same_file_to_hard_link.py b/replace_same_file_to_hard_link.py new file mode 100644 index 0000000000000000000000000000000000000000..12829f0d827c7f3b4cdac0158de7ffee4b31b738 --- /dev/null +++ b/replace_same_file_to_hard_link.py @@ -0,0 +1,98 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +""" +function: This script resolves locales's BEP inconsistence, + it scans a specific path and replaces the same file + in that path with a hard link.Avoid different language + packs each time due to concurrent compilation. +""" +import os +import sys +import time + +all_file = {} + +def cmp_file(f1, f2): + """compare two files in bytes""" + st1 = os.stat(f1) + st2 = os.stat(f2) + + bufsize = 8 * 1024 + with open(f1, 'rb') as fp1, open(f2, 'rb') as fp2: + while True: + b1 = fp1.read(bufsize) + b2 = fp2.read(bufsize) + if b1 != b2: + return False + if not b1: + return True + + +def search_all_inode(dir_path): + """recursively traverse the directory to group all""" + files = os.listdir(dir_path) + + for fi in files: + fi_d = os.path.join(dir_path, fi) + if os.path.isdir(fi_d): + search_all_inode(fi_d) + else: + size = os.stat(fi_d).st_size + if size in all_file: + all_file[size].append(fi_d) + else: + all_file[size] = [fi_d] + + +def deal_one(file_paths): + """traverse the file array, delete the same file and create a hard link""" + file_count = len(file_paths) + inode_files = {} + + for i in range(0, file_count): + for j in range(i + 1, file_count): + file1 = file_paths[i] + file2 = file_paths[j] + + file1_inode = os.stat(file1).st_ino + file2_inode = os.stat(file2).st_ino + + if file1_inode not in inode_files: + inode_files[file1_inode] = file1 + + if file1_inode == file2_inode: + continue + + if cmp_file(file1, file2): + print('deal same file:', file1, '==', file2) + os.remove(file2) + os.link(file1, file2) + else: + if file2_inode not in inode_files: + inode_files[file2_inode] = file2 + + +def deal_files(): + """get file array and processed one by one""" + for size in all_file: + file_paths = all_file[size] + if len(file_paths) > 1: + deal_one(file_paths) + + +def usage(): + """print usage""" + print(""" +rm_same_file: Replace the same file with a hard link. + +rm_same_file.py [target path] + + """) + +if __name__ == "__main__": + if len(sys.argv) == 2: + search_all_inode(sys.argv[1]) + deal_files() + else: + usage() + sys.exit()