You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/11/28 21:58:41 UTC

[1/2] incubator-mynewt-newt git commit: Remove obsolete fn: DescendantDirsOfParent().

Repository: incubator-mynewt-newt
Updated Branches:
  refs/heads/develop 3f78d01db -> 366024fff


Remove obsolete fn: DescendantDirsOfParent().


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/45796e8a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/45796e8a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/45796e8a

Branch: refs/heads/develop
Commit: 45796e8a8fdfca95ef435148e183184084e37465
Parents: 3f78d01
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Nov 28 10:47:59 2016 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Nov 28 10:47:59 2016 -0800

----------------------------------------------------------------------
 newt/vendor/mynewt.apache.org/newt/util/util.go | 38 --------------------
 .../vendor/mynewt.apache.org/newt/util/util.go  | 38 --------------------
 util/util.go                                    | 38 --------------------
 3 files changed, 114 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/45796e8a/newt/vendor/mynewt.apache.org/newt/util/util.go
----------------------------------------------------------------------
diff --git a/newt/vendor/mynewt.apache.org/newt/util/util.go b/newt/vendor/mynewt.apache.org/newt/util/util.go
index 21c67bb..a1b85f2 100644
--- a/newt/vendor/mynewt.apache.org/newt/util/util.go
+++ b/newt/vendor/mynewt.apache.org/newt/util/util.go
@@ -28,7 +28,6 @@ import (
 	"os"
 	"os/exec"
 	"os/signal"
-	"path"
 	"path/filepath"
 	"runtime"
 	"sort"
@@ -269,43 +268,6 @@ func ReadConfig(path string, name string) (*viper.Viper, error) {
 	}
 }
 
