MCPcopy Index your code
hub / github.com/GoogleContainerTools/container-structure-test / CheckSameFile

Function CheckSameFile

internal/pkgutil/fs_utils.go:146–175  ·  view source on GitHub ↗
(f1name, f2name string)

Source from the content-addressed store, hash-verified

144}
145
146func CheckSameFile(f1name, f2name string) (bool, error) {
147 // Check first if files differ in size and immediately return
148 f1stat, err := os.Lstat(f1name)
149 if err != nil {
150 return false, err
151 }
152 f2stat, err := os.Lstat(f2name)
153 if err != nil {
154 return false, err
155 }
156
157 if f1stat.Size() != f2stat.Size() {
158 return false, nil
159 }
160
161 // Next, check file contents
162 f1, err := ioutil.ReadFile(f1name)
163 if err != nil {
164 return false, err
165 }
166 f2, err := ioutil.ReadFile(f2name)
167 if err != nil {
168 return false, err
169 }
170
171 if !bytes.Equal(f1, f2) {
172 return false, nil
173 }
174 return true, nil
175}
176
177// HasFilepathPrefix checks if the given file path begins with prefix
178func HasFilepathPrefix(path, prefix string) bool {

Callers

nothing calls this directly

Calls 1

ReadFileMethod · 0.65

Tested by

no test coverage detected