Skip to content

Commit

Permalink
cmd: add extra check for preserving links when input is a symlink
Browse files Browse the repository at this point in the history
  • Loading branch information
tdewolff committed Apr 2, 2022
1 parent 66064d2 commit d1eec07
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cmd/minify/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ func createTasks(inputs []string, output string) ([]Task, []string, error) {
var info os.FileInfo
var err error
if !preserveLinks {
// follow and dereference symlinks
info, err = os.Stat(input)
} else {
info, err = os.Lstat(input)
Expand All @@ -548,7 +549,8 @@ func createTasks(inputs []string, output string) ([]Task, []string, error) {
}

root := filepath.Dir(input) + string(os.PathSeparator) + "."
if info.Mode()&os.ModeSymlink != 0 {
if preserveLinks && info.Mode()&os.ModeSymlink != 0 {
// copy symlink as is
if !sync {
Warning.Println("--sync not specified, omitting symbolic link", input)
continue
Expand All @@ -559,7 +561,7 @@ func createTasks(inputs []string, output string) ([]Task, []string, error) {
}
tasks = append(tasks, task)
} else if info.Mode().IsRegular() {
valid := pattern == nil || pattern.MatchString(info.Name())
valid := pattern == nil || pattern.MatchString(info.Name()) // don't filter mimetype
if valid || sync {
task, err := NewTask(root, input, output, !valid)
if err != nil {
Expand Down Expand Up @@ -610,7 +612,7 @@ func createTasks(inputs []string, output string) ([]Task, []string, error) {
}

if preserveLinks && d.Type()&os.ModeSymlink != 0 {
// copy symlinks as is
// copy symlink as is
if !sync {
Warning.Println("--sync not specified, omitting symbolic link", path)
return nil
Expand Down

0 comments on commit d1eec07

Please sign in to comment.