cached_downloader.go
func (c *cachedDownloader) populateCache(
	logger lager.Logger,
	url *url.URL,
	name string,
	cachingInfo CachingInfoType,
	checksum ChecksumInfoType,
	transformer CacheTransformer,
	cancelChan <-chan struct{},
) (download, bool, int64, error) {
	filename, cachingInfo, err := c.downloader.Download(logger, url, func() (*os.File, error) {
		return ioutil.TempFile(c.uncachedPath, name+"-")
	}, cachingInfo, checksum, cancelChan)
	if err != nil {
		return download{}, false, 0, err
	}

	if filename == "" {
		return download{}, true, 0, nil
	}

	fileInfo, err := os.Stat(filename)
	if err != nil {
		return download{}, false, 0, err
	}
	defer os.Remove(filename)

	cachedFile, err := ioutil.TempFile(c.uncachedPath, "transformed")
	if err != nil {
		return download{}, false, 0, err
	}

	err = cachedFile.Close()
	if err != nil {
		return download{}, false, 0, err
	}

	cachedSize, err := transformer(filename, cachedFile.Name())
	if err != nil {
		return download{}, false, 0, err
	}

	return download{
		path:        cachedFile.Name(),
		size:        cachedSize,
		cachingInfo: cachingInfo,
	}, false, fileInfo.Size(), nil
}
func (c *cachedDownloader) populateCache(
	logger lager.Logger,
	url *url.URL,
	name string,
	cachingInfo CachingInfoType,
	checksum ChecksumInfoType,
	transformer CacheTransformer,
	cancelChan <-chan struct{},
) (download, bool, int64, error) {
	filename, cachingInfo, err := c.downloader.Download(logger, url, func() (*os.File, error) {
		return ioutil.TempFile(c.uncachedPath, name+"-")
	}, cachingInfo, checksum, cancelChan)
	if err != nil {
		return download{}, false, 0, err
	}

	if filename == "" {
		return download{}, true, 0, nil
	}

	fileInfo, err := os.Stat(filename)
	if err != nil {
		return download{}, false, 0, err
	}
	defer os.Remove(filename)

	cachedFile, err := ioutil.TempFile(c.uncachedPath, "transformed")
	if err != nil {
		return download{}, false, 0, err
	}

	err = cachedFile.Close()
	if err != nil {
		return download{}, false, 0, err
	}

	cachedSize, err := transformer(filename, cachedFile.Name())
	if err != nil {
		return download{}, false, 0, err
	}

	return download{
		path:        cachedFile.Name(),
		size:        cachedSize,
		cachingInfo: cachingInfo,
	}, false, fileInfo.Size(), nil
}
func ( c * cachedDownloader ) populateCache ( logger lager . Logger , url * url . URL , name string , cachingInfo CachingInfoType , checksum ChecksumInfoType , transformer CacheTransformer , cancelChan <- chan struct { } , ) ( download , bool , int64 , error ) { filename , cachingInfo , err := c . downloader . Download ( logger , url , func ( ) ( * os . File , error ) { return ioutil . TempFile ( c . uncachedPath , name + " " ) } , cachingInfo , checksum , cancelChan ) if err != nil { return download { } , false , 0 , err } if filename == " " { return download { } , true , 0 , nil } fileInfo , err := os . Stat ( filename ) if err != nil { return download { } , false , 0 , err } defer os . Remove ( filename ) cachedFile , err := ioutil . TempFile ( c . uncachedPath , " " ) if err != nil { return download { } , false , 0 , err } err = cachedFile . Close ( ) if err != nil { return download { } , false , 0 , err } cachedSize , err := transformer ( filename , cachedFile . Name ( ) ) if err != nil { return download { } , false , 0 , err } return download { path : cachedFile . Name ( ) , size : cachedSize , cachingInfo : cachingInfo , } , false , fileInfo . Size ( ) , nil }
// Currently populateCache takes a transformer due to the fact that a fetchCachedDirectory
// uses only a TarTransformer, which overwrites what is currently set. This way one transformer
// can be used to call Fetch and FetchAsDirectory
Currently populateCache takes a transformer due to the fact that a fetchCachedDirectory uses only a TarTransformer which overwrites what is currently set . This way one transformer can be used to call Fetch and FetchAsDirectory