Skip to content

Commit

Permalink
🎨 增加 File.CopyWithoutHidden 函数,用于不复制隐藏文件
Browse files Browse the repository at this point in the history
  • Loading branch information
88250 committed May 5, 2024
1 parent dca0181 commit 4260723
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,11 @@ func (gl *GuluFile) CopyFileNewtimes(source, dest string) (err error) {
}

func (gl *GuluFile) copyFile(source, dest string, ignoreHidden, chtimes bool) (err error) {
sourceinfo, err := os.Lstat(source)
if nil != err {
return
}

if ignoreHidden && gl.IsHidden(source) {
return
}
Expand All @@ -278,11 +283,6 @@ func (gl *GuluFile) copyFile(source, dest string, ignoreHidden, chtimes bool) (e
}
defer destfile.Close()

sourceinfo, err := os.Lstat(source)
if nil != err {
return
}

if 0 != sourceinfo.Mode()&os.ModeSymlink {
// 忽略符号链接
return
Expand Down Expand Up @@ -329,6 +329,10 @@ func (gl *GuluFile) copyDir(source, dest string, ignoreHidden, chtimes bool) (er
return err
}

if ignoreHidden && gl.IsHidden(source) {
return
}

if err = os.MkdirAll(dest, 0755); err != nil {
return err
}
Expand All @@ -342,10 +346,6 @@ func (gl *GuluFile) copyDir(source, dest string, ignoreHidden, chtimes bool) (er
srcFilePath := filepath.Join(source, f.Name())
destFilePath := filepath.Join(dest, f.Name())

if gl.IsHidden(srcFilePath) {
continue
}

if f.IsDir() {
err = gl.copyDir(srcFilePath, destFilePath, ignoreHidden, chtimes)
if err != nil {
Expand Down

0 comments on commit 4260723

Please sign in to comment.