-func DescendantDirsOfParent(rootPath string, parentName string, fullPath bool) ([]string, error) {
-	rootPath = path.Clean(rootPath)
-
-	if NodeNotExist(rootPath) {
-		return []string{}, nil
-	}
-
-	children, err := ChildDirs(rootPath)
-	if err != nil {
-		return nil, err
-	}
-
-	dirs := []string{}
-	if path.Base(rootPath) == parentName {
-		for _, child := range children {
-			if fullPath {
-				child = rootPath + "/" + child
-			}
-
-			dirs = append(dirs, child)
-		}
-	} else {
-		for _, child := range children {
-			childPath := rootPath + "/" + child
-			subDirs, err := DescendantDirsOfParent(childPath, parentName,
-				fullPath)
-			if err != nil {
-				return nil, err
-			}
-
-			dirs = append(dirs, subDirs...)
-		}
-	}
-
-	return dirs, nil
-}
-
 // Execute the command specified by cmdStr on the shell and return results
 func ShellCommand(cmdStr string) ([]byte, error) {
 	log.Debug(cmdStr)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/45796e8a/newtmgr/vendor/mynewt.apache.org/newt/util/util.go
----------------------------------------------------------------------
diff --git a/newtmgr/vendor/mynewt.apache.org/newt/util/util.go b/newtmgr/vendor/mynewt.apache.org/newt/util/util.go
index 21c67bb..a1b85f2 100644
--- a/newtmgr/vendor/mynewt.apache.org/newt/util/util.go
+++ b/newtmgr/vendor/mynewt.apache.org/newt/util/util.go
@@ -28,7 +28,6 @@ import (
 	"os"
 	"os/exec"
 	"os/signal"
-	"path"
 	"path/filepath"
 	"runtime"
 	"sort"
@@ -269,43 +268,6 @@ func ReadConfig(path string, name string) (*viper.Viper, error) {
 	}
 }
 
-func DescendantDirsOfParent(rootPath string, parentName string, fullPath bool) ([]string, error) {
-	rootPath = path.Clean(rootPath)
-
-	if NodeNotExist(rootPath) {
-		return []string{}, nil
-	}
-
-	children, err := ChildDirs(rootPath)
-	if err != nil {
-		return nil, err
-	}
-
-	dirs := []string{}
-	if path.Base(rootPath) == parentName {
-		for _, child := range children {
-			if fullPath {
-				child = rootPath + "/" + child
-			}
-
-			dirs = append(dirs, child)
-		}
-	} else {
-		for _, child := range children {
-			childPath := rootPath + "/" + child
-			subDirs, err := DescendantDirsOfParent(childPath, parentName,
-				fullPath)
-			if err != nil {
-				return nil, err
-			}
-
-			dirs = append(dirs, subDirs...)
-		}
-	}
-
-	return dirs, nil
-}
-
 // Execute the command specified by cmdStr on the shell and return results
 func ShellCommand(cmdStr string) ([]byte, error) {
 	log.Debug(cmdStr)

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/45796e8a/util/util.go
----------------------------------------------------------------------
diff --git a/util/util.go b/util/util.go
index 21c67bb..a1b85f2 100644
--- a/util/util.go
+++ b/util/util.go
@@ -28,7 +28,6 @@ import (
 	"os"
 	"os/exec"
 	"os/signal"
-	"path"
 	"path/filepath"
 	"runtime"
 	"sort"
@@ -269,43 +268,6 @@ func ReadConfig(path string, name string) (*viper.Viper, error) {
 	}
 }
 
-func DescendantDirsOfParent(rootPath string, parentName string, fullPath bool) ([]string, error) {
-	rootPath = path.Clean(rootPath)
-
-	if NodeNotExist(rootPath) {
-		return []string{}, nil
-	}
-
-	children, err := ChildDirs(rootPath)
-	if err != nil {
-		return nil, err
-	}
-
-	dirs := []string{}
-	if path.Base(rootPath) == parentName {
-		for _, child := range children {
-			if fullPath {
-				child = rootPath + "/" + child
-			}
-
-			dirs = append(dirs, child)
-		}
-	} else {
-		for _, child := range children {
-			childPath := rootPath + "/" + child
-			subDirs, err := DescendantDirsOfParent(childPath, parentName,
-				fullPath)
-			if err != nil {
-				return nil, err
-			}
-
-			dirs = append(dirs, subDirs...)
-		}
-	}
-
-	return dirs, nil
-}
-
 // Execute the command specified by cmdStr on the shell and return results
 func ShellCommand(cmdStr string) ([]byte, error) {
 	log.Debug(cmdStr)


[2/2] incubator-mynewt-newt git commit: newt - Allow symlinked directories.

Posted by cc...@apache.org.
newt - Allow symlinked directories.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/366024ff
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/366024ff
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/366024ff

Branch: refs/heads/develop
Commit: 366024fff72c647379bba5b7fcfe9a78e81c2e67
Parents: 45796e8
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Nov 28 13:54:49 2016 -0800
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Nov 28 13:54:49 2016 -0800

----------------------------------------------------------------------
 newt/pkg/localpackage.go | 19 +++++++++++++------
 newt/repo/repo.go        | 32 +++++++++++++++++++++++++++++---
 2 files changed, 42 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/366024ff/newt/pkg/localpackage.go
----------------------------------------------------------------------
diff --git a/newt/pkg/localpackage.go b/newt/pkg/localpackage.go
index 26c2252..1db30f8 100644
--- a/newt/pkg/localpackage.go
+++ b/newt/pkg/localpackage.go
@@ -402,11 +402,11 @@ func LocalPackageSpecialName(dirName string) bool {
 
 func ReadLocalPackageRecursive(repo *repo.Repo,
 	pkgList map[string]interfaces.PackageInterface, basePath string,
-	pkgName string) ([]string, error) {
+	pkgName string, searchedMap map[string]struct{}) ([]string, error) {
 
 	var warnings []string
 
-	dirList, err := repo.FilteredSearchList(pkgName)
+	dirList, err := repo.FilteredSearchList(pkgName, searchedMap)
 	if err != nil {
 		return warnings, util.NewNewtError(err.Error())
 	}
@@ -417,7 +417,7 @@ func ReadLocalPackageRecursive(repo *repo.Repo,
 		}
 
 		subWarnings, err := ReadLocalPackageRecursive(repo, pkgList,
-			basePath, filepath.Join(pkgName, name))
+			basePath, filepath.Join(pkgName, name), searchedMap)
 		warnings = append(warnings, subWarnings...)
 		if err != nil {
 			return warnings, err
@@ -459,7 +459,12 @@ func ReadLocalPackages(repo *repo.Repo, basePath string) (
 	pkgMap = &map[string]interfaces.PackageInterface{}
 	warnings = []string{}
 
-	searchPaths, err := repo.FilteredSearchList("")
+	// Keep track of which directories we have traversed.  Prevent infinite
+	// loops caused by symlink cycles by not inspecting the same directory
+	// twice.
+	searchedMap := map[string]struct{}{}
+
+	searchPaths, err := repo.FilteredSearchList("", searchedMap)
 	if err != nil {
 		return
 	}
@@ -472,14 +477,16 @@ func ReadLocalPackages(repo *repo.Repo, basePath string) (
 		}
 
 		var dirList []string
-		if dirList, err = repo.FilteredSearchList(path); err != nil {
+		if dirList, err = repo.FilteredSearchList(
+			path, searchedMap); err != nil {
+
 			return
 		}
 
 		for _, subDir := range dirList {
 			var subWarnings []string
 			subWarnings, err = ReadLocalPackageRecursive(repo, *pkgMap,
-				basePath, filepath.Join(path, subDir))
+				basePath, filepath.Join(path, subDir), searchedMap)
 			warnings = append(warnings, subWarnings...)
 			if err != nil {
 				return

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/366024ff/newt/repo/repo.go
----------------------------------------------------------------------
diff --git a/newt/repo/repo.go b/newt/repo/repo.go
index 159c66d..25c0d94 100644
--- a/newt/repo/repo.go
+++ b/newt/repo/repo.go
@@ -89,7 +89,9 @@ func (r *Repo) ignoreDir(dir string) bool {
 	return false
 }
 
-func (repo *Repo) FilteredSearchList(curPath string) ([]string, error) {
+func (repo *Repo) FilteredSearchList(
+	curPath string, searchedMap map[string]struct{}) ([]string, error) {
+
 	list := []string{}
 
 	path := filepath.Join(repo.Path(), curPath)
@@ -98,11 +100,35 @@ func (repo *Repo) FilteredSearchList(curPath string) ([]string, error) {
 		return list, util.FmtNewtError("failed to read repo \"%s\": %s",
 			repo.Name(), err.Error())
 	}
+
 	for _, dirEnt := range dirList {
-		if !dirEnt.IsDir() {
+		// Resolve symbolic links.
+		entPath := filepath.Join(path, dirEnt.Name())
+		entry, err := os.Stat(entPath)
+		if err != nil {
+			return nil, util.ChildNewtError(err)
+		}
+
+		name := entry.Name()
+		if err != nil {
 			continue
 		}
-		name := dirEnt.Name()
+
+		if !entry.IsDir() {
+			continue
+		}
+
+		// Don't search the same directory twice.  This check is necessary in
+		// case of symlink cycles.
+		absPath, err := filepath.EvalSymlinks(entPath)
+		if err != nil {
+			return nil, util.ChildNewtError(err)
+		}
+		if _, ok := searchedMap[absPath]; ok {
+			continue
+		}
+		searchedMap[absPath] = struct{}{}
+
 		if strings.HasPrefix(name, ".") {
 			continue
 		}