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:42 UTC
[2/2] incubator-mynewt-newt git commit: newt - Allow symlinked
directories.
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
}