Replace github.com/unknwon/com with stdlib and internal helpers (#8148)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Joe Chen <jc@unknwon.io>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Copilot
2026-02-05 22:08:54 -05:00
committed by GitHub
parent 6d56105f8f
commit bf17cc6c69
38 changed files with 259 additions and 171 deletions

View File

@@ -3,11 +3,11 @@ package database
import (
"context"
"fmt"
"strconv"
"strings"
"time"
"github.com/cockroachdb/errors"
"github.com/unknwon/com"
log "unknwon.dev/clog/v2"
"xorm.io/xorm"
@@ -148,7 +148,7 @@ func (c *Comment) APIFormat() *api.Comment {
}
func CommentHashTag(id int64) string {
return "issuecomment-" + com.ToStr(id)
return "issuecomment-" + strconv.FormatInt(id, 10)
}
// HashTag returns unique hash tag for comment.
@@ -158,7 +158,7 @@ func (c *Comment) HashTag() string {
// EventTag returns unique event hash tag for comment.
func (c *Comment) EventTag() string {
return "event-" + com.ToStr(c.ID)
return "event-" + strconv.FormatInt(c.ID, 10)
}
// mailParticipants sends new comment emails to repository watchers

View File

@@ -3,11 +3,11 @@ package database
import (
"context"
"fmt"
"strconv"
"strings"
"time"
"github.com/cockroachdb/errors"
"github.com/unknwon/com"
log "unknwon.dev/clog/v2"
"xorm.io/xorm"
@@ -221,7 +221,7 @@ func (issue *Issue) APIFormat() *api.Issue {
// HashTag returns unique hash tag for issue.
func (issue *Issue) HashTag() string {
return "issue-" + com.ToStr(issue.ID)
return "issue-" + strconv.FormatInt(issue.ID, 10)
}
// IsPoster returns true if given user by ID is the poster.
@@ -828,7 +828,7 @@ func GetIssueByRef(ref string) (*Issue, error) {
return nil, ErrIssueNotExist{args: map[string]any{"ref": ref}}
}
index := com.StrTo(after).MustInt64()
index, _ := strconv.ParseInt(after, 10, 64)
if index == 0 {
return nil, ErrIssueNotExist{args: map[string]any{"ref": ref}}
}
@@ -1219,7 +1219,8 @@ func parseCountResult(results []map[string][]byte) int64 {
return 0
}
for _, result := range results[0] {
return com.StrTo(string(result)).MustInt64()
count, _ := strconv.ParseInt(string(result), 10, 64)
return count
}
return 0
}

View File

@@ -5,12 +5,12 @@ import (
"fmt"
"github.com/cockroachdb/errors"
"github.com/unknwon/com"
log "unknwon.dev/clog/v2"
"gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/email"
"gogs.io/gogs/internal/markup"
"gogs.io/gogs/internal/strutil"
"gogs.io/gogs/internal/userutil"
)
@@ -138,7 +138,7 @@ func mailIssueCommentToParticipants(issue *Issue, doer *User, mentions []string)
for i := range participants {
if participants[i].ID == doer.ID {
continue
} else if com.IsSliceContainsStr(names, participants[i].Name) {
} else if strutil.ContainsFold(names, participants[i].Name) {
continue
}
@@ -146,7 +146,7 @@ func mailIssueCommentToParticipants(issue *Issue, doer *User, mentions []string)
names = append(names, participants[i].Name)
}
if issue.Assignee != nil && issue.Assignee.ID != doer.ID {
if !com.IsSliceContainsStr(names, issue.Assignee.Name) {
if !strutil.ContainsFold(names, issue.Assignee.Name) {
tos = append(tos, issue.Assignee.Email)
names = append(names, issue.Assignee.Name)
}
@@ -157,7 +157,7 @@ func mailIssueCommentToParticipants(issue *Issue, doer *User, mentions []string)
names = append(names, doer.Name)
toUsernames := make([]string, 0, len(mentions)) // list of user names.
for i := range mentions {
if com.IsSliceContainsStr(names, mentions[i]) {
if strutil.ContainsFold(names, mentions[i]) {
continue
}

View File

@@ -4,11 +4,11 @@ import (
"context"
"fmt"
"net/url"
"strconv"
"strings"
"time"
"github.com/cockroachdb/errors"
"github.com/unknwon/com"
"gopkg.in/ini.v1"
log "unknwon.dev/clog/v2"
"xorm.io/xorm"
@@ -341,7 +341,8 @@ func SyncMirrors() {
log.Trace("SyncMirrors [repo_id: %s]", repoID)
MirrorQueue.Remove(repoID)
m, err := GetMirrorByRepoID(com.StrTo(repoID).MustInt64())
id, _ := strconv.ParseInt(repoID, 10, 64)
m, err := GetMirrorByRepoID(id)
if err != nil {
log.Error("GetMirrorByRepoID [%v]: %v", repoID, err)
continue

View File

@@ -5,10 +5,10 @@ import (
"fmt"
"os"
"path/filepath"
"strconv"
"time"
"github.com/cockroachdb/errors"
"github.com/unknwon/com"
log "unknwon.dev/clog/v2"
"xorm.io/xorm"
@@ -217,7 +217,7 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle
// Create temporary directory to store temporary copy of the base repository,
// and clean it up when operation finished regardless of succeed or not.
tmpBasePath := filepath.Join(conf.Server.AppDataPath, "tmp", "repos", com.ToStr(time.Now().Nanosecond())+".git")
tmpBasePath := filepath.Join(conf.Server.AppDataPath, "tmp", "repos", strconv.Itoa(time.Now().Nanosecond())+".git")
if err = os.MkdirAll(filepath.Dir(tmpBasePath), os.ModePerm); err != nil {
return err
}
@@ -284,7 +284,7 @@ func (pr *PullRequest) Merge(doer *User, baseGitRepo *git.Repository, mergeStyle
}
// Name non-branch commit state to a new temporary branch in order to save changes.
tmpBranch := com.ToStr(time.Now().UnixNano(), 10)
tmpBranch := strconv.FormatInt(time.Now().UnixNano(), 10)
if _, stderr, err = process.ExecDir(-1, tmpBasePath,
fmt.Sprintf("PullRequest.Merge (git checkout): %s", tmpBasePath),
"git", "checkout", "-b", tmpBranch); err != nil {
@@ -414,8 +414,8 @@ func (pr *PullRequest) testPatch() (err error) {
return nil
}
repoWorkingPool.CheckIn(com.ToStr(pr.BaseRepoID))
defer repoWorkingPool.CheckOut(com.ToStr(pr.BaseRepoID))
repoWorkingPool.CheckIn(strconv.FormatInt(pr.BaseRepoID, 10))
defer repoWorkingPool.CheckOut(strconv.FormatInt(pr.BaseRepoID, 10))
log.Trace("PullRequest[%d].testPatch (patchPath): %s", pr.ID, patchPath)
@@ -625,7 +625,7 @@ func (pr *PullRequest) UpdatePatch() (err error) {
}
// Add a temporary remote.
tmpRemote := com.ToStr(time.Now().UnixNano())
tmpRemote := strconv.FormatInt(time.Now().UnixNano(), 10)
baseRepoPath := RepoPath(pr.BaseRepo.MustOwner().Name, pr.BaseRepo.Name)
err = headGitRepo.RemoteAdd(tmpRemote, baseRepoPath, git.RemoteAddOptions{Fetch: true})
if err != nil {
@@ -868,7 +868,8 @@ func TestPullRequests() {
log.Trace("TestPullRequests[%v]: processing test task", prID)
PullRequestQueue.Remove(prID)
pr, err := GetPullRequestByID(com.StrTo(prID).MustInt64())
id, _ := strconv.ParseInt(prID, 10, 64)
pr, err := GetPullRequestByID(id)
if err != nil {
log.Error("GetPullRequestByID[%s]: %v", prID, err)
continue

View File

@@ -11,7 +11,9 @@ import (
"os/exec"
"path"
"path/filepath"
"slices"
"sort"
"strconv"
"strings"
"time"
@@ -36,6 +38,7 @@ import (
"gogs.io/gogs/internal/process"
"gogs.io/gogs/internal/repoutil"
"gogs.io/gogs/internal/semverutil"
"gogs.io/gogs/internal/strutil"
"gogs.io/gogs/internal/sync"
)
@@ -77,14 +80,15 @@ func LoadRepoConfig() {
}
customPath := filepath.Join(conf.CustomDir(), "conf", t)
if com.IsDir(customPath) {
customFiles, err := com.StatDir(customPath)
if osutil.IsDir(customPath) {
entries, err := os.ReadDir(customPath)
if err != nil {
log.Fatal("Failed to get custom %s files: %v", t, err)
}
for _, f := range customFiles {
if !com.IsSliceContainsStr(files, f) {
for _, entry := range entries {
f := entry.Name()
if !strutil.ContainsFold(files, f) {
files = append(files, f)
}
}
@@ -104,12 +108,12 @@ func LoadRepoConfig() {
// Filter out invalid names and promote preferred licenses.
sortedLicenses := make([]string, 0, len(Licenses))
for _, name := range conf.Repository.PreferredLicenses {
if com.IsSliceContainsStr(Licenses, name) {
if slices.Contains(Licenses, name) {
sortedLicenses = append(sortedLicenses, name)
}
}
for _, name := range Licenses {
if !com.IsSliceContainsStr(conf.Repository.PreferredLicenses, name) {
if !slices.Contains(conf.Repository.PreferredLicenses, name) {
sortedLicenses = append(sortedLicenses, name)
}
}
@@ -309,7 +313,7 @@ func (r *Repository) HTMLURL() string {
// CustomAvatarPath returns repository custom avatar file path.
func (r *Repository) CustomAvatarPath() string {
return filepath.Join(conf.Picture.RepositoryAvatarUploadPath, com.ToStr(r.ID))
return filepath.Join(conf.Picture.RepositoryAvatarUploadPath, strconv.FormatInt(r.ID, 10))
}
// RelAvatarLink returns relative avatar link to the site domain,
@@ -317,7 +321,7 @@ func (r *Repository) CustomAvatarPath() string {
// Since Gravatar support not needed here - just check for image path.
func (r *Repository) RelAvatarLink() string {
defaultImgURL := ""
if !com.IsExist(r.CustomAvatarPath()) {
if !osutil.Exist(r.CustomAvatarPath()) {
return defaultImgURL
}
return fmt.Sprintf("%s/%s/%d", conf.Server.Subpath, RepoAvatarURLPrefix, r.ID)
@@ -645,7 +649,7 @@ func (r *Repository) NextIssueIndex() int64 {
}
func (r *Repository) LocalCopyPath() string {
return filepath.Join(conf.Server.AppDataPath, "tmp", "local-r", com.ToStr(r.ID))
return filepath.Join(conf.Server.AppDataPath, "tmp", "local-r", strconv.FormatInt(r.ID, 10))
}
// UpdateLocalCopy fetches latest changes of given branch from repoPath to localPath.
@@ -705,7 +709,7 @@ func (r *Repository) PatchPath(index int64) (string, error) {
return "", err
}
return filepath.Join(RepoPath(r.Owner.Name, r.Name), "pulls", com.ToStr(index)+".patch"), nil
return filepath.Join(RepoPath(r.Owner.Name, r.Name), "pulls", strconv.FormatInt(index, 10)+".patch"), nil
}
// SavePatch saves patch data to corresponding location by given issue ID.
@@ -730,7 +734,7 @@ func isRepositoryExist(e Engine, u *User, repoName string) (bool, error) {
OwnerID: u.ID,
LowerName: strings.ToLower(repoName),
})
return has && com.IsDir(RepoPath(u.Name, repoName)), err
return has && osutil.IsDir(RepoPath(u.Name, repoName)), err
}
// IsRepositoryExist returns true if the repository with given name under user has already existed.
@@ -842,12 +846,14 @@ func MigrateRepository(doer, owner *User, opts MigrateRepoOptions) (*Repository,
}
// Check if repository is empty.
_, stderr, err := com.ExecCmdDir(repoPath, "git", "log", "-1")
cmd := exec.Command("git", "log", "-1")
cmd.Dir = repoPath
output, err := cmd.CombinedOutput()
if err != nil {
if strings.Contains(stderr, "fatal: bad default revision 'HEAD'") {
if strings.Contains(string(output), "fatal: bad default revision 'HEAD'") {
repo.IsBare = true
} else {
return repo, errors.Newf("check bare: %v - %s", err, stderr)
return repo, errors.Newf("check bare: %v - %s", err, output)
}
}
@@ -1070,7 +1076,7 @@ func initRepository(e Engine, repoPath string, doer *User, repo *Repository, opt
return errors.Wrap(err, "set default branch")
}
tmpDir := filepath.Join(os.TempDir(), "gogs-"+repo.Name+"-"+com.ToStr(time.Now().Nanosecond()))
tmpDir := filepath.Join(os.TempDir(), "gogs-"+repo.Name+"-"+strconv.Itoa(time.Now().Nanosecond()))
// Initialize repository according to user's choice.
if opts.AutoInit {
@@ -1493,7 +1499,7 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error
// Rename remote wiki repository to new path and delete local copy.
wikiPath := WikiPath(owner.Name, repo.Name)
if com.IsExist(wikiPath) {
if osutil.Exist(wikiPath) {
RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalWikiPath())
if err = os.Rename(wikiPath, WikiPath(newOwner.Name, repo.Name)); err != nil {
return errors.Newf("rename repository wiki: %v", err)
@@ -1504,8 +1510,8 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error
}
func deleteRepoLocalCopy(repoID int64) {
repoWorkingPool.CheckIn(com.ToStr(repoID))
defer repoWorkingPool.CheckOut(com.ToStr(repoID))
repoWorkingPool.CheckIn(strconv.FormatInt(repoID, 10))
defer repoWorkingPool.CheckOut(strconv.FormatInt(repoID, 10))
RemoveAllWithNotice(fmt.Sprintf("Delete repository %d local copy", repoID), repoutil.RepositoryLocalPath(repoID))
}
@@ -1535,7 +1541,7 @@ func ChangeRepositoryName(u *User, oldRepoName, newRepoName string) (err error)
}
wikiPath := repo.WikiPath()
if com.IsExist(wikiPath) {
if osutil.Exist(wikiPath) {
if err = os.Rename(wikiPath, WikiPath(u.Name, newRepoName)); err != nil {
return errors.Newf("rename repository wiki: %v", err)
}
@@ -1593,11 +1599,11 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e
// Create/Remove git-daemon-export-ok for git-daemon
daemonExportFile := path.Join(repo.RepoPath(), "git-daemon-export-ok")
if repo.IsPrivate && com.IsExist(daemonExportFile) {
if repo.IsPrivate && osutil.Exist(daemonExportFile) {
if err = os.Remove(daemonExportFile); err != nil {
log.Error("Failed to remove %s: %v", daemonExportFile, err)
}
} else if !repo.IsPrivate && !com.IsExist(daemonExportFile) {
} else if !repo.IsPrivate && !osutil.Exist(daemonExportFile) {
if f, err := os.Create(daemonExportFile); err != nil {
log.Error("Failed to create %s: %v", daemonExportFile, err)
} else {
@@ -1929,7 +1935,7 @@ func DeleteOldRepositoryArchives() {
basePath := filepath.Join(repo.RepoPath(), "archives")
for _, format := range formats {
dirPath := filepath.Join(basePath, format)
if !com.IsDir(dirPath) {
if !osutil.IsDir(dirPath) {
continue
}
@@ -1992,7 +1998,7 @@ func gatherMissingRepoRecords() ([]*Repository, error) {
if err := x.Where("id > 0").Iterate(new(Repository),
func(idx int, bean any) error {
repo := bean.(*Repository)
if !com.IsDir(repo.RepoPath()) {
if !osutil.IsDir(repo.RepoPath()) {
repos = append(repos, repo)
}
return nil
@@ -2143,7 +2149,7 @@ func repoStatsCheck(checker *repoChecker) {
return
}
for _, result := range results {
id := com.StrTo(result["id"]).MustInt64()
id, _ := strconv.ParseInt(string(result["id"]), 10, 64)
log.Trace("Updating %s: %d", checker.desc, id)
_, err = x.Exec(checker.correctSQL, id, id)
if err != nil {
@@ -2204,7 +2210,7 @@ func CheckRepoStats() {
log.Error("Select %s: %v", desc, err)
} else {
for _, result := range results {
id := com.StrTo(result["id"]).MustInt64()
id, _ := strconv.ParseInt(string(result["id"]), 10, 64)
log.Trace("Updating %s: %d", desc, id)
_, err = x.Exec("UPDATE `repository` SET num_closed_issues=(SELECT COUNT(*) FROM `issue` WHERE repo_id=? AND is_closed=? AND is_pull=?) WHERE id=?", id, true, false, id)
if err != nil {
@@ -2221,7 +2227,7 @@ func CheckRepoStats() {
log.Error("Select repository count 'num_forks': %v", err)
} else {
for _, result := range results {
id := com.StrTo(result["id"]).MustInt64()
id, _ := strconv.ParseInt(string(result["id"]), 10, 64)
log.Trace("Updating repository count 'num_forks': %d", id)
repo, err := GetRepositoryByID(id)
@@ -2632,8 +2638,8 @@ func (r *Repository) GetForks() ([]*Repository, error) {
//
func (r *Repository) CreateNewBranch(oldBranch, newBranch string) (err error) {
repoWorkingPool.CheckIn(com.ToStr(r.ID))
defer repoWorkingPool.CheckOut(com.ToStr(r.ID))
repoWorkingPool.CheckIn(strconv.FormatInt(r.ID, 10))
defer repoWorkingPool.CheckOut(strconv.FormatInt(r.ID, 10))
localPath := r.LocalCopyPath()

View File

@@ -3,11 +3,11 @@ package database
import (
"context"
"fmt"
"slices"
"strings"
"github.com/cockroachdb/errors"
"github.com/gogs/git-module"
"github.com/unknwon/com"
"gogs.io/gogs/internal/errutil"
"gogs.io/gogs/internal/tool"
@@ -199,7 +199,7 @@ func UpdateOrgProtectBranch(repo *Repository, protectBranch *ProtectBranch, whit
}
validTeamIDs = make([]int64, 0, len(teams))
for i := range teams {
if teams[i].HasWriteAccess() && com.IsSliceContainsInt64(teamIDs, teams[i].ID) {
if teams[i].HasWriteAccess() && slices.Contains(teamIDs, teams[i].ID) {
validTeamIDs = append(validTeamIDs, teams[i].ID)
}
}

View File

@@ -8,18 +8,19 @@ import (
"os/exec"
"path"
"path/filepath"
"strconv"
"strings"
"time"
"github.com/cockroachdb/errors"
gouuid "github.com/satori/go.uuid"
"github.com/unknwon/com"
"github.com/gogs/git-module"
"gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/cryptoutil"
"gogs.io/gogs/internal/gitutil"
"gogs.io/gogs/internal/ioutil"
"gogs.io/gogs/internal/osutil"
"gogs.io/gogs/internal/pathutil"
"gogs.io/gogs/internal/process"
@@ -63,12 +64,12 @@ type ComposeHookEnvsOptions struct {
func ComposeHookEnvs(opts ComposeHookEnvsOptions) []string {
envs := []string{
"SSH_ORIGINAL_COMMAND=1",
EnvAuthUserID + "=" + com.ToStr(opts.AuthUser.ID),
EnvAuthUserID + "=" + strconv.FormatInt(opts.AuthUser.ID, 10),
EnvAuthUserName + "=" + opts.AuthUser.Name,
EnvAuthUserEmail + "=" + opts.AuthUser.Email,
EnvRepoOwnerName + "=" + opts.OwnerName,
EnvRepoOwnerSaltMd5 + "=" + cryptoutil.MD5(opts.OwnerSalt),
EnvRepoID + "=" + com.ToStr(opts.RepoID),
EnvRepoID + "=" + strconv.FormatInt(opts.RepoID, 10),
EnvRepoName + "=" + opts.RepoName,
EnvRepoCustomHooksPath + "=" + filepath.Join(opts.RepoPath, "custom_hooks"),
}
@@ -85,7 +86,7 @@ func ComposeHookEnvs(opts ComposeHookEnvsOptions) []string {
// discardLocalRepoBranchChanges discards local commits/changes of
// given branch to make sure it is even to remote branch.
func discardLocalRepoBranchChanges(localPath, branch string) error {
if !com.IsExist(localPath) {
if !osutil.Exist(localPath) {
return nil
}
@@ -146,8 +147,8 @@ func (r *Repository) UpdateRepoFile(doer *User, opts UpdateRepoFileOptions) erro
return errors.Errorf("bad tree path %q", opts.NewTreeName)
}
repoWorkingPool.CheckIn(com.ToStr(r.ID))
defer repoWorkingPool.CheckOut(com.ToStr(r.ID))
repoWorkingPool.CheckIn(strconv.FormatInt(r.ID, 10))
defer repoWorkingPool.CheckOut(strconv.FormatInt(r.ID, 10))
if err := r.DiscardLocalRepoBranchChanges(opts.OldBranch); err != nil {
return errors.Newf("discard local repo branch[%s] changes: %v", opts.OldBranch, err)
@@ -249,8 +250,8 @@ func (r *Repository) GetDiffPreview(branch, treePath, content string) (*gitutil.
return nil, errors.Errorf("bad tree path %q", treePath)
}
repoWorkingPool.CheckIn(com.ToStr(r.ID))
defer repoWorkingPool.CheckOut(com.ToStr(r.ID))
repoWorkingPool.CheckIn(strconv.FormatInt(r.ID, 10))
defer repoWorkingPool.CheckOut(strconv.FormatInt(r.ID, 10))
if err := r.DiscardLocalRepoBranchChanges(branch); err != nil {
return nil, errors.Newf("discard local repo branch[%s] changes: %v", branch, err)
@@ -322,8 +323,8 @@ func (r *Repository) DeleteRepoFile(doer *User, opts DeleteRepoFileOptions) (err
return errors.Errorf("bad tree path %q", opts.TreePath)
}
repoWorkingPool.CheckIn(com.ToStr(r.ID))
defer repoWorkingPool.CheckOut(com.ToStr(r.ID))
repoWorkingPool.CheckIn(strconv.FormatInt(r.ID, 10))
defer repoWorkingPool.CheckOut(strconv.FormatInt(r.ID, 10))
if err = r.DiscardLocalRepoBranchChanges(opts.OldBranch); err != nil {
return errors.Newf("discard local r branch[%s] changes: %v", opts.OldBranch, err)
@@ -562,8 +563,8 @@ func (r *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions) err
return errors.Newf("get uploads by UUIDs[%v]: %v", opts.Files, err)
}
repoWorkingPool.CheckIn(com.ToStr(r.ID))
defer repoWorkingPool.CheckOut(com.ToStr(r.ID))
repoWorkingPool.CheckIn(strconv.FormatInt(r.ID, 10))
defer repoWorkingPool.CheckOut(strconv.FormatInt(r.ID, 10))
if err = r.DiscardLocalRepoBranchChanges(opts.OldBranch); err != nil {
return errors.Newf("discard local r branch[%s] changes: %v", opts.OldBranch, err)
@@ -606,7 +607,7 @@ func (r *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions) err
return errors.Newf("cannot overwrite symbolic link: %s", upload.Name)
}
if err = com.Copy(tmpPath, targetPath); err != nil {
if err = ioutil.CopyFile(tmpPath, targetPath); err != nil {
return errors.Newf("copy: %v", err)
}
}

View File

@@ -9,18 +9,19 @@ import (
"os"
"path"
"path/filepath"
"strconv"
"strings"
"sync"
"time"
"github.com/cockroachdb/errors"
"github.com/unknwon/com"
"golang.org/x/crypto/ssh"
log "unknwon.dev/clog/v2"
"xorm.io/xorm"
"gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/errutil"
"gogs.io/gogs/internal/osutil"
"gogs.io/gogs/internal/process"
)
@@ -210,7 +211,8 @@ func SSHKeygenParsePublicKey(key, keyTestPath, keygenPath string) (string, int,
}
keyType := strings.Trim(fields[len(fields)-1], "()\r\n")
return strings.ToLower(keyType), com.StrTo(fields[0]).MustInt(), nil
length, _ := strconv.Atoi(fields[0])
return strings.ToLower(keyType), length, nil
}
// SSHNativeParsePublicKey extracts the key type and length using the golang SSH library.
@@ -540,7 +542,7 @@ func RewriteAuthorizedKeys() error {
return err
}
if com.IsExist(fpath) {
if osutil.Exist(fpath) {
if err = os.Remove(fpath); err != nil {
return err
}

View File

@@ -7,7 +7,6 @@ import (
"github.com/cockroachdb/errors"
"github.com/pquerna/otp/totp"
"github.com/unknwon/com"
"gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/cryptoutil"
@@ -29,7 +28,7 @@ func (t *TwoFactor) ValidateTOTP(passcode string) (bool, error) {
if err != nil {
return false, errors.Newf("DecodeString: %v", err)
}
decryptSecret, err := com.AESGCMDecrypt(cryptoutil.MD5Bytes(conf.Security.SecretKey), secret)
decryptSecret, err := cryptoutil.AESGCMDecrypt(cryptoutil.MD5Bytes(conf.Security.SecretKey), secret)
if err != nil {
return false, errors.Newf("AESGCMDecrypt: %v", err)
}

View File

@@ -5,15 +5,16 @@ import (
"os"
"path"
"path/filepath"
"strconv"
"strings"
"time"
"github.com/cockroachdb/errors"
"github.com/unknwon/com"
"github.com/gogs/git-module"
"gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/osutil"
"gogs.io/gogs/internal/pathutil"
"gogs.io/gogs/internal/repoutil"
"gogs.io/gogs/internal/sync"
@@ -61,7 +62,7 @@ func (r *Repository) WikiPath() string {
// HasWiki returns true if repository has wiki.
func (r *Repository) HasWiki() bool {
return com.IsDir(r.WikiPath())
return osutil.IsDir(r.WikiPath())
}
// InitWiki initializes a wiki for repository,
@@ -80,7 +81,7 @@ func (r *Repository) InitWiki() error {
}
func (r *Repository) LocalWikiPath() string {
return filepath.Join(conf.Server.AppDataPath, "tmp", "local-wiki", com.ToStr(r.ID))
return filepath.Join(conf.Server.AppDataPath, "tmp", "local-wiki", strconv.FormatInt(r.ID, 10))
}
// UpdateLocalWiki makes sure the local copy of repository wiki is up-to-date.
@@ -95,8 +96,8 @@ func discardLocalWikiChanges(localPath string) error {
// updateWikiPage adds new page to repository wiki.
func (r *Repository) updateWikiPage(doer *User, oldTitle, title, content, message string, isNew bool) error {
wikiWorkingPool.CheckIn(com.ToStr(r.ID))
defer wikiWorkingPool.CheckOut(com.ToStr(r.ID))
wikiWorkingPool.CheckIn(strconv.FormatInt(r.ID, 10))
defer wikiWorkingPool.CheckOut(strconv.FormatInt(r.ID, 10))
if err := r.InitWiki(); err != nil {
return errors.Newf("InitWiki: %v", err)
@@ -114,7 +115,7 @@ func (r *Repository) updateWikiPage(doer *User, oldTitle, title, content, messag
// If not a new file, show perform update not create.
if isNew {
if com.IsExist(filename) {
if osutil.Exist(filename) {
return ErrWikiAlreadyExist{filename}
}
} else {
@@ -167,8 +168,8 @@ func (r *Repository) EditWikiPage(doer *User, oldTitle, title, content, message
}
func (r *Repository) DeleteWikiPage(doer *User, title string) (err error) {
wikiWorkingPool.CheckIn(com.ToStr(r.ID))
defer wikiWorkingPool.CheckOut(com.ToStr(r.ID))
wikiWorkingPool.CheckIn(strconv.FormatInt(r.ID, 10))
defer wikiWorkingPool.CheckOut(strconv.FormatInt(r.ID, 10))
localPath := r.LocalWikiPath()
if err = discardLocalWikiChanges(localPath); err != nil {