MCPcopy Create free account
hub / github.com/aptly-dev/aptly / Verify

Method Verify

files/package_pool.go:166–227  ·  view source on GitHub ↗

Verify checks whether file exists in the pool and fills back checksum info if poolPath is empty, poolPath is generated automatically based on checksum info (if available) in any case, if function returns true, it also fills back checksums with complete information about the file in the pool

(poolPath, basename string, checksums *utils.ChecksumInfo, checksumStorage aptly.ChecksumStorage)

Source from the content-addressed store, hash-verified

164// if poolPath is empty, poolPath is generated automatically based on checksum info (if available)
165// in any case, if function returns true, it also fills back checksums with complete information about the file in the pool
166func (pool *PackagePool) Verify(poolPath, basename string, checksums *utils.ChecksumInfo, checksumStorage aptly.ChecksumStorage) (string, bool, error) {
167 possiblePoolPaths := []string{}
168
169 if poolPath != "" {
170 possiblePoolPaths = append(possiblePoolPaths, poolPath)
171 } else {
172 // try to guess
173 if checksums.SHA256 != "" {
174 modernPath, err := pool.buildPoolPath(basename, checksums)
175 if err != nil {
176 return "", false, err
177 }
178 possiblePoolPaths = append(possiblePoolPaths, modernPath)
179 }
180
181 if pool.supportLegacyPaths && checksums.MD5 != "" {
182 legacyPath, err := pool.LegacyPath(basename, checksums)
183 if err != nil {
184 return "", false, err
185 }
186 possiblePoolPaths = append(possiblePoolPaths, legacyPath)
187 }
188 }
189
190 for _, path := range possiblePoolPaths {
191 fullPoolPath := filepath.Join(pool.rootPath, path)
192
193 targetInfo, err := os.Stat(fullPoolPath)
194 if err != nil {
195 if !os.IsNotExist(err) {
196 // unable to stat target location?
197 return "", false, err
198 }
199 // doesn't exist, skip it
200 continue
201 }
202
203 if targetInfo.Size() != checksums.Size {
204 // oops, wrong file?
205 continue
206 }
207
208 var targetChecksums *utils.ChecksumInfo
209 targetChecksums, err = pool.ensureChecksums(path, fullPoolPath, checksumStorage)
210
211 if err != nil {
212 return "", false, err
213 }
214
215 if checksums.MD5 != "" && targetChecksums.MD5 != checksums.MD5 ||
216 checksums.SHA256 != "" && targetChecksums.SHA256 != checksums.SHA256 {
217 // wrong file?
218 return "", false, nil
219 }
220
221 // fill back checksums
222 *checksums = *targetChecksums
223 return path, true, nil

Callers

nothing calls this directly

Calls 5

buildPoolPathMethod · 0.95
LegacyPathMethod · 0.95
ensureChecksumsMethod · 0.95
StatMethod · 0.65
SizeMethod · 0.65

Tested by

no test coverage detected