From 09ef4dc2f75e0ac3b6bb87c04e0246618ad7acbd Mon Sep 17 00:00:00 2001 From: Patrice Arruda Date: Fri, 31 Jul 2020 15:49:30 +0000 Subject: [PATCH] Update language to comply with inclusive guidance See https://source.android.com/setup/contribute/respectful-code for reference Bug: 161896447 Test: m diff_target_files Change-Id: I5654ccc5ba9be8cff01689b952d2feaade19ae79 --- cmd/diff_target_files/Android.bp | 4 +- .../{whitelist.go => allow_list.go} | 56 +++++++++---------- .../{whitelist_test.go => allow_list_test.go} | 18 +++--- cmd/diff_target_files/compare.go | 4 +- cmd/diff_target_files/diff_target_files.go | 10 ++-- 5 files changed, 46 insertions(+), 46 deletions(-) rename cmd/diff_target_files/{whitelist.go => allow_list.go} (77%) rename cmd/diff_target_files/{whitelist_test.go => allow_list_test.go} (82%) diff --git a/cmd/diff_target_files/Android.bp b/cmd/diff_target_files/Android.bp index 5397f4b74..bc6b068b9 100644 --- a/cmd/diff_target_files/Android.bp +++ b/cmd/diff_target_files/Android.bp @@ -5,12 +5,12 @@ blueprint_go_binary { "diff_target_files.go", "glob.go", "target_files.go", - "whitelist.go", + "allow_list.go", "zip_artifact.go", ], testSrcs: [ "compare_test.go", "glob_test.go", - "whitelist_test.go", + "allow_list_test.go", ], } diff --git a/cmd/diff_target_files/whitelist.go b/cmd/diff_target_files/allow_list.go similarity index 77% rename from cmd/diff_target_files/whitelist.go rename to cmd/diff_target_files/allow_list.go index f00fc1ee2..ca55b43e1 100644 --- a/cmd/diff_target_files/whitelist.go +++ b/cmd/diff_target_files/allow_list.go @@ -25,18 +25,13 @@ import ( "unicode" ) -type jsonWhitelist struct { - Paths []string - IgnoreMatchingLines []string -} - -type whitelist struct { +type allowList struct { path string ignoreMatchingLines []string } -func parseWhitelists(whitelists []string, whitelistFiles []string) ([]whitelist, error) { - var ret []whitelist +func parseAllowLists(allowLists []string, allowListFiles []string) ([]allowList, error) { + var ret []allowList add := func(path string, ignoreMatchingLines []string) { for _, x := range ret { @@ -46,24 +41,24 @@ func parseWhitelists(whitelists []string, whitelistFiles []string) ([]whitelist, } } - ret = append(ret, whitelist{ + ret = append(ret, allowList{ path: path, ignoreMatchingLines: ignoreMatchingLines, }) } - for _, file := range whitelistFiles { - newWhitelists, err := parseWhitelistFile(file) + for _, file := range allowListFiles { + newAllowlists, err := parseAllowListFile(file) if err != nil { return nil, err } - for _, w := range newWhitelists { + for _, w := range newAllowlists { add(w.path, w.ignoreMatchingLines) } } - for _, s := range whitelists { + for _, s := range allowLists { colon := strings.IndexRune(s, ':') var ignoreMatchingLines []string if colon >= 0 { @@ -75,7 +70,7 @@ func parseWhitelists(whitelists []string, whitelistFiles []string) ([]whitelist, return ret, nil } -func parseWhitelistFile(file string) ([]whitelist, error) { +func parseAllowListFile(file string) ([]allowList, error) { r, err := os.Open(file) if err != nil { return nil, err @@ -84,27 +79,32 @@ func parseWhitelistFile(file string) ([]whitelist, error) { d := json.NewDecoder(newJSONCommentStripper(r)) - var jsonWhitelists []jsonWhitelist + var jsonAllowLists []struct { + Paths []string + IgnoreMatchingLines []string + } - err = d.Decode(&jsonWhitelists) + if err := d.Decode(&jsonAllowLists); err != nil { + return nil, err + } - var whitelists []whitelist - for _, w := range jsonWhitelists { + var allowLists []allowList + for _, w := range jsonAllowLists { for _, p := range w.Paths { - whitelists = append(whitelists, whitelist{ + allowLists = append(allowLists, allowList{ path: p, ignoreMatchingLines: w.IgnoreMatchingLines, }) } } - return whitelists, err + return allowLists, err } -func filterModifiedPaths(l [][2]*ZipArtifactFile, whitelists []whitelist) ([][2]*ZipArtifactFile, error) { +func filterModifiedPaths(l [][2]*ZipArtifactFile, allowLists []allowList) ([][2]*ZipArtifactFile, error) { outer: for i := 0; i < len(l); i++ { - for _, w := range whitelists { + for _, w := range allowLists { if match, err := Match(w.path, l[i][0].Name); err != nil { return l, err } else if match { @@ -126,10 +126,10 @@ outer: return l, nil } -func filterNewPaths(l []*ZipArtifactFile, whitelists []whitelist) ([]*ZipArtifactFile, error) { +func filterNewPaths(l []*ZipArtifactFile, allowLists []allowList) ([]*ZipArtifactFile, error) { outer: for i := 0; i < len(l); i++ { - for _, w := range whitelists { + for _, w := range allowLists { if match, err := Match(w.path, l[i].Name); err != nil { return l, err } else if match && len(w.ignoreMatchingLines) == 0 { @@ -192,18 +192,18 @@ func diffIgnoringMatchingLines(a *ZipArtifactFile, b *ZipArtifactFile, ignoreMat return bytes.Compare(bufA, bufB) == 0, nil } -func applyWhitelists(diff zipDiff, whitelists []whitelist) (zipDiff, error) { +func applyAllowLists(diff zipDiff, allowLists []allowList) (zipDiff, error) { var err error - diff.modified, err = filterModifiedPaths(diff.modified, whitelists) + diff.modified, err = filterModifiedPaths(diff.modified, allowLists) if err != nil { return diff, err } - diff.onlyInA, err = filterNewPaths(diff.onlyInA, whitelists) + diff.onlyInA, err = filterNewPaths(diff.onlyInA, allowLists) if err != nil { return diff, err } - diff.onlyInB, err = filterNewPaths(diff.onlyInB, whitelists) + diff.onlyInB, err = filterNewPaths(diff.onlyInB, allowLists) if err != nil { return diff, err } diff --git a/cmd/diff_target_files/whitelist_test.go b/cmd/diff_target_files/allow_list_test.go similarity index 82% rename from cmd/diff_target_files/whitelist_test.go rename to cmd/diff_target_files/allow_list_test.go index 4b19fdd21..8410e5acc 100644 --- a/cmd/diff_target_files/whitelist_test.go +++ b/cmd/diff_target_files/allow_list_test.go @@ -57,10 +57,10 @@ c var f2 = bytesToZipArtifactFile("dir/f2", nil) -func Test_applyWhitelists(t *testing.T) { +func Test_applyAllowLists(t *testing.T) { type args struct { diff zipDiff - whitelists []whitelist + allowLists []allowList } tests := []struct { name string @@ -74,7 +74,7 @@ func Test_applyWhitelists(t *testing.T) { diff: zipDiff{ onlyInA: []*ZipArtifactFile{f1a, f2}, }, - whitelists: []whitelist{{path: "dir/f1"}}, + allowLists: []allowList{{path: "dir/f1"}}, }, want: zipDiff{ onlyInA: []*ZipArtifactFile{f2}, @@ -86,7 +86,7 @@ func Test_applyWhitelists(t *testing.T) { diff: zipDiff{ onlyInA: []*ZipArtifactFile{f1a, f2}, }, - whitelists: []whitelist{{path: "dir/*"}}, + allowLists: []allowList{{path: "dir/*"}}, }, want: zipDiff{}, }, @@ -96,7 +96,7 @@ func Test_applyWhitelists(t *testing.T) { diff: zipDiff{ modified: [][2]*ZipArtifactFile{{f1a, f1b}}, }, - whitelists: []whitelist{{path: "dir/*"}}, + allowLists: []allowList{{path: "dir/*"}}, }, want: zipDiff{}, }, @@ -106,20 +106,20 @@ func Test_applyWhitelists(t *testing.T) { diff: zipDiff{ modified: [][2]*ZipArtifactFile{{f1a, f1b}}, }, - whitelists: []whitelist{{path: "dir/*", ignoreMatchingLines: []string{"foo: .*"}}}, + allowLists: []allowList{{path: "dir/*", ignoreMatchingLines: []string{"foo: .*"}}}, }, want: zipDiff{}, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got, err := applyWhitelists(tt.args.diff, tt.args.whitelists) + got, err := applyAllowLists(tt.args.diff, tt.args.allowLists) if (err != nil) != tt.wantErr { - t.Errorf("applyWhitelists() error = %v, wantErr %v", err, tt.wantErr) + t.Errorf("Test_applyAllowLists() error = %v, wantErr %v", err, tt.wantErr) return } if !reflect.DeepEqual(got, tt.want) { - t.Errorf("applyWhitelists() = %v, want %v", got, tt.want) + t.Errorf("Test_applyAllowLists() = %v, want %v", got, tt.want) } }) } diff --git a/cmd/diff_target_files/compare.go b/cmd/diff_target_files/compare.go index 00cd9ca10..45b6d6b1c 100644 --- a/cmd/diff_target_files/compare.go +++ b/cmd/diff_target_files/compare.go @@ -21,7 +21,7 @@ import ( // compareTargetFiles takes two ZipArtifacts and compares the files they contain by examining // the path, size, and CRC of each file. -func compareTargetFiles(priZip, refZip ZipArtifact, artifact string, whitelists []whitelist, filters []string) (zipDiff, error) { +func compareTargetFiles(priZip, refZip ZipArtifact, artifact string, allowLists []allowList, filters []string) (zipDiff, error) { priZipFiles, err := priZip.Files() if err != nil { return zipDiff{}, fmt.Errorf("error fetching target file lists from primary zip %v", err) @@ -45,7 +45,7 @@ func compareTargetFiles(priZip, refZip ZipArtifact, artifact string, whitelists // Compare the file lists from both builds diff := diffTargetFilesLists(refZipFiles, priZipFiles) - return applyWhitelists(diff, whitelists) + return applyAllowLists(diff, allowLists) } // zipDiff contains the list of files that differ between two zip files. diff --git a/cmd/diff_target_files/diff_target_files.go b/cmd/diff_target_files/diff_target_files.go index 75bc8ee4e..634565bca 100644 --- a/cmd/diff_target_files/diff_target_files.go +++ b/cmd/diff_target_files/diff_target_files.go @@ -22,8 +22,8 @@ import ( ) var ( - whitelists = newMultiString("whitelist", "whitelist patterns in the form [:]") - whitelistFiles = newMultiString("whitelist_file", "files containing whitelist definitions") + allowLists = newMultiString("allowlist", "allowlist patterns in the form [:]") + allowListFiles = newMultiString("allowlist_file", "files containing allowlist definitions") filters = newMultiString("filter", "filter patterns to apply to files in target-files.zip before comparing") ) @@ -47,9 +47,9 @@ func main() { os.Exit(1) } - whitelists, err := parseWhitelists(*whitelists, *whitelistFiles) + allowLists, err := parseAllowLists(*allowLists, *allowListFiles) if err != nil { - fmt.Fprintf(os.Stderr, "Error parsing whitelists: %v\n", err) + fmt.Fprintf(os.Stderr, "Error parsing allowlists: %v\n", err) os.Exit(1) } @@ -67,7 +67,7 @@ func main() { } defer refZip.Close() - diff, err := compareTargetFiles(priZip, refZip, targetFilesPattern, whitelists, *filters) + diff, err := compareTargetFiles(priZip, refZip, targetFilesPattern, allowLists, *filters) if err != nil { fmt.Fprintf(os.Stderr, "Error comparing zip files: %v\n", err) os.Exit(1)