Пример #1
0
func (cmd *PluginInstall) tryDownloadPluginBinaryfromGivenPath(pluginSourceFilepath string, downloader fileutils.Downloader) string {
	size, filename, err := downloader.DownloadFile(pluginSourceFilepath)

	if err != nil {
		cmd.ui.Failed(fmt.Sprintf(T("Download attempt failed: {{.Error}}\n\nUnable to install, plugin is not available from the given url.", map[string]interface{}{"Error": err.Error()})))
	}

	cmd.ui.Say(fmt.Sprintf("%d "+T("bytes downloaded")+"...", size))

	executablePath := filepath.Join(downloader.SavePath(), filename)
	os.Chmod(executablePath, 0700)

	return executablePath
}
Пример #2
0
	"io/ioutil"
	"net/http"
	"os"
	"path"

	"github.com/cloudfoundry/cli/fileutils"

	"github.com/onsi/gomega/ghttp"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Downloader", func() {
	var (
		downloader fileutils.Downloader
		tempDir    string
	)

	BeforeEach(func() {
		var err error
		tempDir, err = ioutil.TempDir("", "file-download-test")
		Expect(err).NotTo(HaveOccurred())
		downloader = fileutils.NewDownloader(tempDir)
	})

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

	Describe("DownloadFile", func() {
		var server *ghttp.Server