From a19447aed128ecadfcd938d6a80cd4951af1f4ce Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 25 Dec 2020 09:59:32 +0000 Subject: 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 --- modules/util/compare.go | 23 +++++++++++++++++++---- modules/util/copy.go | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 modules/util/copy.go (limited to 'modules/util') 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) +} -- cgit v1.2.3