How to test every dir recursively and if all files in specific dir share same uid, gid, mode, capabilities, selabel. run a command if they do.
example contents of file1.txt:
set_metadata("/system/system/vendor/app/mcRegistry/00060308060501020000000000000000.tlbin", "uid", 0, "gid", 0, "mode", 0644, "capabilities", 0x0, "selabel", "u:object_r:mobicore_file:s0");
set_metadata("/system/system/vendor/app/mcRegistry/ffffffffd00000000000000000000062.tlbin", "uid", 0, "gid", 0, "mode", 0644, "capabilities", 0x0, "selabel", "u:object_r:mobicore_file:s0");
set_metadata("/system/system/vendor/app/mcRegistry", "uid", 0, "gid", 0, "mode", 0755, "capabilities", 0x0, "selabel", "u:object_r:mobicore_file:s0");
Wanted output:
set_metadata("/system/system/vendor/app/mcRegistry", "uid", 0, "gid", 0, "dmode", 0755, "fmode", 0644, "capabilities", 0x0, "selabel", "u:object_r:mobicore_file:s0");
So basically if all share common uid, gid, mode, rewrite the full directory, rename its mode to dmode, save all the files common mode add it as fmode
also I am using https://github.com/cubinator/ext4/blob/master/ext4.py35.py library to check all this.
How would I do it. It's too difficult for me. I managed to rename "mode" to "dmode"
with re.sub
and thats about it nothing else.
EDIT: assume you can get the uid of file with {uid}
and same goes for gid etc.
EDIT2: I find directories with
import glob
files = glob.glob("system" + '/**/*', recursive=True)
A common and simple method for checking if all items in some collection share the same values over a set of attributes is to collect these attributes (UID, GID, etc.) in a tuple
, for each item in the collection, and insert that tuple into a set
. After you finish iterating over all the items, check if the set is exactly of size 1. If it is, that means all the items have the same values over the observed attributes.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.