Skip to content

Commit c3e4920

Browse files
committed
just "proxy" Copy func for now
1 parent 4f0b089 commit c3e4920

File tree

2 files changed

+6
-107
lines changed

2 files changed

+6
-107
lines changed

integrations/integration_test.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,8 +230,7 @@ func prepareTestEnv(t testing.TB, skip ...int) func() {
230230
assert.NoError(t, models.LoadFixtures())
231231
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
232232

233-
assert.NoError(t, util.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"),
234-
setting.RepoRootPath))
233+
assert.NoError(t, util.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
235234
return deferFn
236235
}
237236

@@ -472,6 +471,5 @@ func resetFixtures(t *testing.T) {
472471
assert.NoError(t, queue.GetManager().FlushAll(context.Background(), -1))
473472
assert.NoError(t, models.LoadFixtures())
474473
assert.NoError(t, util.RemoveAll(setting.RepoRootPath))
475-
assert.NoError(t, util.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"),
476-
setting.RepoRootPath))
474+
assert.NoError(t, util.CopyDir(path.Join(filepath.Dir(setting.AppPath), "integrations/gitea-repositories-meta"), setting.RepoRootPath))
477475
}

modules/util/copy.go

Lines changed: 4 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,119 +1,20 @@
1-
// Copyright 2013 com authors
2-
//
3-
// Licensed under the Apache License, Version 2.0 (the "License"): you may
4-
// not use this file except in compliance with the License. You may obtain
5-
// a copy of the License at
6-
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
8-
//
9-
// Unless required by applicable law or agreed to in writing, software
10-
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11-
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12-
// License for the specific language governing permissions and limitations
13-
// under the License.
14-
//
151
// Copyright 2020 The Gitea Authors. All rights reserved.
162
// Use of this source code is governed by a MIT-style
173
// license that can be found in the LICENSE file.
184

195
package util
206

217
import (
22-
"fmt"
23-
"io"
24-
"os"
25-
"path"
26-
"strings"
8+
"github.com/unknwon/com"
279
)
2810

2911
// CopyFile copies file from source to target path.
3012
func CopyFile(src, dest string) error {
31-
// Gather file information to set back later.
32-
si, err := os.Lstat(src)
33-
if err != nil {
34-
return err
35-
}
36-
37-
// Handle symbolic link.
38-
if si.Mode()&os.ModeSymlink != 0 {
39-
target, err := os.Readlink(src)
40-
if err != nil {
41-
return err
42-
}
43-
// NOTE: os.Chmod and os.Chtimes don't recoganize symbolic link,
44-
// which will lead "no such file or directory" error.
45-
return os.Symlink(target, dest)
46-
}
47-
48-
sr, err := os.Open(src)
49-
if err != nil {
50-
return err
51-
}
52-
defer sr.Close()
53-
54-
dw, err := os.Create(dest)
55-
if err != nil {
56-
return err
57-
}
58-
defer dw.Close()
59-
60-
if _, err = io.Copy(dw, sr); err != nil {
61-
return err
62-
}
63-
64-
// Set back file information.
65-
if err = os.Chtimes(dest, si.ModTime(), si.ModTime()); err != nil {
66-
return err
67-
}
68-
return os.Chmod(dest, si.Mode())
13+
return com.Copy(src, dest)
6914
}
7015

7116
// CopyDir copy files recursively from source to target directory.
72-
//
73-
// The filter accepts a function that process the path info.
74-
// and should return true for need to filter.
75-
//
7617
// It returns error when error occurs in underlying functions.
77-
func CopyDir(srcPath, destPath string, filters ...func(filePath string) bool) error {
78-
// Check if target directory exists.
79-
targetExist, err := IsExist(destPath)
80-
if err != nil {
81-
return err
82-
}
83-
if targetExist {
84-
return fmt.Errorf("file or directory alreay exists: '%s'", destPath)
85-
}
86-
87-
err = os.MkdirAll(destPath, os.ModePerm)
88-
if err != nil {
89-
return err
90-
}
91-
92-
// Gather directory info.
93-
infos, err := StatDir(srcPath, true)
94-
if err != nil {
95-
return err
96-
}
97-
98-
var filter func(filePath string) bool
99-
if len(filters) > 0 {
100-
filter = filters[0]
101-
}
102-
103-
for _, info := range infos {
104-
if filter != nil && filter(info) {
105-
continue
106-
}
107-
108-
curPath := path.Join(destPath, info)
109-
if strings.HasSuffix(info, "/") {
110-
err = os.MkdirAll(curPath, os.ModePerm)
111-
} else {
112-
err = CopyFile(path.Join(srcPath, info), curPath)
113-
}
114-
if err != nil {
115-
return err
116-
}
117-
}
118-
return nil
18+
func CopyDir(srcPath, destPath string) error {
19+
return com.CopyDir(srcPath, destPath)
11920
}

0 commit comments

Comments
 (0)