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

Method LinkFromPool

gcs/public.go:231–294  ·  view source on GitHub ↗

LinkFromPool links package file from pool to dist's pool location.

(publishedPrefix, publishedRelPath, fileName string, sourcePool aptly.PackagePool,
	sourcePath string, sourceChecksums utils.ChecksumInfo, force bool)

Source from the content-addressed store, hash-verified

229
230// LinkFromPool links package file from pool to dist's pool location.
231func (g *PublishedStorage) LinkFromPool(publishedPrefix, publishedRelPath, fileName string, sourcePool aptly.PackagePool,
232 sourcePath string, sourceChecksums utils.ChecksumInfo, force bool) error {
233
234 publishedDirectory := filepath.Join(publishedPrefix, publishedRelPath)
235 relPath := filepath.Join(publishedDirectory, fileName)
236 poolPath := filepath.Join(g.prefix, relPath)
237
238 if g.pathCache == nil {
239 paths, md5s, err := g.internalFilelist(filepath.Join(publishedPrefix, "pool"))
240 if err != nil {
241 return errors.Wrap(err, "error caching paths under prefix")
242 }
243
244 g.pathCache = make(map[string]string, len(paths))
245 for i := range paths {
246 g.pathCache[filepath.Join(publishedPrefix, "pool", paths[i])] = md5s[i]
247 }
248 }
249
250 destinationMD5, exists := g.pathCache[relPath]
251 sourceMD5 := strings.ToLower(sourceChecksums.MD5)
252
253 if exists {
254 if sourceMD5 == "" {
255 return fmt.Errorf("unable to compare object, MD5 checksum missing")
256 }
257
258 if len(destinationMD5) != 32 {
259 var err error
260 destinationMD5, err = g.getMD5(relPath)
261 if err != nil {
262 return errors.Wrap(err, fmt.Sprintf("error verifying MD5 for %s: %s", g, poolPath))
263 }
264 g.pathCache[relPath] = destinationMD5
265 }
266
267 if destinationMD5 == sourceMD5 {
268 return nil
269 }
270
271 if !force {
272 return fmt.Errorf("error putting file to %s: file already exists and is different: %s", poolPath, g)
273 }
274 }
275
276 source, err := sourcePool.Open(sourcePath)
277 if err != nil {
278 return err
279 }
280 defer func() { _ = source.Close() }()
281
282 if g.debug {
283 log.Debug().Msgf("GCS: LinkFromPool '%s'", relPath)
284 }
285
286 err = g.putFile(relPath, source, sourceMD5)
287 if err != nil {
288 return errors.Wrap(err, fmt.Sprintf("error uploading %s to %s: %s", sourcePath, g, poolPath))

Calls 5

internalFilelistMethod · 0.95
getMD5Method · 0.95
putFileMethod · 0.95
OpenMethod · 0.65
CloseMethod · 0.65