aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git/tree_entry.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2020-02-21 23:04:20 +0000
committerGitHub <noreply@github.com>2020-02-21 17:04:20 -0600
commitc8d1c3812980573eae0a1ecd5e84c8b44457c3e4 (patch)
tree29ea510382c64bd6355588a8ac03255425338f33 /modules/git/tree_entry.go
parent6b019724f3294fd04b9a7c4d3a3e60107977eb64 (diff)
downloadgitea-c8d1c3812980573eae0a1ecd5e84c8b44457c3e4.tar.gz
gitea-c8d1c3812980573eae0a1ecd5e84c8b44457c3e4.zip
Render READMEs in docs/ .gitea or .github from root (#10361)
* Render READMEs in docs/ .gitea or .github from root
Diffstat (limited to 'modules/git/tree_entry.go')
-rw-r--r--modules/git/tree_entry.go32
1 files changed, 32 insertions, 0 deletions
diff --git a/modules/git/tree_entry.go b/modules/git/tree_entry.go
index 4e18cc8ead..75ff37048e 100644
--- a/modules/git/tree_entry.go
+++ b/modules/git/tree_entry.go
@@ -167,6 +167,38 @@ func (te *TreeEntry) FollowLink() (*TreeEntry, error) {
return target, nil
}
+// FollowLinks returns the entry ultimately pointed to by a symlink
+func (te *TreeEntry) FollowLinks() (*TreeEntry, error) {
+ if !te.IsLink() {
+ return nil, ErrBadLink{te.Name(), "not a symlink"}
+ }
+ entry := te
+ for i := 0; i < 999; i++ {
+ if entry.IsLink() {
+ next, err := entry.FollowLink()
+ if err != nil {
+ return nil, err
+ }
+ if next.ID == entry.ID {
+ return nil, ErrBadLink{
+ entry.Name(),
+ "recursive link",
+ }
+ }
+ entry = next
+ } else {
+ break
+ }
+ }
+ if entry.IsLink() {
+ return nil, ErrBadLink{
+ te.Name(),
+ "too many levels of symbolic links",
+ }
+ }
+ return entry, nil
+}
+
// GetSubJumpablePathName return the full path of subdirectory jumpable ( contains only one directory )
func (te *TreeEntry) GetSubJumpablePathName() string {
if te.IsSubModule() || !te.IsDir() {