| OLD | NEW |
| 1 // Copyright 2017 The LUCI Authors. | 1 // Copyright 2017 The LUCI Authors. |
| 2 // | 2 // |
| 3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
| 5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
| 6 // | 6 // |
| 7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 // | 8 // |
| 9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
| 10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
| 13 // limitations under the License. | 13 // limitations under the License. |
| 14 | 14 |
| 15 package common | 15 package common |
| 16 | 16 |
| 17 import ( | 17 import ( |
| 18 "fmt" | 18 "fmt" |
| 19 "os" |
| 19 "path/filepath" | 20 "path/filepath" |
| 20 ) | 21 ) |
| 21 | 22 |
| 22 // FilesystemView provides a filtered "view" of a filesystem. | 23 // FilesystemView provides a filtered "view" of a filesystem. |
| 23 // It translates absolute paths to relative paths based on its configured root p
ath. | 24 // It translates absolute paths to relative paths based on its configured root p
ath. |
| 24 // It also hides any paths which match a blacklist entry. | 25 // It also hides any paths which match a blacklist entry. |
| 25 type FilesystemView struct { | 26 type FilesystemView struct { |
| 26 root string | 27 root string |
| 27 blacklist []string | 28 blacklist []string |
| 28 } | 29 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } | 73 } |
| 73 | 74 |
| 74 return false | 75 return false |
| 75 } | 76 } |
| 76 | 77 |
| 77 // match is equivalent to filepath.Match, but assumes that pattern is valid. | 78 // match is equivalent to filepath.Match, but assumes that pattern is valid. |
| 78 func match(pattern, name string) bool { | 79 func match(pattern, name string) bool { |
| 79 matched, _ := filepath.Match(pattern, name) | 80 matched, _ := filepath.Match(pattern, name) |
| 80 return matched | 81 return matched |
| 81 } | 82 } |
| 83 |
| 84 // WalkFuncSkipFile is a helper for implemenations of filepath.WalkFunc. The |
| 85 // value that it returns may in turn be returned by the WalkFunc implementaiton |
| 86 // to indicate that file should be skipped. |
| 87 func WalkFuncSkipFile(file os.FileInfo) error { |
| 88 if file.IsDir() { |
| 89 return filepath.SkipDir |
| 90 } |
| 91 // If we were to return SkipDir for a file, it would cause |
| 92 // filepath.Walk to skip the file's containing directory, which we do |
| 93 // not want (see https://golang.org/pkg/path/filepath/#WalkFunc). |
| 94 return nil |
| 95 } |
| OLD | NEW |