Skip to content

Commit

Permalink
cmd: fix endless loop on preserving attributes on Windows, see #646
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Dec 12, 2023
1 parent d579304 commit ca97b30
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions cmd/minify/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -949,8 +949,18 @@ func preserveAttributes(src, root, dst string) {
if src == "" || dst == "" {
return
}

// make sure we only set attributes on directories and files inside the root destination
var err error
src, err = filepath.Rel(root, src)
if err != nil {
// should never occur
Error.Printf("src is not part of root path: src=%s root=%s", src, root)
return
}

Next:
srcInfo, err := os.Stat(src)
srcInfo, err := os.Stat(filepath.Join(root, src))
if err != nil {
Warning.Println(err)
return
Expand All @@ -976,10 +986,11 @@ Next:
Warning.Println(err)
}
}
if src != root {
// preserve on until root path
src = filepath.Dir(src)
dst = filepath.Dir(dst)

src = filepath.Dir(src)
dst = filepath.Dir(dst)
if src != "." {
// go up to but excluding the root path
goto Next
}
}

0 comments on commit ca97b30

Please sign in to comment.