Beispiel #1
0
func SaveBuildGeneralDetails(buildName, buildNumber string) error {
	path, err := GetBuildDir(buildName, buildNumber)
	if err != nil {
		return err
	}
	path += BUILD_INFO_DETAILS
	var exists bool
	exists, err = ioutils.IsFileExists(path)
	if err != nil {
		return err
	}
	if exists {
		return nil
	}
	meta := BuildGeneralDetails{
		Timestamp: time.Now(),
	}
	b, err := json.Marshal(&meta)
	err = cliutils.CheckError(err)
	var content bytes.Buffer
	err = json.Indent(&content, b, "", "  ")
	err = cliutils.CheckError(err)
	if err != nil {
		return err
	}
	err = ioutil.WriteFile(path, []byte(content.String()), 0600)
	return err
}
Beispiel #2
0
func prepareLicenseFile(filepath string, overrideFile bool) (err error) {
	if filepath == "" {
		return
	}
	var dir bool
	dir, err = ioutils.IsDir(filepath)
	if err != nil {
		return
	}
	if dir {
		err = cliutils.CheckError(errors.New(filepath + " is a directory."))
		if err != nil {
			return
		}
	}
	var exists bool
	exists, err = ioutils.IsFileExists(filepath)
	if err != nil {
		return
	}
	if !overrideFile && exists {
		err = cliutils.CheckError(errors.New("File already exist, in case you wish to override the file use --override flag"))
		if err != nil {
			return
		}
	}
	_, directory := ioutils.GetFileAndDirFromPath(filepath)
	isPathExists := ioutils.IsPathExists(directory)
	if !isPathExists {
		os.MkdirAll(directory, 0700)
	}
	err = ioutil.WriteFile(filepath, nil, 0777)
	err = cliutils.CheckError(err)
	return
}
Beispiel #3
0
func saveConfig(config *Config) error {
	b, err := json.Marshal(&config)
	err = cliutils.CheckError(err)
	if err != nil {
		return err
	}
	var content bytes.Buffer
	err = json.Indent(&content, b, "", "  ")
	err = cliutils.CheckError(err)
	if err != nil {
		return err
	}
	path, err := getConFilePath()
	if err != nil {
		return err
	}
	var exists bool
	exists, err = ioutils.IsFileExists(path)
	if err != nil {
		return err
	}
	if exists {
		err := os.Remove(path)
		err = cliutils.CheckError(err)
		if err != nil {
			return err
		}
	}
	path, err = getConFilePath()
	if err != nil {
		return err
	}
	ioutil.WriteFile(path, []byte(content.String()), 0600)
	return nil
}
Beispiel #4
0
func GetFilePath(fileName string) string {
	filePath := GetTestResourcesPath() + "specs/common" + ioutils.GetFileSeperator() + fileName
	isExists, _ := ioutils.IsFileExists(filePath)
	if isExists {
		return filePath
	}
	return getFileByOs(fileName)
}
Beispiel #5
0
func readSshKeyPathFromConsole(details, savedDetails *config.ArtifactoryDetails) error {
	if details.SshKeyPath == "" {
		ioutils.ScanFromConsole("SSH key file path", &details.SshKeyPath, savedDetails.SshKeyPath)
	}

	details.SshKeyPath = cliutils.ReplaceTildeWithUserHome(details.SshKeyPath)
	exists, err := ioutils.IsFileExists(details.SshKeyPath)
	if err != nil {
		return err
	}
	if !exists {
		log.Warn("Could not find SSH key file at:", details.SshKeyPath)
	}
	return nil
}
Beispiel #6
0
func shouldDownloadFile(localFilePath string, remoteFileDetails *ioutils.FileDetails) (bool, error) {
	exists, err := ioutils.IsFileExists(localFilePath)
	if err != nil {
		return false, err
	}
	if !exists {
		return true, nil
	}
	localFileDetails, err := ioutils.GetFileDetails(localFilePath)
	if err != nil {
		return false, err
	}
	if localFileDetails.Sha1 != remoteFileDetails.Sha1 {
		return true, nil
	}
	return false, nil
}
Beispiel #7
0
func shouldDownloadFile(localFilePath, md5, sha1 string) (bool, error) {
	exists, err := ioutils.IsFileExists(localFilePath)
	if err != nil {
		return false, err
	}
	if !exists {
		return true, nil
	}
	localFileDetails, err := ioutils.GetFileDetails(localFilePath)
	if err != nil {
		return false, err
	}
	if localFileDetails.Md5 != md5 || localFileDetails.Sha1 != sha1 {
		return true, nil
	}
	return false, nil
}
Beispiel #8
0
func readConf() (*Config, error) {
	confFilePath, err := getConFilePath()
	if err != nil {
		return nil, err
	}
	config := new(Config)
	exists, err := ioutils.IsFileExists(confFilePath)
	if err != nil {
		return nil, err
	}
	if !exists {
		return config, nil
	}
	content, err := ioutils.ReadFile(confFilePath)
	if err != nil {
		return nil, err
	}
	json.Unmarshal(content, &config)

	return config, nil
}