Example #1
0
func inspectInstance(inst local.PackageInstance, listFiles bool) {
	log.Infof("Instance: %s", inst.Pin())
	if listFiles {
		log.Infof("Package files:")
		for _, f := range inst.Files() {
			if f.Symlink() {
				target, err := f.SymlinkTarget()
				if err != nil {
					log.Infof(" E %s (%s)", f.Name(), err)
				} else {
					log.Infof(" S %s -> %s", f.Name(), target)
				}
			} else {
				log.Infof(" F %s", f.Name())
			}
		}
	}
}
Example #2
0
func (client *clientImpl) FetchAndDeployInstance(pin common.Pin) error {
	err := common.ValidatePin(pin)
	if err != nil {
		return err
	}

	// Use temp file for storing package file. Delete it when done.
	var instance local.PackageInstance
	f, err := client.deployer.TempFile(pin.InstanceID)
	if err != nil {
		return err
	}
	defer func() {
		// Instance takes ownership of the file, no need to close it separately.
		if instance == nil {
			f.Close()
		}
		os.Remove(f.Name())
	}()

	// Fetch the package data to the provided storage.
	err = client.FetchInstance(pin, f)
	if err != nil {
		return err
	}

	// Open the instance, verify the instance ID.
	instance, err = local.OpenInstance(f, pin.InstanceID)
	if err != nil {
		return err
	}
	defer instance.Close()

	// Deploy it. 'defer' will take care of removing the temp file if needed.
	_, err = client.deployer.DeployInstance(instance)
	return err
}
Example #3
0
func (client *clientImpl) RegisterInstance(instance local.PackageInstance) error {
	// Attempt to register.
	client.Logger.Infof("cipd: registering %s", instance.Pin())
	result, err := client.remote.registerInstance(instance.Pin())
	if err != nil {
		return err
	}

	// Asked to upload the package file to CAS first?
	if result.uploadSession != nil {
		err = client.UploadToCAS(instance.Pin().InstanceID, instance.DataReader(), result.uploadSession)
		if err != nil {
			return err
		}
		// Try again, now that file is uploaded.
		client.Logger.Infof("cipd: registering %s", instance.Pin())
		result, err = client.remote.registerInstance(instance.Pin())
		if err != nil {
			return err
		}
		if result.uploadSession != nil {
			return ErrBadUpload
		}
	}

	if result.alreadyRegistered {
		client.Logger.Infof(
			"cipd: instance %s is already registered by %s on %s",
			instance.Pin(), result.registeredBy, result.registeredTs)
	} else {
		client.Logger.Infof("cipd: instance %s was successfully registered", instance.Pin())
	}

	return nil
}