termux / proot

An chroot-like implementation using ptrace.
https://wiki.termux.com/wiki/PRoot
Other
775 stars 160 forks source link

enhance the link2symlink with one more type of .l2s.* files to track all files hard linked in a hard link group #185

Closed zxq432 closed 3 years ago

zxq432 commented 3 years ago

Problem description

the following is a flat list of the .l2s. file in /.l2s folder, there are total 730 .l2s. files for 365 hard link groups, and 244 of the groups with a regular .l2s.*0001 files associated with 224 files each being the only single hard linked file to each of the .l2s.*0001 files. this kind of wrapper of a single file using link2symlink is really unnecessary for over 2/3 of all hard link groups created.

llocalhost /.l2s # ls -alt .l2s* | wc
    730    7300   65305

localhost /.l2s # ls -alt | grep -v ^l | grep 1$ | wc
    244    2196   18729

after a run of "emaint sync -a", there is a huge file over 1BG: .l2s.tmp_pack_Qe2Jyu0001.0001

localhost /.l2s # ls -alt | head       
total 0
drwxr-xr-x  2 root root     253952 Sep 14 05:36 .
lrwxrwxrwx  1 root root        102 Sep 14 05:36 .l2s.a0001 -> /.l2s/.l2s.a0001.0001
-rw-r--r--  1 root root         29 Sep 14 05:34 .l2s.a0001.0001
lrwxrwxrwx  1 root root        114 Sep 14 03:17 .l2s.tmp_idx_fe4JsQ0001 -> /.l2s/.l2s.tmp_idx_fe4JsQ0001.0001
lrwxrwxrwx  1 root root        114 Sep 14 03:17 .l2s.tmp_pack_Qe2Jyu0001 -> /.l2s/.l2s.tmp_pack_Qe2Jyu0001.0001
-rw-r--r--  1 root root   88636220 Sep 14 03:17 .l2s.tmp_idx_fe4JsQ0001.0001
-rw-r--r--  1 root root 1081614493 Sep 14 03:17 .l2s.tmp_pack_Qe2Jyu0001.0001
drwxr-xr-x 23 root root       3488 Sep 14 03:10 ..
lrwxrwxrwx  1 root root        106 Sep 14 00:43 .l2s.perlbug0002 -> /.l2s/.l2s.perlbug0002.0002

localhost /.l2s # find -L /var/db/repos/gentoo -samefile .l2s.tmp_pack_Qe2Jyu0001.0001 -print -quit
/var/db/repos/gentoo/.git/objects/pack/pack-c70cc34a96b5b66f4f14504b666df6f7003a7417.pack
localhost /.l2s # 

enhancement the proot with a script tool named l2l-clean to get rid of unnecessary links for those having hard link count equql 1 will help. but you have no clue of the original position of the original file. finding out it using "find -L /var /usr /lib -samefile .l2s.tmp_pack_Qe2Jyu0001.0001 -print -quit" will take a long time. with https://github.com/termux/proot/issues/183 PROOT_L2S_ROOT enhancement by a tree structure, it might be easier if the position of the original file was not change, using "find -L /var/db/repos/gentoo -samefile .l2s.tmp_pack_Qe2Jyu0001.0001 -print -quit" with result immediately. but it might fail if the file moved to another folder.

Steps to reproduce

Expected behavior

add one more .l2s.* text or json file with some special suffix '.txt' or '.json' and with the paths of hard linked files as file content, which makes a triplet for one group of hard link, will help tracking all the files hard linked for the link group, and do better for cleaning out the unnecessary links directly in the proot ln hook without adding a cleaning tool.

Additional information

zxq432 commented 3 years ago

this is repeated in 183