Esempio n. 1
0
func (cache *rpcCache) writeFile(target *core.BuildTarget, file string, body []byte) bool {
	out := path.Join(target.OutDir(), file)
	if err := os.MkdirAll(path.Dir(out), core.DirPermissions); err != nil {
		log.Warning("Failed to create directory for artifacts: %s", err)
		return false
	}
	if err := core.WriteFile(bytes.NewReader(body), out, fileMode(target)); err != nil {
		log.Warning("RPC cache failed to write file %s", err)
		return false
	}
	log.Debug("Retrieved %s - %s from RPC cache", target.Label, file)
	return true
}
Esempio n. 2
0
// StoreArtifact takes in the artifact content and path as parameters and creates a file with
// the given content in the given path.
// The function will return the first error found in the process, or nil if the process is successful.
func (cache *Cache) StoreArtifact(artPath string, key []byte) error {
	log.Info("Storing artifact %s", artPath)
	lock := cache.lockFile(artPath, true, int64(len(key)))
	defer lock.Unlock()

	fullPath := path.Join(cache.rootPath, artPath)
	dirPath := path.Dir(fullPath)
	if err := os.MkdirAll(dirPath, core.DirPermissions); err != nil {
		log.Warning("Couldn't create path %s in http cache: %s", dirPath, err)
		cache.removeAndDeleteFile(artPath, lock)
		os.RemoveAll(dirPath)
		return err
	}
	log.Debug("Writing artifact to %s", fullPath)
	if err := core.WriteFile(bytes.NewReader(key), fullPath, 0); err != nil {
		log.Errorf("Could not create %s artifact: %s", fullPath, err)
		cache.removeAndDeleteFile(artPath, lock)
		return err
	}
	return nil
}