/// Look for a file from which to parse configuration (nut.yml in current /// directory). Parse the file, and returns an updated context (root directory) /// TODO: look for nut.yml file in parent folders func FindProject(context Utils.Context) (Project, Utils.Context, error) { // var parentProject Project var project Project var err error var newContext Utils.Context var store Persist.Store foundDirectory := context.GetUserDirectory() // fullpath := filepath.Join(foundDirectory, NutFileName) fullpath := filepath.Join(foundDirectory, NutOverrideFileName) previousFoundDirectory := "" var exists bool searchHigher := true found := false for searchHigher == true { if exists, err = Utils.FileExists(fullpath); exists && err == nil { found = true searchHigher = false } else { fullpath = filepath.Join(foundDirectory, NutFileName) if exists, err = Utils.FileExists(fullpath); exists && err == nil { found = true searchHigher = false } else { previousFoundDirectory = foundDirectory foundDirectory = filepath.Dir(foundDirectory) // fullpath = filepath.Join(foundDirectory, NutFileName) fullpath = filepath.Join(foundDirectory, NutOverrideFileName) if foundDirectory == previousFoundDirectory { searchHigher = false } } } } if found { if project, err = LoadProjectFromFile(fullpath); err == nil { log.Debug("Parsed from file: ", fullpath) if newContext, err = Utils.NewContext(foundDirectory, context.GetUserDirectory()); err == nil { log.Debug("Context updated: ", newContext) if store, err = Persist.InitStore(newContext.GetRootDirectory()); err == nil { log.Debug("Store initialized: ", store) if err = ResolveDependencies(project, store, fullpath); err == nil { log.Debug("Resolved dependencies from file: ", fullpath) return project, newContext, err } } } } } else { err = errors.New("Could not find '" + NutFileName + "', neither in current directory nor in its parents.") } return nil, nil, err }
func (self *VolumeV6) getFullContainerPath(context Utils.Context) (string, error) { if self.Container == "" { return "", errors.New("Undefined container path") } else { log.Debug("getFullContainerPath value ", self.Container) clean := containerFilepath.ToSlash(containerFilepath.Clean(self.Container)) log.Debug("getFullContainerPath clean ", clean) if containerFilepath.IsAbs(clean) { log.Debug("getFullContainerPath isAbs") return clean, nil } else { log.Debug("getFullContainerPath is not Abs") log.Debug("getFullContainerPath return ", containerFilepath.Join(context.GetRootDirectory(), clean)) return containerFilepath.Join(context.GetRootDirectory(), clean), nil } } }
func (self *VolumeV6) getFullHostPath(context Utils.Context) (string, error) { if self.Host == "" { return "", errors.New("Undefined host path") } else { log.Debug("getFullHostPath value ", self.Host) res := filepath.Clean(self.Host) log.Debug("getFullHostPath clean ", res) if !filepath.IsAbs(res) { log.Debug("getFullHostPath is not Abs") res = filepath.Join(context.GetRootDirectory(), res) } log.Debug("getFullHostPath value ", res) if strings.Contains(res, `:\`) { // path on windows. Eg: C:\\Users\ log.Debug("getFullHostPath windows ", `:\`) parts := strings.Split(res, `:\`) parts[0] = strings.ToLower(parts[0]) // drive letter should be lower case res = "//" + parts[0] + "/" + filepath.ToSlash(parts[1]) } log.Debug("getFullHostPath res ", res) return res, nil } }