// Exists checks for codebase existence by using the basic pkg rev Exists() // routine to see if the specified codebase (at any specified rev, or from // the default VCS rev) can be found. If so it'll return the fullest URI // it can to that codebase pkg repo, otherwise an error is returned. // Config file and env var settings can help to find the codebase, ie: // * DVLN_CODEBASE_PATH in env or codebase_path in cfg file // - > space separated list of paths to prepend to the codebase name // - > eg: "github.com/dvln git+ssh://host.com/path/to/clones /some/local/dir" // - - note: 'hub' and 'hub:<uri>' reserved for future user/central dvln hub // - > all values are *always* forward slash regardless of platform // - > 'dvln' as the codebase would result in looking, in order, here: // - > "github.com/dvln/dvln[.git]" // - > "git+ssh://host.com/clone/path/dvln[.git]" // - > "/some/local/dir/dvln[.git]" // - > "dvln" // - > final fallback will be on the individual dvln itself // Based on the above existence checks it'll return: // - string: URI: full path (on filesystem) or URL (if remote), "" if not found // - locality: where it exists (LocalDir, RemoteURL, NonExistent) // - error: any error that is detected in scanning for the workspace func (cb *Defn) Exists(codebaseVerSel string) (string, Locality, error) { //eriknow, make some choices around codebase existence checks... // should be a challenge, that's for sure var err error exists := false if codebaseVerSel != "" { exists, err = file.Exists(codebaseVerSel) } wkspcRootDir := "" if !exists { wkspcRootDir = globs.GetString("wkspcRootDir") } if wkspcRootDir == "" { wkspcRootDir = globs.GetString("dvlnCfgDir") } if codebaseVerSel == "" || !exists || err != nil { if err == nil { out.Debugln("No codebase file to read, skipping (considered normal)") } else { out.Debugf("No codebase file to read, skipping (abnormal, unexpected err: %s)\n", err) } return "", NonExistent, err } return codebaseVerSel, LocalDir, nil }
// OptimizedMatches is basically the same as fileutils.Matches() but optimized for archive.go. // It will assume that the inputs have been preprocessed and therefore the function // doen't need to do as much error checking and clean-up. This was done to avoid // repeating these steps on each file being checked during the archive process. // The more generic fileutils.Matches() can't make these assumptions. func OptimizedMatches(file string, patterns []string, patDirs [][]string) (bool, error) { matched := false parentPath := filepath.Dir(file) parentPathDirs := strings.Split(parentPath, "/") for i, pattern := range patterns { negative := false if exclusion(pattern) { negative = true pattern = pattern[1:] } match, err := filepath.Match(pattern, file) if err != nil { return false, out.WrapErr(err, "Optimized matching, failed to match pattern", 4008) } if !match && parentPath != "." { // Check to see if the pattern matches one of our parent dirs. if len(patDirs[i]) <= len(parentPathDirs) { match, _ = filepath.Match(strings.Join(patDirs[i], "/"), strings.Join(parentPathDirs[:len(patDirs[i])], "/")) } } if match { matched = !negative } } if matched { out.Debugf("Skipping excluded path: %s", file) } return matched, nil }