| 63 | const char * gUserIgnoreAssets = NULL; |
| 64 | |
| 65 | static bool isHidden(const char *root, const char *path) |
| 66 | { |
| 67 | // Patterns syntax: |
| 68 | // - Delimiter is : |
| 69 | // - Entry can start with the flag ! to avoid printing a warning |
| 70 | // about the file being ignored. |
| 71 | // - Entry can have the flag "<dir>" to match only directories |
| 72 | // or <file> to match only files. Default is to match both. |
| 73 | // - Entry can be a simplified glob "<prefix>*" or "*<suffix>" |
| 74 | // where prefix/suffix must have at least 1 character (so that |
| 75 | // we don't match a '*' catch-all pattern.) |
| 76 | // - The special filenames "." and ".." are always ignored. |
| 77 | // - Otherwise the full string is matched. |
| 78 | // - match is not case-sensitive. |
| 79 | |
| 80 | if (strcmp(path, ".") == 0 || strcmp(path, "..") == 0) { |
| 81 | return true; |
| 82 | } |
| 83 | |
| 84 | const char *delim = ":"; |
| 85 | const char *p = gUserIgnoreAssets; |
| 86 | if (!p || !p[0]) { |
| 87 | p = getenv("ANDROID_AAPT_IGNORE"); |
| 88 | } |
| 89 | if (!p || !p[0]) { |
| 90 | p = gDefaultIgnoreAssets; |
| 91 | } |
| 92 | char *patterns = strdup(p); |
| 93 | |
| 94 | bool ignore = false; |
| 95 | bool chatty = true; |
| 96 | char *matchedPattern = NULL; |
| 97 | |
| 98 | String8 fullPath(root); |
| 99 | fullPath.appendPath(path); |
| 100 | FileType type = getFileType(fullPath); |
| 101 | |
| 102 | int plen = strlen(path); |
| 103 | |
| 104 | // Note: we don't have strtok_r under mingw. |
| 105 | for(char *token = strtok(patterns, delim); |
| 106 | !ignore && token != NULL; |
| 107 | token = strtok(NULL, delim)) { |
| 108 | chatty = token[0] != '!'; |
| 109 | if (!chatty) token++; // skip ! |
| 110 | if (strncasecmp(token, "<dir>" , 5) == 0) { |
| 111 | if (type != kFileTypeDirectory) continue; |
| 112 | token += 5; |
| 113 | } |
| 114 | if (strncasecmp(token, "<file>", 6) == 0) { |
| 115 | if (type != kFileTypeRegular) continue; |
| 116 | token += 6; |
| 117 | } |
| 118 | |
| 119 | matchedPattern = token; |
| 120 | int n = strlen(token); |
| 121 | |
| 122 | if (token[0] == '*') { |
no test coverage detected