summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Salyzyn2017-05-02 16:02:17 -0500
committerMark Salyzyn2017-05-18 17:54:31 -0500
commit2d37797b68563f0e6219049ce003c3586e628d8c (patch)
tree178adfada281d0703dcced28db0e0689121255ee /libcutils/fs_config.cpp
parent64e3f88d693054b77fe398cb50bd282e5b6dae00 (diff)
downloadplatform-system-core-2d37797b68563f0e6219049ce003c3586e628d8c.tar.gz
platform-system-core-2d37797b68563f0e6219049ce003c3586e628d8c.tar.xz
platform-system-core-2d37797b68563f0e6219049ce003c3586e628d8c.zip
libcutils: fs_config: alias "system/<partition>/" to "<partition>/"
For the known partitions entrenched in the build system: vendor, oem and odm only. We will alias entries that reference system/<partition> and <partition>/ so that if either are specified, the rule will apply to both possible paths. Test: gTest libcutils-tests Bug: 37703469 Change-Id: Ida9405cbed323489a3d0599c1645e9be2c7b9d08
Diffstat (limited to 'libcutils/fs_config.cpp')
-rw-r--r--libcutils/fs_config.cpp34
1 files changed, 32 insertions, 2 deletions
diff --git a/libcutils/fs_config.cpp b/libcutils/fs_config.cpp
index 2b3443f3f..e08ee707e 100644
--- a/libcutils/fs_config.cpp
+++ b/libcutils/fs_config.cpp
@@ -273,6 +273,36 @@ static int fs_config_open(int dir, int which, const char* target_out_path) {
273 return fd; 273 return fd;
274} 274}
275 275
276// if path is "vendor/<stuff>", "oem/<stuff>" or "odm/<stuff>"
277static bool is_partition(const char* path, size_t len) {
278 static const char* partitions[] = {"vendor/", "oem/", "odm/"};
279 for (size_t i = 0; i < (sizeof(partitions) / sizeof(partitions[0])); ++i) {
280 size_t plen = strlen(partitions[i]);
281 if (len <= plen) continue;
282 if (!strncmp(path, partitions[i], plen)) return true;
283 }
284 return false;
285}
286
287// alias prefixes of "<partition>/<stuff>" to "system/<partition>/<stuff>" or
288// "system/<partition>/<stuff>" to "<partition>/<stuff>"
289static bool prefix_cmp(const char* prefix, const char* path, size_t len) {
290 if (!strncmp(prefix, path, len)) return true;
291
292 static const char system[] = "system/";
293 if (!strncmp(path, system, strlen(system))) {
294 path += strlen(system);
295 } else if (len <= strlen(system)) {
296 return false;
297 } else if (strncmp(prefix, system, strlen(system))) {
298 return false;
299 } else {
300 prefix += strlen(system);
301 len -= strlen(system);
302 }
303 return is_partition(prefix, len) && !strncmp(prefix, path, len);
304}
305
276static bool fs_config_cmp(bool dir, const char* prefix, size_t len, const char* path, size_t plen) { 306static bool fs_config_cmp(bool dir, const char* prefix, size_t len, const char* path, size_t plen) {
277 if (dir) { 307 if (dir) {
278 if (plen < len) { 308 if (plen < len) {
@@ -281,13 +311,13 @@ static bool fs_config_cmp(bool dir, const char* prefix, size_t len, const char*
281 } else { 311 } else {
282 // If name ends in * then allow partial matches. 312 // If name ends in * then allow partial matches.
283 if (prefix[len - 1] == '*') { 313 if (prefix[len - 1] == '*') {
284 return !strncmp(prefix, path, len - 1); 314 return prefix_cmp(prefix, path, len - 1);
285 } 315 }
286 if (plen != len) { 316 if (plen != len) {
287 return false; 317 return false;
288 } 318 }
289 } 319 }
290 return !strncmp(prefix, path, len); 320 return prefix_cmp(prefix, path, len);
291} 321}
292 322
293void fs_config(const char* path, int dir, const char* target_out_path, unsigned* uid, unsigned* gid, 323void fs_config(const char* path, int dir, const char* target_out_path, unsigned* uid, unsigned* gid,