| 164 | } |
| 165 | |
| 166 | func writeIfDifferent(fs billy.Basic, path string, data []byte) error { |
| 167 | var oldData []byte |
| 168 | |
| 169 | f, err := fs.Open(path) |
| 170 | if err == nil { |
| 171 | defer f.Close() |
| 172 | oldData, _ = io.ReadAll(f) |
| 173 | } |
| 174 | |
| 175 | // Quick check to avoid unneeded writes |
| 176 | if !bytes.Equal(oldData, data) { |
| 177 | return util.WriteFile(fs, path, data, os.ModePerm) |
| 178 | } |
| 179 | |
| 180 | return nil |
| 181 | } |
| 182 | |
| 183 | // hookTemplate is based on a combination of sources, but allows us to run |
| 184 | // multiple hooks from a directory (all of them will always be run) and only |