@@ -56,55 +56,92 @@ static bool validateFileName(const char* fileName)
5656 return true ;
5757}
5858
59+ // The default to use if no other ignore pattern is defined.
60+ const char * const gDefaultIgnoreAssets =
61+ " !.svn:!.git:.*:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*.scc:*~" ;
62+ // The ignore pattern that can be passed via --ignore-assets in Main.cpp
63+ const char * gUserIgnoreAssets = NULL ;
64+
5965static bool isHidden (const char *root, const char *path)
6066{
61- const char *ext = NULL ;
62- const char *type = NULL ;
63-
64- // Skip all hidden files.
65- if (path[0 ] == ' .' ) {
66- // Skip ., .. and .svn but don't chatter about it.
67- if (strcmp (path, " ." ) == 0
68- || strcmp (path, " .." ) == 0
69- || strcmp (path, " .svn" ) == 0 ) {
70- return true ;
71- }
72- type = " hidden" ;
73- } else if (path[0 ] == ' _' ) {
74- // skip directories starting with _ (don't chatter about it)
75- String8 subdirName (root);
76- subdirName.appendPath (path);
77- if (getFileType (subdirName.string ()) == kFileTypeDirectory ) {
78- return true ;
79- }
80- } else if (strcmp (path, " CVS" ) == 0 ) {
81- // Skip CVS but don't chatter about it.
82- return true ;
83- } else if (strcasecmp (path, " thumbs.db" ) == 0
84- || strcasecmp (path, " picasa.ini" ) == 0 ) {
85- // Skip suspected image indexes files.
86- type = " index" ;
87- } else if (path[strlen (path)-1 ] == ' ~' ) {
88- // Skip suspected emacs backup files.
89- type = " backup" ;
90- } else if ((ext = strrchr (path, ' .' )) != NULL && strcmp (ext, " .scc" ) == 0 ) {
91- // Skip VisualSourceSafe files and don't chatter about it
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 ) {
9281 return true ;
93- } else {
94- // Let everything else through.
95- return false ;
9682 }
9783
98- /* If we get this far, "type" should be set and the file
99- * should be skipped.
100- */
101- String8 subdirName (root);
102- subdirName.appendPath (path);
103- fprintf (stderr, " (skipping %s %s '%s')\n " , type,
104- getFileType (subdirName.string ())==kFileTypeDirectory ? " dir" :" file" ,
105- subdirName.string ());
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);
10693
107- return true ;
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 ] == ' *' ) {
123+ // Match *suffix
124+ token++;
125+ if (n <= plen) {
126+ ignore = strncasecmp (token, path + plen - n, n) == 0 ;
127+ }
128+ } else if (n > 1 && token[n - 1 ] == ' *' ) {
129+ // Match prefix*
130+ ignore = strncasecmp (token, path, n - 1 ) == 0 ;
131+ } else {
132+ ignore = strcasecmp (token, path) == 0 ;
133+ }
134+ }
135+
136+ if (ignore && chatty) {
137+ fprintf (stderr, " (skipping %s '%s' due to ANDROID_AAPT_IGNORE pattern '%s')\n " ,
138+ type == kFileTypeDirectory ? " dir" : " file" ,
139+ path,
140+ matchedPattern ? matchedPattern : " " );
141+ }
142+
143+ free (patterns);
144+ return ignore;
108145}
109146
110147// =========================================================================
0 commit comments