gitlab.com/apertussolutions/u-root@v7.0.0+incompatible/cmds/core/elvish/util/fullnames_windows_test.go (about)

     1  package util
     2  
     3  import (
     4  	"os/exec"
     5  	"sort"
     6  	"strings"
     7  	"syscall"
     8  )
     9  
    10  func ls(dir string) []string {
    11  	cmd := exec.Command("cmd")
    12  	cmd.SysProcAttr = &syscall.SysProcAttr{
    13  		CmdLine: "cmd /C dir /A /B " + dir,
    14  	}
    15  	output, err := cmd.Output()
    16  	mustOK(err)
    17  	names := strings.Split(strings.Trim(string(output), "\r\n"), "\r\n")
    18  	for i := range names {
    19  		names[i] = dir + names[i]
    20  	}
    21  	// Remove filenames that start with ".".
    22  	// XXX: This behavior only serves to make current behavior of FullNames,
    23  	// which always treat dotfiles as hidden, legal; the validness of this
    24  	// behavior is quetionable. However, since FullNames is also depended by the
    25  	// glob package for testing, changing FullNames requires changing the
    26  	// behavior of globbing as well.
    27  	filtered := make([]string, 0, len(names))
    28  	for _, name := range names {
    29  		if !strings.HasPrefix(name, dir+".") {
    30  			filtered = append(filtered, name)
    31  		}
    32  	}
    33  	sort.Strings(filtered)
    34  	return filtered
    35  }