本文整理汇总了Golang中github.com/cloudfoundry/gofileutils/fileutils.CopyPathToPath函数的典型用法代码示例。如果您正苦于以下问题:Golang CopyPathToPath函数的具体用法?Golang CopyPathToPath怎么用?Golang CopyPathToPath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CopyPathToPath函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: copyUploadableFiles
func (actor PushActorImpl) copyUploadableFiles(appDir string, uploadDir string) (presentFiles []resources.AppFileResource, hasFileToUpload bool, err error) {
// Find which files need to be uploaded
allAppFiles, err := actor.appfiles.AppFilesInDir(appDir)
if err != nil {
return
}
appFilesToUpload, presentFiles, apiErr := actor.getFilesToUpload(allAppFiles)
if apiErr != nil {
err = errors.New(apiErr.Error())
return
}
hasFileToUpload = len(appFilesToUpload) > 0
// Copy files into a temporary directory and return it
err = actor.appfiles.CopyFiles(appFilesToUpload, appDir, uploadDir)
if err != nil {
return
}
// copy cfignore if present
fileutils.CopyPathToPath(filepath.Join(appDir, ".cfignore"), filepath.Join(uploadDir, ".cfignore")) //error handling?
return
}
示例2: GatherFiles
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 {
fileInfo, err := os.Lstat(filepath.Join(appDir, remoteFiles[i].Path))
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
}
示例3: installPlugin
func (cmd *PluginInstall) installPlugin(pluginMetadata *plugin.PluginMetadata, pluginDestinationFilepath, pluginSourceFilepath string) {
err := fileutils.CopyPathToPath(pluginSourceFilepath, pluginDestinationFilepath)
if err != nil {
cmd.ui.Failed(fmt.Sprintf(T("Could not copy plugin binary: \n{{.Error}}", map[string]interface{}{"Error": err.Error()})))
}
configMetadata := plugin_config.PluginMetadata{
Location: pluginDestinationFilepath,
Version: pluginMetadata.Version,
Commands: pluginMetadata.Commands,
}
cmd.pluginConfig.SetPlugin(pluginMetadata.Name, configMetadata)
}
示例4: CopyFiles
func CopyFiles(appFiles []models.AppFileFields, fromDir, toDir string) (err error) {
if err != nil {
return
}
for _, file := range appFiles {
fromPath := filepath.Join(fromDir, file.Path)
toPath := filepath.Join(toDir, file.Path)
err = fileutils.CopyPathToPath(fromPath, toPath)
if err != nil {
return
}
}
return
}
示例5: installPlugin
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
}
示例6: UploadApp
func (repo CloudControllerApplicationBitsRepository) UploadApp(appGuid string, appDir string, fileSizePrinter func(path string, zipSize, fileCount int64)) (apiErr error) {
fileutils.TempDir("apps", func(uploadDir string, err error) {
if err != nil {
apiErr = err
return
}
var presentFiles []resources.AppFileResource
repo.sourceDir(appDir, func(sourceDir string, sourceErr error) {
if sourceErr != nil {
err = sourceErr
return
}
presentFiles, err = repo.copyUploadableFiles(sourceDir, uploadDir)
if err != nil {
return
}
// copy cfignore if present
fileutils.CopyPathToPath(filepath.Join(sourceDir, ".cfignore"), filepath.Join(uploadDir, ".cfignore"))
})
if err != nil {
apiErr = err
return
}
fileutils.TempFile("uploads", func(zipFile *os.File, err error) {
if err != nil {
apiErr = err
return
}
zipFileSize := int64(0)
zipFileCount := int64(0)
err = repo.zipper.Zip(uploadDir, zipFile)
switch err := err.(type) {
case nil:
stat, err := zipFile.Stat()
if err != nil {
apiErr = errors.NewWithError(T("Error zipping application"), err)
return
}
zipFileSize = int64(stat.Size())
zipFileCount = app_files.CountFiles(uploadDir)
case *errors.EmptyDirError:
zipFile = nil
default:
apiErr = errors.NewWithError(T("Error zipping application"), err)
return
}
fileSizePrinter(appDir, zipFileSize, zipFileCount)
apiErr = repo.uploadBits(appGuid, zipFile, presentFiles)
if apiErr != nil {
return
}
})
})
return
}
示例7:
fileBytes, err := ioutil.ReadFile(filePath)
Expect(err).NotTo(HaveOccurred())
Expect(string(fileBytes)).To(Equal("Never Gonna Let You Down"))
})
})
Describe("CopyPathToPath", func() {
var destPath string
BeforeEach(func() {
destPath = fileutils.TempPath("copy_test")
})
Describe("when the source is a file", func() {
BeforeEach(func() {
err := fileutils.CopyPathToPath(fixturePath, destPath)
Expect(err).NotTo(HaveOccurred())
})
It("copies the file contents", func() {
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() {
fileInfo, err := os.Stat(destPath)
Expect(err).NotTo(HaveOccurred())
示例8:
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")})
})