Ejemplo n.º 1
0
func (cmd *PluginInstall) installPlugin(pluginMetadata *plugin.PluginMetadata, pluginDestinationFilepath, pluginSourceFilepath string) error {
	err := fileutils.CopyPathToPath(pluginSourceFilepath, pluginDestinationFilepath)
	if err != nil {
		return errors.New(T(
			"Could not copy plugin binary: \n{{.Error}}",
			map[string]interface{}{
				"Error": err.Error(),
			}),
		)
	}

	configMetadata := pluginconfig.PluginMetadata{
		Location: pluginDestinationFilepath,
		Version:  pluginMetadata.Version,
		Commands: pluginMetadata.Commands,
	}

	cmd.pluginConfig.SetPlugin(pluginMetadata.Name, configMetadata)
	return nil
}
Ejemplo n.º 2
0
		Describe("when the source is a file", func() {
			var destPath string

			BeforeEach(func() {
				fd, err := ioutil.TempFile("", "copy_test")
				Expect(err).NotTo(HaveOccurred())
				fd.Close()
				destPath = fd.Name()
			})

			AfterEach(func() {
				os.RemoveAll(destPath)
			})

			It("copies the file contents", func() {
				err := fileutils.CopyPathToPath(fixturePath, destPath)
				Expect(err).NotTo(HaveOccurred())
				fileBytes, err := ioutil.ReadFile(destPath)
				Expect(err).NotTo(HaveOccurred())

				fixtureBytes, err := ioutil.ReadFile(fixturePath)
				Expect(err).NotTo(HaveOccurred())
				Expect(fileBytes).To(Equal(fixtureBytes))
			})

			It("preserves the file mode", func() {
				err := fileutils.CopyPathToPath(fixturePath, destPath)
				Expect(err).NotTo(HaveOccurred())
				fileInfo, err := os.Stat(destPath)
				Expect(err).NotTo(HaveOccurred())
Ejemplo n.º 3
0
func (actor PushActorImpl) GatherFiles(localFiles []models.AppFileFields, appDir string, uploadDir string) ([]resources.AppFileResource, bool, error) {
	appFileResource := []resources.AppFileResource{}
	for _, file := range localFiles {
		appFileResource = append(appFileResource, resources.AppFileResource{
			Path: file.Path,
			Sha1: file.Sha1,
			Size: file.Size,
		})
	}

	remoteFiles, err := actor.appBitsRepo.GetApplicationFiles(appFileResource)
	if err != nil {
		return []resources.AppFileResource{}, false, err
	}

	filesToUpload := make([]models.AppFileFields, len(localFiles), len(localFiles))
	copy(filesToUpload, localFiles)

	for _, remoteFile := range remoteFiles {
		for i, fileToUpload := range filesToUpload {
			if remoteFile.Path == fileToUpload.Path {
				filesToUpload = append(filesToUpload[:i], filesToUpload[i+1:]...)
			}
		}
	}

	err = actor.appfiles.CopyFiles(filesToUpload, appDir, uploadDir)
	if err != nil {
		return []resources.AppFileResource{}, false, err
	}

	_, err = os.Stat(filepath.Join(appDir, ".cfignore"))
	if err == nil {
		err = fileutils.CopyPathToPath(filepath.Join(appDir, ".cfignore"), filepath.Join(uploadDir, ".cfignore"))
		if err != nil {
			return []resources.AppFileResource{}, false, err
		}
	}

	for i := range remoteFiles {
		fullPath, err := filepath.Abs(filepath.Join(appDir, remoteFiles[i].Path))
		if err != nil {
			return []resources.AppFileResource{}, false, err
		}

		if runtime.GOOS == "windows" {
			fullPath = windowsPathPrefix + fullPath
		}
		fileInfo, err := os.Lstat(fullPath)
		if err != nil {
			return []resources.AppFileResource{}, false, err
		}
		fileMode := fileInfo.Mode()

		if runtime.GOOS == "windows" {
			fileMode = fileMode | 0700
		}

		remoteFiles[i].Mode = fmt.Sprintf("%#o", fileMode)
	}

	return remoteFiles, len(filesToUpload) > 0, nil
}
Ejemplo n.º 4
0
	BeforeEach(func() {
		ui = &testterm.FakeUI{}
		requirementsFactory = new(requirementsfakes.FakeFactory)

		var err error
		fakePluginRepoDir, err = ioutil.TempDir("", "plugins")
		Expect(err).ToNot(HaveOccurred())

		fixtureDir := filepath.Join("..", "..", "..", "fixtures", "plugins")

		pluginDir = filepath.Join(fakePluginRepoDir, ".cf", "plugins")
		err = os.MkdirAll(pluginDir, 0700)
		Expect(err).NotTo(HaveOccurred())

		fileutils.CopyPathToPath(filepath.Join(fixtureDir, "test_1.exe"), filepath.Join(pluginDir, "test_1.exe"))
		fileutils.CopyPathToPath(filepath.Join(fixtureDir, "test_2.exe"), filepath.Join(pluginDir, "test_2.exe"))

		confighelpers.PluginRepoDir = func() string {
			return fakePluginRepoDir
		}

		pluginPath := filepath.Join(confighelpers.PluginRepoDir(), ".cf", "plugins")
		pluginConfig = pluginconfig.NewPluginConfig(
			func(err error) { Expect(err).ToNot(HaveOccurred()) },
			configuration.NewDiskPersistor(filepath.Join(pluginPath, "config.json")),
			pluginPath,
		)
		pluginConfig.SetPlugin("test_1.exe", pluginconfig.PluginMetadata{Location: filepath.Join(pluginDir, "test_1.exe")})
		pluginConfig.SetPlugin("test_2.exe", pluginconfig.PluginMetadata{Location: filepath.Join(pluginDir, "test_2.exe")})
	})