>> bug fix: stop paths ending in a slash being treated as longer

> use absolute paths
> add formatting to dry run output
This commit is contained in:
Thomas Lindop 2025-05-24 11:38:03 +01:00
parent eab2cf9f67
commit 5ce718239e

20
main.go
View file

@ -55,6 +55,9 @@ type context struct {
// See link below for more details. // See link below for more details.
// https://www.unicode.org/versions/Unicode16.0.0/core-spec/chapter-2/#G25564 // https://www.unicode.org/versions/Unicode16.0.0/core-spec/chapter-2/#G25564
const MAX_CODE_POINT rune = 0x10ffff const MAX_CODE_POINT rune = 0x10ffff
var (
ErrNoPwd = errors.New("Could not get current working directory!")
)
var OwlVersion string var OwlVersion string
@ -76,6 +79,7 @@ var FAT_RUNESET = runeset{
* Compares paths so that all files come before the directories that contain * Compares paths so that all files come before the directories that contain
* them. Files in the same directory come in alphanumeric * them. Files in the same directory come in alphanumeric
* order. * order.
* Note that paths a,b MUST be absolute.
*/ */
func comparePaths(a, b string) int { func comparePaths(a, b string) int {
sep := string(fpath.Separator) sep := string(fpath.Separator)
@ -113,6 +117,10 @@ func (ctx *context) parseFileList() ([]string, error) {
return nil return nil
} }
for _, dir := range ctx.RecurseDirs { for _, dir := range ctx.RecurseDirs {
dir, err := fpath.Abs(dir)
if err != nil {
return result, ErrNoPwd
}
fpath.WalkDir(dir, addFiles) fpath.WalkDir(dir, addFiles)
} }
if len(errMsgs) == 0 { if len(errMsgs) == 0 {
@ -122,7 +130,6 @@ func (ctx *context) parseFileList() ([]string, error) {
} }
} }
func isFatValid(r rune) bool { func isFatValid(r rune) bool {
for _, runeRange := range FAT_RUNESET { for _, runeRange := range FAT_RUNESET {
if runeRange[0] <= r && r <= runeRange[1] { if runeRange[0] <= r && r <= runeRange[1] {
@ -244,9 +251,13 @@ func main() {
) )
} else { } else {
ctx.FileList, err = ctx.parseFileList() ctx.FileList, err = ctx.parseFileList()
if err == ErrNoPwd {
kaput(err)
}
if err != nil { if err != nil {
warn(err.Error()) warn(err.Error())
} }
counter := 0
for _, file := range ctx.FileList { for _, file := range ctx.FileList {
oldName := fpath.Base(file) oldName := fpath.Base(file)
dirName := fpath.Dir(file) dirName := fpath.Dir(file)
@ -258,8 +269,13 @@ func main() {
continue continue
} }
if ctx.DryRun { if ctx.DryRun {
format := "%s -> <<%s>>\n"
if counter % 2 == 1 {
format = "\x1b[2m%s -> <<%s>>\x1b[0m\n"
}
counter++
fmt.Printf( fmt.Printf(
"%s -> <<%s>>\n", format,
file, file,
newPath, newPath,
) )