Skip to content

Commit

Permalink
various tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Apr 29, 2022
1 parent c741271 commit 39e3ad4
Show file tree
Hide file tree
Showing 281 changed files with 840 additions and 686 deletions.
2 changes: 1 addition & 1 deletion asset/tui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type tuiApplicationController struct {
Running bool
Offset int
Results []*processor.FileJob
TuiFileWalker *file.FileWalker
TuiFileWalker *file.Walker
TuiFileReaderWorker *processor.FileReaderWorker
TuiSearcherWorker *processor.SearcherWorker

Expand Down
61 changes: 17 additions & 44 deletions file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,20 @@
package file

import (
"errors"
"github.com/boyter/cs/processor/go-gitignore"
"io/ioutil"
"os"
"path"
"path/filepath"
"strings"
"sync"
)

var TerminateWalkError = errors.New("walker terminated")

type File struct {
Location string
Filename string
}

type FileWalker struct {
type Walker struct {
walkMutex sync.Mutex
terminateWalking bool
isWalking bool
Expand All @@ -40,8 +36,8 @@ type FileWalker struct {
UniqueId string
}

func NewFileWalker(directory string, fileListQueue chan *File) *FileWalker {
return &FileWalker{
func NewFileWalker(directory string, fileListQueue chan *File) *Walker {
return &Walker{
walkMutex: sync.Mutex{},
fileListQueue: fileListQueue,
directory: directory,
Expand All @@ -55,34 +51,16 @@ func NewFileWalker(directory string, fileListQueue chan *File) *FileWalker {
}
}

// Call to get the state of the file walker and determine
// if we are walking or not
func (f *FileWalker) Walking() bool {
f.walkMutex.Lock()
defer f.walkMutex.Unlock()
return f.isWalking
}

// Call to have the walker break out of walking and return as
// soon as it possibly can. This is needed because
// this walker needs to work in a TUI interactive mode and
// as such we need to be able to end old processes
func (f *FileWalker) Terminate() {
f.walkMutex.Lock()
defer f.walkMutex.Unlock()
f.terminateWalking = true
}

// Starts walking the supplied directory with the supplied settings
// Start starts walking the supplied directory with the supplied settings
// and putting files that mach into the supplied slice
// Returns usual ioutil errors if there is a file issue
// and a TerminateWalkError if terminate is called while walking
func (f *FileWalker) Start() error {
func (f *Walker) Start() error {
f.walkMutex.Lock()
f.isWalking = true
f.walkMutex.Unlock()

err := f.walkDirectoryRecursive(f.directory, []gitignore.IgnoreMatcher{})
err := f.walkDirectoryRecursive2(f.directory, []gitignore.IgnoreMatcher{})
close(f.fileListQueue)

f.walkMutex.Lock()
Expand All @@ -92,24 +70,20 @@ func (f *FileWalker) Start() error {
return err
}

func (f *FileWalker) walkDirectoryRecursive(directory string, ignores []gitignore.IgnoreMatcher) error {
// NB have to call unlock not using defer because method is recursive
// and will deadlock if not done manually
f.walkMutex.Lock()
if f.terminateWalking == true {
f.walkMutex.Unlock()
return TerminateWalkError
func (f *Walker) walkDirectoryRecursive2(directory string, ignores []gitignore.IgnoreMatcher) error {
d, err := os.Open(directory)
if err != nil {
return err
}
f.walkMutex.Unlock()

fileInfos, err := ioutil.ReadDir(directory)
defer d.Close()

fileInfos, err := d.ReadDir(-1)
if err != nil {
return err
}

files := []os.FileInfo{}
dirs := []os.FileInfo{}
files := []os.DirEntry{}
dirs := []os.DirEntry{}

// We want to break apart the files and directories from the
// return as we loop over them differently and this avoids some
Expand Down Expand Up @@ -252,7 +226,7 @@ func (f *FileWalker) walkDirectoryRecursive(directory string, ignores []gitignor
}
}

err = f.walkDirectoryRecursive(filepath.Join(directory, dir.Name()), ignores)
err = f.walkDirectoryRecursive2(filepath.Join(directory, dir.Name()), ignores)
if err != nil {
return err
}
Expand All @@ -262,7 +236,7 @@ func (f *FileWalker) walkDirectoryRecursive(directory string, ignores []gitignor
return nil
}

// Walk the supplied directory backwards looking for .git or .hg
// FindRepositoryRoot walks the supplied directory backwards looking for .git or .hg
// directories indicating we should start our search from that
// location as its the root.
// Returns the first directory below supplied with .git or .hg in it
Expand Down Expand Up @@ -313,11 +287,10 @@ func checkForGitOrMercurial(curdir string) bool {
return false
}

// A custom version of extracting extensions for a file
// GetExtension is a custom version of extracting extensions for a file
// which deals with extensions specific to code such as
// .travis.yml and the like
func GetExtension(name string) string {

name = strings.ToLower(name)
if !strings.Contains(name, ".") {
return name
Expand Down
5 changes: 3 additions & 2 deletions file/hidden.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: MIT OR Unlicense
//+build !windows
//go:build !windows
// +build !windows

package file

Expand All @@ -8,6 +9,6 @@ import (
)

// IsHidden Returns true if file is hidden
func IsHidden(file os.FileInfo, directory string) (bool, error) {
func IsHidden(file os.DirEntry, directory string) (bool, error) {
return file.Name()[0:1] == ".", nil
}
3 changes: 2 additions & 1 deletion file/hidden_windows.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: MIT OR Unlicense
//+build windows
//go:build windows
// +build windows

package file

Expand Down
1 change: 0 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func main() {
p.StartProcess()
} else {
processor.Error = false // suppress writing errors in TUI mode
//processor.ProcessTui(true)
processor.NewTuiApplication()
}
},
Expand Down
38 changes: 0 additions & 38 deletions processor/fuzz.go

This file was deleted.

2 changes: 0 additions & 2 deletions processor/fuzz.sh

This file was deleted.

1 change: 0 additions & 1 deletion processor/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ func TestParser_Parse(t *testing.T) {
}
}


func TestParser_SimpleTest(t *testing.T) {
lex := NewLexer(`simple test`)
parser := NewParser(lex)
Expand Down
4 changes: 2 additions & 2 deletions processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

var Version = "0.12.0 beta"

// Clean up the input to avoid searching for spaces etc...
// CleanSearchString cleans up the input to avoid searching for spaces etc...
// Take the str cut it up, lower case everything except
// boolean operators and join it all back into the same slice
func CleanSearchString() {
Expand Down Expand Up @@ -42,7 +42,7 @@ func NewProcess(directory string) Process {
}
}

// Process is the main entry point of the command line output it sets everything up and starts running
// StartProcess is the main entry point of the command line output it sets everything up and starts running
func (process *Process) StartProcess() {
// If the user asks we should look back till we find the .git or .hg directory and start the search
// or in case of SVN go back till we don't find it
Expand Down
2 changes: 1 addition & 1 deletion processor/snippet.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"sort"
"unicode"

str "github.com/boyter/cs/str"
"github.com/boyter/cs/str"
)

const (
Expand Down
Loading

0 comments on commit 39e3ad4

Please sign in to comment.