feat: change report

This commit is contained in:
崔竞宁
2022-09-14 12:06:53 +08:00
parent 7e7d887b2e
commit a63d804054
3 changed files with 18 additions and 15 deletions

View File

@@ -73,8 +73,8 @@ func main() {
} }
for _, s := range r.NoSpaceSources { for _, s := range r.NoSpaceSources {
logrus.Infof("restore unfinished: base= '%s' relative_path= '%s'", s.Base, s.RelativePath) logrus.Infof("restore unfinished: base= '%s' relative_path= '%v'", s.Base, s.RelativePaths)
opts = append(opts, acp.AccurateSource(s.Base, s.RelativePath)) opts = append(opts, acp.AccurateSource(s.Base, s.RelativePaths...))
} }
} else { } else {
opts = append(opts, acp.Source(sources...)) opts = append(opts, acp.Source(sources...))

13
opt.go
View File

@@ -89,12 +89,7 @@ type Option func(*option) *option
func Source(paths ...string) Option { func Source(paths ...string) Option {
return func(o *option) *option { return func(o *option) *option {
for _, p := range paths { for _, p := range paths {
p = strings.TrimSpace(p)
if p == "" {
continue
}
p = path.Clean(p) p = path.Clean(p)
if p[len(p)-1] == '/' { if p[len(p)-1] == '/' {
p = p[:len(p)-1] p = p[:len(p)-1]
} }
@@ -108,12 +103,10 @@ func Source(paths ...string) Option {
func AccurateSource(base string, relativePaths ...string) Option { func AccurateSource(base string, relativePaths ...string) Option {
return func(o *option) *option { return func(o *option) *option {
for _, p := range relativePaths { base = path.Clean(base)
p = strings.TrimSpace(p)
if p == "" {
continue
}
for _, p := range relativePaths {
p = path.Clean(p)
if p[len(p)-1] == '/' { if p[len(p)-1] == '/' {
p = p[:len(p)-1] p = p[:len(p)-1]
} }

View File

@@ -18,7 +18,17 @@ func (c *Copyer) Report() *Report {
noSpaceSources := make([]*FilePath, 0, len(nss)) noSpaceSources := make([]*FilePath, 0, len(nss))
for _, s := range nss { for _, s := range nss {
noSpaceSources = append(noSpaceSources, &FilePath{Base: s.base, RelativePath: s.relativePath}) if len(noSpaceSources) == 0 {
noSpaceSources = append(noSpaceSources, &FilePath{Base: s.base, RelativePaths: []string{s.relativePath}})
continue
}
if last := noSpaceSources[len(noSpaceSources)-1]; last.Base == s.base {
last.RelativePaths = append(last.RelativePaths, s.relativePath)
continue
}
noSpaceSources = append(noSpaceSources, &FilePath{Base: s.base, RelativePaths: []string{s.relativePath}})
} }
return &Report{ return &Report{
@@ -73,8 +83,8 @@ type File struct {
} }
type FilePath struct { type FilePath struct {
Base string `json:"base,omitempty"` Base string `json:"base,omitempty"`
RelativePath string `json:"relative_path,omitempty"` RelativePaths []string `json:"relative_paths,omitempty"`
} }
type Report struct { type Report struct {