本文整理匯總了Golang中github.com/bitrise-io/go-utils/pathutil.IsPathExists函數的典型用法代碼示例。如果您正苦於以下問題:Golang IsPathExists函數的具體用法?Golang IsPathExists怎麽用?Golang IsPathExists使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了IsPathExists函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestDownloadPluginBin
func TestDownloadPluginBin(t *testing.T) {
t.Log("example plugin bin - ")
{
pluginBinURL := analyticsPluginBinURL
destinationDir, err := pathutil.NormalizedOSTempDirPath("TestDownloadPluginBin")
require.NoError(t, err)
exist, err := pathutil.IsPathExists(destinationDir)
require.NoError(t, err)
if exist {
err := os.RemoveAll(destinationDir)
require.NoError(t, err)
}
require.NoError(t, os.MkdirAll(destinationDir, 0777))
destinationPth := filepath.Join(destinationDir, "example")
require.NoError(t, downloadPluginBin(pluginBinURL, destinationPth))
exist, err = pathutil.IsPathExists(destinationPth)
require.NoError(t, err)
require.Equal(t, true, exist)
}
}
示例2: validate
func (configs ConfigsModel) validate() (string, error) {
// required
if configs.GradleFile == "" {
return "", errors.New("No GradleFile parameter specified!")
}
if exist, err := pathutil.IsPathExists(configs.GradleFile); err != nil {
return "", fmt.Errorf("Failed to check if GradleFile exist at: %s, error: %s", configs.GradleFile, err)
} else if !exist {
return "", fmt.Errorf("GradleFile not exist at: %s", configs.GradleFile)
}
if configs.GradleTasks == "" {
return "", errors.New("No GradleTask parameter specified!")
}
if configs.GradlewPath == "" {
explanation := `
Using a Gradle Wrapper (gradlew) is required, as the wrapper is what makes sure
that the right Gradle version is installed and used for the build.
You can find more information about the Gradle Wrapper (gradlew),
and about how you can generate one (if you would not have one already
in the official guide at: https://docs.gradle.org/current/userguide/gradle_wrapper.html`
return explanation, errors.New("No GradlewPath parameter specified!")
}
if exist, err := pathutil.IsPathExists(configs.GradlewPath); err != nil {
return "", fmt.Errorf("Failed to check if GradlewPath exist at: %s, error: %s", configs.GradlewPath, err)
} else if !exist {
return "", fmt.Errorf("GradlewPath not exist at: %s", configs.GradlewPath)
}
return "", nil
}
示例3: initBitriseWorkPaths
func initBitriseWorkPaths() error {
bitriseWorkDirPath, err := pathutil.NormalizedOSTempDirPath("bitrise")
if err != nil {
return err
}
if exist, err := pathutil.IsPathExists(bitriseWorkDirPath); err != nil {
return err
} else if !exist {
if err := os.MkdirAll(bitriseWorkDirPath, 0777); err != nil {
return err
}
}
BitriseWorkDirPath = bitriseWorkDirPath
bitriseWorkStepsDirPath, err := filepath.Abs(filepath.Join(BitriseWorkDirPath, "step_src"))
if err != nil {
return err
}
if exist, err := pathutil.IsPathExists(bitriseWorkStepsDirPath); err != nil {
return err
} else if !exist {
if err := os.MkdirAll(bitriseWorkStepsDirPath, 0777); err != nil {
return err
}
}
BitriseWorkStepsDirPath = bitriseWorkStepsDirPath
return nil
}
示例4: isCacheAvailable
func isCacheAvailable(srcDir string) (bool, error) {
carthageDir := filepath.Join(srcDir, carthageDirName)
if exist, err := pathutil.IsPathExists(carthageDir); err != nil {
return false, err
} else if !exist {
return false, nil
}
buildDir := filepath.Join(carthageDir, buildDirName)
if exist, err := pathutil.IsPathExists(buildDir); err != nil {
return false, err
} else if exist {
pattern := filepath.Join(buildDir, "*")
files, err := filepath.Glob(pattern)
if err != nil {
return false, err
}
if len(files) == 0 {
return false, nil
}
} else {
return false, nil
}
// read cahce
cacheContent := ""
cacheFilePth := filepath.Join(srcDir, carthageDirName, cacheFileName)
if exist, err := pathutil.IsPathExists(cacheFilePth); err != nil {
return false, err
} else if exist {
cacheContent, err = fileutil.ReadStringFromFile(cacheFilePth)
if err != nil {
return false, err
}
} else {
return false, nil
}
swiftVersion, err := swiftVersion()
if err != nil {
return false, err
}
resolvedFilePath := filepath.Join(srcDir, resolvedFileName)
resolved, err := contentsOfCartfileResolved(resolvedFilePath)
if err != nil {
return false, err
}
desiredCacheContent := fmt.Sprintf("--Swift version: %s --Swift version \n --%s: %s --%s", swiftVersion, resolvedFileName, resolved, resolvedFileName)
return cacheContent == desiredCacheContent, nil
}
示例5: IsSSHKeypairFileExistInDirectory
// IsSSHKeypairFileExistInDirectory ...
func IsSSHKeypairFileExistInDirectory(workdirPth string) bool {
privFilePath := fullSSHPrivateKeyFilePath(workdirPth)
pubFilePath := fullSSHPublicKeyFilePath(workdirPth)
exists, err := pathutil.IsPathExists(privFilePath)
if !exists || err != nil {
return false
}
exists, err = pathutil.IsPathExists(pubFilePath)
if !exists || err != nil {
return false
}
return true
}
示例6: TestClonePluginSrc
func TestClonePluginSrc(t *testing.T) {
t.Log("example plugin - latest version")
{
pluginSource := examplePluginGitURL
versionTag := ""
destinationDir, err := pathutil.NormalizedOSTempDirPath("TestClonePluginSrc")
require.NoError(t, err)
exist, err := pathutil.IsPathExists(destinationDir)
require.NoError(t, err)
if exist {
err := os.RemoveAll(destinationDir)
require.NoError(t, err)
}
version, hash, err := clonePluginSrc(pluginSource, versionTag, destinationDir)
require.NoError(t, err)
require.NotNil(t, version)
require.NotEmpty(t, hash)
exist, err = pathutil.IsPathExists(destinationDir)
require.NoError(t, err)
require.Equal(t, true, exist)
}
t.Log("example plugin - 0.9.0 version")
{
pluginSource := examplePluginGitURL
versionTag := "0.9.0"
destinationDir, err := pathutil.NormalizedOSTempDirPath("TestClonePluginSrc")
require.NoError(t, err)
exist, err := pathutil.IsPathExists(destinationDir)
require.NoError(t, err)
if exist {
err := os.RemoveAll(destinationDir)
require.NoError(t, err)
}
version, hash, err := clonePluginSrc(pluginSource, versionTag, destinationDir)
require.NoError(t, err)
require.NotNil(t, version)
require.Equal(t, "0.9.0", version.String())
require.NotEmpty(t, hash)
exist, err = pathutil.IsPathExists(destinationDir)
require.NoError(t, err)
require.Equal(t, true, exist)
}
}
示例7: ReadSpecStep
// ReadSpecStep ...
func ReadSpecStep(pth string) (stepmanModels.StepModel, error) {
if isExists, err := pathutil.IsPathExists(pth); err != nil {
return stepmanModels.StepModel{}, err
} else if !isExists {
return stepmanModels.StepModel{}, errors.New(fmt.Sprint("No file found at path", pth))
}
bytes, err := fileutil.ReadBytesFromFile(pth)
if err != nil {
return stepmanModels.StepModel{}, err
}
var stepModel stepmanModels.StepModel
if err := yaml.Unmarshal(bytes, &stepModel); err != nil {
return stepmanModels.StepModel{}, err
}
if err := stepModel.Normalize(); err != nil {
return stepmanModels.StepModel{}, err
}
if err := stepModel.Validate(false); err != nil {
return stepmanModels.StepModel{}, err
}
if err := stepModel.FillMissingDefaults(); err != nil {
return stepmanModels.StepModel{}, err
}
return stepModel, nil
}
示例8: validate
func (configs ConfigsModel) validate() error {
if configs.XamarinSolution == "" {
return errors.New("No XamarinSolution parameter specified!")
}
if exist, err := pathutil.IsPathExists(configs.XamarinSolution); err != nil {
return fmt.Errorf("Failed to check if XamarinSolution exist at: %s, error: %s", configs.XamarinSolution, err)
} else if !exist {
return fmt.Errorf("XamarinSolution not exist at: %s", configs.XamarinSolution)
}
if configs.XamarinConfiguration == "" {
return errors.New("No XamarinConfiguration parameter specified!")
}
if configs.XamarinPlatform == "" {
return errors.New("No XamarinPlatform parameter specified!")
}
if configs.APIKey == "" {
return errors.New("No APIKey parameter specified!")
}
if configs.User == "" {
return errors.New("No User parameter specified!")
}
if configs.Devices == "" {
return errors.New("No Devices parameter specified!")
}
if configs.Series == "" {
return errors.New("No Series parameter specified!")
}
return nil
}
示例9: readRouteMap
func readRouteMap() (SteplibRoutes, error) {
exist, err := pathutil.IsPathExists(getRoutingFilePath())
if err != nil {
return SteplibRoutes{}, err
} else if !exist {
return SteplibRoutes{}, nil
}
bytes, err := fileutil.ReadBytesFromFile(getRoutingFilePath())
if err != nil {
return SteplibRoutes{}, err
}
var routeMap map[string]string
if err := json.Unmarshal(bytes, &routeMap); err != nil {
return SteplibRoutes{}, err
}
routes := []SteplibRoute{}
for key, value := range routeMap {
routes = append(routes, SteplibRoute{
SteplibURI: key,
FolderAlias: value,
})
}
return routes, nil
}
示例10: GetConfigs
// GetConfigs ...
func GetConfigs() (ConfigsModel, error) {
configPth := getEnvmanConfigsFilePath()
defaultConfigs := createDefaultConfigsModel()
if isExist, err := pathutil.IsPathExists(configPth); err != nil {
return ConfigsModel{}, err
} else if !isExist {
return defaultConfigs, nil
}
bytes, err := fileutil.ReadBytesFromFile(configPth)
if err != nil {
return ConfigsModel{}, err
}
type ConfigsFileMode struct {
EnvBytesLimitInKB *int `json:"env_bytes_limit_in_kb,omitempty"`
EnvListBytesLimitInKB *int `json:"env_list_bytes_limit_in_kb,omitempty"`
}
var userConfigs ConfigsFileMode
if err := json.Unmarshal(bytes, &userConfigs); err != nil {
return ConfigsModel{}, err
}
if userConfigs.EnvBytesLimitInKB != nil {
defaultConfigs.EnvBytesLimitInKB = *userConfigs.EnvBytesLimitInKB
}
if userConfigs.EnvListBytesLimitInKB != nil {
defaultConfigs.EnvListBytesLimitInKB = *userConfigs.EnvListBytesLimitInKB
}
return defaultConfigs, nil
}
示例11: destroy
func destroy(c *cli.Context) {
log.Infoln("Destroy")
additionalEnvs, err := config.CreateEnvItemsModelFromSlice(MachineParamsAdditionalEnvs.Get())
if err != nil {
log.Fatalf("Invalid Environment parameter: %s", err)
}
configModel, err := config.ReadMachineConfigFileFromDir(MachineWorkdir.Get(), additionalEnvs)
if err != nil {
log.Fatalln("Failed to read Config file: ", err)
}
isOK, err := pathutil.IsPathExists(path.Join(MachineWorkdir.Get(), "Vagrantfile"))
if err != nil {
log.Fatalln("Failed to check 'Vagrantfile' in the WorkDir: ", err)
}
if !isOK {
log.Fatalln("Vagrantfile not found in the WorkDir!")
}
log.Infof("configModel: %#v", configModel)
if err := doCleanup(configModel, "will-be-destroyed"); err != nil {
log.Fatalf("Failed to Cleanup: %s", err)
}
if err := doDestroy(configModel); err != nil {
log.Fatalf("Failed to Destroy: %s", err)
}
log.Infoln("=> Destroy DONE - OK")
}
示例12: loadBitriseConfig
func loadBitriseConfig() (ConfigModel, error) {
if err := EnsureBitriseConfigDirExists(); err != nil {
return ConfigModel{}, err
}
configPth := getBitriseConfigFilePath()
if exist, err := pathutil.IsPathExists(configPth); err != nil {
return ConfigModel{}, err
} else if !exist {
return ConfigModel{}, nil
}
bytes, err := fileutil.ReadBytesFromFile(configPth)
if err != nil {
return ConfigModel{}, err
}
if len(bytes) == 0 {
return ConfigModel{}, errors.New("empty config file")
}
config := ConfigModel{}
if err := json.Unmarshal(bytes, &config); err != nil {
return ConfigModel{}, fmt.Errorf("failed to marshal config (%s), error: %s", string(bytes), err)
}
return config, nil
}
示例13: WriteStepSpecToFile
// WriteStepSpecToFile ...
func WriteStepSpecToFile(templateCollection models.StepCollectionModel, route SteplibRoute) error {
pth := GetStepSpecPath(route)
if exist, err := pathutil.IsPathExists(pth); err != nil {
log.Error("Failed to check path:", err)
return err
} else if !exist {
dir, _ := path.Split(pth)
err := os.MkdirAll(dir, 0777)
if err != nil {
return err
}
} else {
err := os.Remove(pth)
if err != nil {
return err
}
}
collection, err := generateStepLib(route, templateCollection)
if err != nil {
return err
}
bytes, err := json.MarshalIndent(collection, "", "\t")
if err != nil {
return err
}
return fileutil.WriteBytesToFile(pth, bytes)
}
示例14: PrepareForStepRun
// PrepareForStepRun ...
func (toolkit GoToolkit) PrepareForStepRun(step stepmanModels.StepModel, sIDData models.StepIDData, stepAbsDirPath string) error {
fullStepBinPath := stepBinaryCacheFullPath(sIDData)
// try to use cached binary, if possible
if sIDData.IsUniqueResourceID() {
if exists, err := pathutil.IsPathExists(fullStepBinPath); err != nil {
log.Warn("Failed to check cached binary for step, error: %s", err)
} else if exists {
log.Debugln("No need to compile, binary already exists")
return nil
}
}
// it's not cached, so compile it
if step.Toolkit == nil {
return errors.New("No Toolkit information specified in step")
}
if step.Toolkit.Go == nil {
return errors.New("No Toolkit.Go information specified in step")
}
packageName := step.Toolkit.Go.PackageName
return goBuildInIsolation(packageName, stepAbsDirPath, fullStepBinPath)
}
示例15: gitInitWithRemote
func gitInitWithRemote(cloneIntoDir, repositoryURL string) error {
gitCheckPath := filepath.Join(cloneIntoDir, ".git")
if exist, err := pathutil.IsPathExists(gitCheckPath); err != nil {
return fmt.Errorf("Failed to file path (%s), err: %s", gitCheckPath, err)
} else if exist {
return fmt.Errorf(".git folder already exists in the destination dir (%s)", gitCheckPath)
}
if err := os.MkdirAll(cloneIntoDir, 0777); err != nil {
return fmt.Errorf("Failed to create the clone_destination_dir at: %s", cloneIntoDir)
}
if err := gitInit(cloneIntoDir); err != nil {
return fmt.Errorf("Could not init git repository, err: %s", cloneIntoDir)
}
if err := gitAddRemote(cloneIntoDir, repositoryURL); err != nil {
return fmt.Errorf("Could not add remote, err: %s", err)
}
if err := gitFetch(cloneIntoDir); err != nil {
return fmt.Errorf("Could not fetch from repository, err: %s", err)
}
return nil
}