diff options
author | Tris Forster <tris.git@tfconsulting.com.au> | 2018-05-01 17:04:36 +1000 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2018-05-01 10:04:36 +0300 |
commit | 85d14cc229263c5788cac9370ac60e9582f9de6c (patch) | |
tree | cd8b7d9505335f86eddfdd3379afb21f414c00c0 /vendor/code.gitea.io | |
parent | 1928920a08e038e1ec0f631b2f84f5610638209f (diff) | |
download | gitea-85d14cc229263c5788cac9370ac60e9582f9de6c.tar.gz gitea-85d14cc229263c5788cac9370ac60e9582f9de6c.zip |
Symlink icons (#1416) (#3826)
* Updated vendor code for code.gitea.io/git
* Display symlinks correctly for files and directories
* Added symlink tests
* Applied silverwinds stylesheet patch
Signed-off-by: Tris Forster <tris.git@shoddynet.org>
Diffstat (limited to 'vendor/code.gitea.io')
-rw-r--r-- | vendor/code.gitea.io/git/MAINTAINERS | 1 | ||||
-rw-r--r-- | vendor/code.gitea.io/git/error.go | 10 | ||||
-rw-r--r-- | vendor/code.gitea.io/git/sha1.go | 29 | ||||
-rw-r--r-- | vendor/code.gitea.io/git/tree_entry.go | 40 |
4 files changed, 56 insertions, 24 deletions
diff --git a/vendor/code.gitea.io/git/MAINTAINERS b/vendor/code.gitea.io/git/MAINTAINERS index 4f3aab3183..8c8a4947dd 100644 --- a/vendor/code.gitea.io/git/MAINTAINERS +++ b/vendor/code.gitea.io/git/MAINTAINERS @@ -18,3 +18,4 @@ Antoine Girard <sapk@sapk.fr> (@sapk) Jonas Östanbäck <jonas.ostanback@gmail.com> (@cez81) David Schneiderbauer <dschneiderbauer@gmail.com> (@daviian) Peter Žeby <morlinest@gmail.com> (@morlinest) +Jonas Franz <info@jonasfranz.software> (@JonasFranzDEV) diff --git a/vendor/code.gitea.io/git/error.go b/vendor/code.gitea.io/git/error.go index 4fd2a5b8fd..1aae5a37a2 100644 --- a/vendor/code.gitea.io/git/error.go +++ b/vendor/code.gitea.io/git/error.go @@ -40,6 +40,16 @@ func (err ErrNotExist) Error() string { return fmt.Sprintf("object does not exist [id: %s, rel_path: %s]", err.ID, err.RelPath) } +// ErrBadLink entry.FollowLink error +type ErrBadLink struct { + Name string + Message string +} + +func (err ErrBadLink) Error() string { + return fmt.Sprintf("%s: %s", err.Name, err.Message) +} + // ErrUnsupportedVersion error when required git version not matched type ErrUnsupportedVersion struct { Required string diff --git a/vendor/code.gitea.io/git/sha1.go b/vendor/code.gitea.io/git/sha1.go index 50708dee8b..6c9d53949d 100644 --- a/vendor/code.gitea.io/git/sha1.go +++ b/vendor/code.gitea.io/git/sha1.go @@ -5,6 +5,7 @@ package git import ( + "bytes" "encoding/hex" "fmt" "strings" @@ -26,43 +27,23 @@ func (id SHA1) Equal(s2 interface{}) bool { } return v == id.String() case []byte: - if len(v) != 20 { - return false - } - for i, v := range v { - if id[i] != v { - return false - } - } + return bytes.Equal(v, id[:]) case SHA1: - for i, v := range v { - if id[i] != v { - return false - } - } + return v == id default: return false } - return true } // String returns string (hex) representation of the Oid. func (id SHA1) String() string { - result := make([]byte, 0, 40) - hexvalues := []byte("0123456789abcdef") - for i := 0; i < 20; i++ { - result = append(result, hexvalues[id[i]>>4]) - result = append(result, hexvalues[id[i]&0xf]) - } - return string(result) + return hex.EncodeToString(id[:]) } // MustID always creates a new SHA1 from a [20]byte array with no validation of input. func MustID(b []byte) SHA1 { var id SHA1 - for i := 0; i < 20; i++ { - id[i] = b[i] - } + copy(id[:], b) return id } diff --git a/vendor/code.gitea.io/git/tree_entry.go b/vendor/code.gitea.io/git/tree_entry.go index 41023010cd..6201eef8fd 100644 --- a/vendor/code.gitea.io/git/tree_entry.go +++ b/vendor/code.gitea.io/git/tree_entry.go @@ -5,6 +5,7 @@ package git import ( + "io" "sort" "strconv" "strings" @@ -90,6 +91,45 @@ func (te *TreeEntry) Blob() *Blob { } } +// FollowLink returns the entry pointed to by a symlink +func (te *TreeEntry) FollowLink() (*TreeEntry, error) { + if !te.IsLink() { + return nil, ErrBadLink{te.Name(), "not a symlink"} + } + + // read the link + r, err := te.Blob().Data() + if err != nil { + return nil, err + } + buf := make([]byte, te.Size()) + _, err = io.ReadFull(r, buf) + if err != nil { + return nil, err + } + + lnk := string(buf) + t := te.ptree + + // traverse up directories + for ; t != nil && strings.HasPrefix(lnk, "../"); lnk = lnk[3:] { + t = t.ptree + } + + if t == nil { + return nil, ErrBadLink{te.Name(), "points outside of repo"} + } + + target, err := t.GetTreeEntryByPath(lnk) + if err != nil { + if IsErrNotExist(err) { + return nil, ErrBadLink{te.Name(), "broken link"} + } + return nil, err + } + return target, nil +} + // GetSubJumpablePathName return the full path of subdirectory jumpable ( contains only one directory ) func (te *TreeEntry) GetSubJumpablePathName() string { if te.IsSubModule() || !te.IsDir() { |