示例#1
0
// validateFlags ensures that all options passed via the command line are valid
func validateFlags(file string, URL string, directory string) {
	// validatePath ensures that something is at a given path
	validatePath := func(path string) {
		if _, err := os.Stat(path); err != nil {
			wrkutils.CouldntReadError(path, err)
		}
	}
	// validateURL ensures that the given URL is valid, or logs an error
	validateURL := func(urlstr string) {
		if _, err := url.Parse(urlstr); err != nil {
			log.WithFields(log.Fields{
				"url":   urlstr,
				"error": err.Error(),
			}).Fatal("Couldn't parse URL")
		}
	}
	if URL != "" {
		validateURL(URL)
	}
	if directory != "" {
		validatePath(directory)
	}
	if file != "" {
		validatePath(file)
	}
}
示例#2
0
// permissions checks to see if a file's octal permissions match the given set
func permissions(parameters []string) (exitCode int, exitMessage string) {
	path := parameters[0]
	givenMode := parameters[1]
	finfo, err := os.Stat(path)
	if err != nil {
		wrkutils.CouldntReadError(path, err)
	}
	actualMode := fmt.Sprint(finfo.Mode().Perm()) // -rwxrw-r-- format
	if actualMode == givenMode {
		return 0, ""
	}
	msg := "File modes did not match"
	return wrkutils.GenericError(msg, givenMode, []string{actualMode})
}