aboutsummaryrefslogtreecommitdiffstats
path: root/modules/util/legacy.go
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2022-04-02 00:34:57 +0800
committerGitHub <noreply@github.com>2022-04-02 00:34:57 +0800
commit4f27c289472a4cfafb5a9b0e38e6a3413c30c562 (patch)
tree4a9388cfaf2efe4e9d0ed0242736769ef7e3e083 /modules/util/legacy.go
parent4c5cb1e2f2c7a1fcc3b151192bd45bd1bbc090bd (diff)
downloadgitea-4f27c289472a4cfafb5a9b0e38e6a3413c30c562.tar.gz
gitea-4f27c289472a4cfafb5a9b0e38e6a3413c30c562.zip
Remove legacy `unknwon/com` package (#19298)
Follows: #19284 * The `CopyDir` is only used inside test code * Rewrite `ToSnakeCase` with more test cases * The `RedisCacher` only put strings into cache, here we use internal `toStr` to replace the legacy `ToStr` * The `UniqueQueue` can use string as ID directly, no need to call `ToStr`
Diffstat (limited to 'modules/util/legacy.go')
-rw-r--r--modules/util/legacy.go40
1 files changed, 24 insertions, 16 deletions
diff --git a/modules/util/legacy.go b/modules/util/legacy.go
index c7da541534..d319faad09 100644
--- a/modules/util/legacy.go
+++ b/modules/util/legacy.go
@@ -9,29 +9,37 @@ import (
"crypto/cipher"
"crypto/rand"
"errors"
-
- "github.com/unknwon/com" //nolint:depguard
+ "io"
+ "os"
)
// CopyFile copies file from source to target path.
func CopyFile(src, dest string) error {
- return com.Copy(src, dest)
-}
+ si, err := os.Lstat(src)
+ if err != nil {
+ return err
+ }
-// 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)
-}
+ sr, err := os.Open(src)
+ if err != nil {
+ return err
+ }
+ defer sr.Close()
-// ToStr converts any interface to string. should be replaced.
-func ToStr(value interface{}, args ...int) string {
- return com.ToStr(value, args...)
-}
+ dw, err := os.Create(dest)
+ if err != nil {
+ return err
+ }
+ defer dw.Close()
-// ToSnakeCase converts a string to snake_case. should be replaced.
-func ToSnakeCase(str string) string {
- return com.ToSnakeCase(str)
+ if _, err = io.Copy(dw, sr); err != nil {
+ return err
+ }
+
+ if err = os.Chtimes(dest, si.ModTime(), si.ModTime()); err != nil {
+ return err
+ }
+ return os.Chmod(dest, si.Mode())
}
// AESGCMEncrypt (from legacy package): encrypts plaintext with the given key using AES in GCM mode. should be replaced.