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

Method Import

files/package_pool.go:235–384  ·  view source on GitHub ↗

Import copies file into package pool - srcPath is full path to source file as it is now - basename is desired human-readable name (canonical filename) - checksums are used to calculate file placement - move indicates whether srcPath can be removed

(srcPath, basename string, checksums *utils.ChecksumInfo, move bool, checksumStorage aptly.ChecksumStorage)

Source from the content-addressed store, hash-verified

233// - checksums are used to calculate file placement
234// - move indicates whether srcPath can be removed
235func (pool *PackagePool) Import(srcPath, basename string, checksums *utils.ChecksumInfo, move bool, checksumStorage aptly.ChecksumStorage) (string, error) {
236 pool.Lock()
237 defer pool.Unlock()
238
239 source, err := os.Open(srcPath)
240 if err != nil {
241 return "", err
242 }
243 defer func() {
244 _ = source.Close()
245 }()
246
247 sourceInfo, err := source.Stat()
248 if err != nil {
249 return "", err
250 }
251
252 if checksums.MD5 == "" || checksums.SHA256 == "" || checksums.Size != sourceInfo.Size() {
253 // need to update checksums, MD5 and SHA256 should be always defined
254 *checksums, err = utils.ChecksumsForFile(srcPath)
255 if err != nil {
256 return "", err
257 }
258 }
259
260 // build target path
261 poolPath, err := pool.buildPoolPath(basename, checksums)
262 if err != nil {
263 return "", err
264 }
265
266 fullPoolPath := filepath.Join(pool.rootPath, poolPath)
267
268 targetInfo, err := os.Stat(fullPoolPath)
269 if err != nil {
270 if !os.IsNotExist(err) {
271 // unable to stat target location?
272 return "", err
273 }
274 } else {
275 // target already exists and same size
276 if targetInfo.Size() == sourceInfo.Size() {
277 var targetChecksums *utils.ChecksumInfo
278
279 targetChecksums, err = pool.ensureChecksums(poolPath, fullPoolPath, checksumStorage)
280 if err != nil {
281 return "", err
282 }
283
284 *checksums = *targetChecksums
285 return poolPath, nil
286 }
287
288 // trying to overwrite file?
289 return "", fmt.Errorf("unable to import into pool: file %s already exists", fullPoolPath)
290 }
291
292 if pool.supportLegacyPaths {

Calls 13

buildPoolPathMethod · 0.95
ensureChecksumsMethod · 0.95
LegacyPathMethod · 0.95
ChecksumsForFileFunction · 0.92
CompleteMethod · 0.80
OpenMethod · 0.65
CloseMethod · 0.65
StatMethod · 0.65
SizeMethod · 0.65
LinkMethod · 0.65
UpdateMethod · 0.65
RemoveMethod · 0.65