summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
author6543 <6543@obermui.de>2020-12-25 09:59:32 +0000
committerGitHub <noreply@github.com>2020-12-25 11:59:32 +0200
commita19447aed128ecadfcd938d6a80cd4951af1f4ce (patch)
tree6312bf946d601aab29731645a4777feeaea66036 /modules
parent04ae0f2f3f4556c6d0b4adc5f2cffd0cc7d25151 (diff)
downloadgitea-a19447aed128ecadfcd938d6a80cd4951af1f4ce.tar.gz
gitea-a19447aed128ecadfcd938d6a80cd4951af1f4ce.zip
migrate from com.* to alternatives (#14103)
* remove github.com/unknwon/com from models * dont use "com.ToStr()" * replace "com.ToStr" with "fmt.Sprint" where its easy to do * more refactor * fix test * just "proxy" Copy func for now * as per @lunny
Diffstat (limited to 'modules')
-rw-r--r--modules/base/tool.go9
-rw-r--r--modules/convert/convert.go6
-rw-r--r--modules/git/repo.go21
-rw-r--r--modules/ssh/ssh.go5
-rw-r--r--modules/util/compare.go23
-rw-r--r--modules/util/copy.go20
6 files changed, 58 insertions, 26 deletions
diff --git a/modules/base/tool.go b/modules/base/tool.go
index 00b13f76c7..7ac572b85b 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -26,7 +26,6 @@ import (
"code.gitea.io/gitea/modules/setting"
"github.com/dustin/go-humanize"
- "github.com/unknwon/com"
)
// EncodeMD5 encodes string to md5 hex value.
@@ -86,8 +85,8 @@ func VerifyTimeLimitCode(data string, minutes int, code string) bool {
// split code
start := code[:12]
lives := code[12:18]
- if d, err := com.StrTo(lives).Int(); err == nil {
- minutes = d
+ if d, err := strconv.ParseInt(lives, 10, 0); err == nil {
+ minutes = int(d)
}
// right active code
@@ -131,7 +130,7 @@ func CreateTimeLimitCode(data string, minutes int, startInf interface{}) string
// create sha1 encode string
sh := sha1.New()
- _, _ = sh.Write([]byte(data + setting.SecretKey + startStr + endStr + com.ToStr(minutes)))
+ _, _ = sh.Write([]byte(fmt.Sprintf("%s%s%s%s%d", data, setting.SecretKey, startStr, endStr, minutes)))
encoded := hex.EncodeToString(sh.Sum(nil))
code := fmt.Sprintf("%s%06d%s", startStr, minutes, encoded)
@@ -223,7 +222,7 @@ func TruncateString(str string, limit int) string {
func StringsToInt64s(strs []string) ([]int64, error) {
ints := make([]int64, len(strs))
for i := range strs {
- n, err := com.StrTo(strs[i]).Int64()
+ n, err := strconv.ParseInt(strs[i], 10, 64)
if err != nil {
return ints, err
}
diff --git a/modules/convert/convert.go b/modules/convert/convert.go
index 63dd072fc4..109931dbc3 100644
--- a/modules/convert/convert.go
+++ b/modules/convert/convert.go
@@ -17,8 +17,6 @@ import (
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/webhook"
-
- "github.com/unknwon/com"
)
// ToEmail convert models.EmailAddress to api.Email
@@ -169,7 +167,7 @@ func ToPublicKey(apiLink string, key *models.PublicKey) *api.PublicKey {
return &api.PublicKey{
ID: key.ID,
Key: key.Content,
- URL: apiLink + com.ToStr(key.ID),
+ URL: fmt.Sprintf("%s%d", apiLink, key.ID),
Title: key.Name,
Fingerprint: key.Fingerprint,
Created: key.CreatedUnix.AsTime(),
@@ -263,7 +261,7 @@ func ToDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey {
KeyID: key.KeyID,
Key: key.Content,
Fingerprint: key.Fingerprint,
- URL: apiLink + com.ToStr(key.ID),
+ URL: fmt.Sprintf("%s%d", apiLink, key.ID),
Title: key.Name,
Created: key.CreatedUnix.AsTime(),
ReadOnly: key.Mode == models.AccessModeRead, // All deploy keys are read-only.
diff --git a/modules/git/repo.go b/modules/git/repo.go
index e824dcc3f2..515899ab04 100644
--- a/modules/git/repo.go
+++ b/modules/git/repo.go
@@ -15,8 +15,6 @@ import (
"strconv"
"strings"
"time"
-
- "github.com/unknwon/com"
)
// GPGSettings represents the default GPG settings for this repository
@@ -309,21 +307,24 @@ func parseSize(objects string) *CountObject {
for _, line := range strings.Split(objects, "\n") {
switch {
case strings.HasPrefix(line, statCount):
- repoSize.Count = com.StrTo(line[7:]).MustInt64()
+ repoSize.Count, _ = strconv.ParseInt(line[7:], 10, 64)
case strings.HasPrefix(line, statSize):
- repoSize.Size = com.StrTo(line[6:]).MustInt64() * 1024
+ repoSize.Size, _ = strconv.ParseInt(line[6:], 10, 64)
+ repoSize.Size *= 1024
case strings.HasPrefix(line, statInpack):
- repoSize.InPack = com.StrTo(line[9:]).MustInt64()
+ repoSize.InPack, _ = strconv.ParseInt(line[9:], 10, 64)
case strings.HasPrefix(line, statPacks):
- repoSize.Packs = com.StrTo(line[7:]).MustInt64()
+ repoSize.Packs, _ = strconv.ParseInt(line[7:], 10, 64)
case strings.HasPrefix(line, statSizePack):
- repoSize.SizePack = com.StrTo(line[11:]).MustInt64() * 1024
+ repoSize.Count, _ = strconv.ParseInt(line[11:], 10, 64)
+ repoSize.Count *= 1024
case strings.HasPrefix(line, statPrunePackage):
- repoSize.PrunePack = com.StrTo(line[16:]).MustInt64()
+ repoSize.PrunePack, _ = strconv.ParseInt(line[16:], 10, 64)
case strings.HasPrefix(line, statGarbage):
- repoSize.Garbage = com.StrTo(line[9:]).MustInt64()
+ repoSize.Garbage, _ = strconv.ParseInt(line[9:], 10, 64)
case strings.HasPrefix(line, statSizeGarbage):
- repoSize.SizeGarbage = com.StrTo(line[14:]).MustInt64() * 1024
+ repoSize.SizeGarbage, _ = strconv.ParseInt(line[14:], 10, 64)
+ repoSize.SizeGarbage *= 1024
}
}
return repoSize
diff --git a/modules/ssh/ssh.go b/modules/ssh/ssh.go
index 4ba52d5653..2b7fd593b5 100644
--- a/modules/ssh/ssh.go
+++ b/modules/ssh/ssh.go
@@ -25,7 +25,6 @@ import (
"code.gitea.io/gitea/modules/util"
"github.com/gliderlabs/ssh"
- "github.com/unknwon/com"
gossh "golang.org/x/crypto/ssh"
)
@@ -58,13 +57,13 @@ func getExitStatusFromError(err error) int {
}
func sessionHandler(session ssh.Session) {
- keyID := session.Context().Value(giteaKeyID).(int64)
+ keyID := fmt.Sprintf("%d", session.Context().Value(giteaKeyID).(int64))
command := session.RawCommand()
log.Trace("SSH: Payload: %v", command)
- args := []string{"serv", "key-" + com.ToStr(keyID), "--config=" + setting.CustomConf}
+ args := []string{"serv", "key-" + keyID, "--config=" + setting.CustomConf}
log.Trace("SSH: Arguments: %v", args)
cmd := exec.Command(setting.AppPath, args...)
cmd.Env = append(
diff --git a/modules/util/compare.go b/modules/util/compare.go
index d4f77aed3b..cd9ba0d91c 100644
--- a/modules/util/compare.go
+++ b/modules/util/compare.go
@@ -4,7 +4,10 @@
package util
-import "sort"
+import (
+ "sort"
+ "strings"
+)
// Int64Slice attaches the methods of Interface to []int64, sorting in increasing order.
type Int64Slice []int64
@@ -36,10 +39,22 @@ func ExistsInSlice(target string, slice []string) bool {
}
// IsStringInSlice sequential searches if string exists in slice.
-func IsStringInSlice(target string, slice []string) bool {
+func IsStringInSlice(target string, slice []string, insensitive ...bool) bool {
+ caseInsensitive := false
+ if len(insensitive) != 0 && insensitive[0] {
+ caseInsensitive = true
+ target = strings.ToLower(target)
+ }
+
for i := 0; i < len(slice); i++ {
- if slice[i] == target {
- return true
+ if caseInsensitive {
+ if strings.ToLower(slice[i]) == target {
+ return true
+ }
+ } else {
+ if slice[i] == target {
+ return true
+ }
}
}
return false
diff --git a/modules/util/copy.go b/modules/util/copy.go
new file mode 100644
index 0000000000..46765849dc
--- /dev/null
+++ b/modules/util/copy.go
@@ -0,0 +1,20 @@
+// Copyright 2020 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package util
+
+import (
+ "github.com/unknwon/com"
+)
+
+// CopyFile copies file from source to target path.
+func CopyFile(src, dest string) error {
+ return com.Copy(src, dest)
+}
+
+// CopyDir copy files recursively from source to target directory.
+// It returns error when error occurs in underlying functions.
+func CopyDir(srcPath, destPath string) error {
+ return com.CopyDir(srcPath, destPath)
+}