Apply standard Go formatting and update project documentation
- Run go fmt on all Go files to ensure consistent formatting - Add official Go tooling commands to CLAUDE.md for code quality - Update project status to reflect current implementation state
This commit is contained in:
parent
1265f9fb07
commit
bde7aeed90
7 changed files with 104 additions and 72 deletions
|
@ -33,7 +33,7 @@ func (c *Collector) Collect(sourceDir string) ([]FileEntry, error) {
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get absolute path: %w", err)
|
||||
}
|
||||
|
||||
|
||||
// Check if source directory exists
|
||||
info, err := os.Stat(absSourceDir)
|
||||
if err != nil {
|
||||
|
@ -42,9 +42,9 @@ func (c *Collector) Collect(sourceDir string) ([]FileEntry, error) {
|
|||
if !info.IsDir() {
|
||||
return nil, fmt.Errorf("source path is not a directory: %s", sourceDir)
|
||||
}
|
||||
|
||||
|
||||
var files []FileEntry
|
||||
|
||||
|
||||
err = filepath.WalkDir(absSourceDir, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
// Log permission errors but continue walking
|
||||
|
@ -54,7 +54,7 @@ func (c *Collector) Collect(sourceDir string) ([]FileEntry, error) {
|
|||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
// Get file info
|
||||
info, err := d.Info()
|
||||
if err != nil {
|
||||
|
@ -64,12 +64,12 @@ func (c *Collector) Collect(sourceDir string) ([]FileEntry, error) {
|
|||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
// Skip symlinks
|
||||
if info.Mode()&os.ModeSymlink != 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
// Check if this file should be included
|
||||
if c.matcher.ShouldInclude(path, info) {
|
||||
// Calculate relative path from source directory
|
||||
|
@ -77,42 +77,42 @@ func (c *Collector) Collect(sourceDir string) ([]FileEntry, error) {
|
|||
if err != nil {
|
||||
return fmt.Errorf("failed to get relative path: %w", err)
|
||||
}
|
||||
|
||||
|
||||
// Clean the relative path to ensure consistent formatting
|
||||
relPath = filepath.ToSlash(relPath)
|
||||
|
||||
|
||||
files = append(files, FileEntry{
|
||||
Path: relPath,
|
||||
FullPath: path,
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("walk error: %w", err)
|
||||
}
|
||||
|
||||
|
||||
// Check if any files were found
|
||||
if len(files) == 0 {
|
||||
return nil, fmt.Errorf("no files found matching criteria")
|
||||
}
|
||||
|
||||
|
||||
return files, nil
|
||||
}
|
||||
|
||||
// GetArchiveFormat determines the archive format from the filename
|
||||
func GetArchiveFormat(filename string) string {
|
||||
lower := strings.ToLower(filename)
|
||||
|
||||
|
||||
if strings.HasSuffix(lower, ".tar.gz") || strings.HasSuffix(lower, ".tgz") {
|
||||
return "tar.gz"
|
||||
}
|
||||
|
||||
|
||||
if strings.HasSuffix(lower, ".zip") {
|
||||
return "zip"
|
||||
}
|
||||
|
||||
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ type PatternMatcher struct {
|
|||
func NewPatternMatcher(pattern string) *PatternMatcher {
|
||||
// Remove trailing slash if present
|
||||
pattern = strings.TrimSuffix(pattern, "/")
|
||||
|
||||
|
||||
return &PatternMatcher{
|
||||
pattern: pattern,
|
||||
matchedDirs: make(map[string]bool),
|
||||
|
@ -58,27 +58,27 @@ func (m *PatternMatcher) ShouldInclude(path string, info os.FileInfo) bool {
|
|||
}
|
||||
return false // Don't include the directory itself, only files within
|
||||
}
|
||||
|
||||
|
||||
// For files, check if any parent directory is in the matched set
|
||||
dir := filepath.Dir(path)
|
||||
for {
|
||||
if m.matchedDirs[dir] {
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
// Also check if this directory matches the pattern (in case we haven't seen it yet)
|
||||
if matched, err := m.dirMatchesPattern(dir); err == nil && matched {
|
||||
m.matchedDirs[dir] = true
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
parent := filepath.Dir(dir)
|
||||
if parent == dir || parent == "." {
|
||||
break
|
||||
}
|
||||
dir = parent
|
||||
}
|
||||
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -86,26 +86,26 @@ func (m *PatternMatcher) ShouldInclude(path string, info os.FileInfo) bool {
|
|||
func (m *PatternMatcher) dirMatchesPattern(dirPath string) (bool, error) {
|
||||
// Get the directory name
|
||||
dirName := filepath.Base(dirPath)
|
||||
|
||||
|
||||
// For simple patterns (no path separators), just match the directory name
|
||||
if len(m.patternSegments) == 1 {
|
||||
return filepath.Match(m.pattern, dirName)
|
||||
}
|
||||
|
||||
|
||||
// For complex patterns, we need to match the full path segments
|
||||
pathSegments := strings.Split(dirPath, string(os.PathSeparator))
|
||||
|
||||
|
||||
// Try to match the pattern segments against the path segments
|
||||
if len(pathSegments) < len(m.patternSegments) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
|
||||
// Check each pattern segment against the corresponding path segment
|
||||
for i := 0; i < len(m.patternSegments); i++ {
|
||||
// Start from the end of both slices
|
||||
patternIdx := len(m.patternSegments) - 1 - i
|
||||
pathIdx := len(pathSegments) - 1 - i
|
||||
|
||||
|
||||
matched, err := filepath.Match(m.patternSegments[patternIdx], pathSegments[pathIdx])
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
@ -114,7 +114,7 @@ func (m *PatternMatcher) dirMatchesPattern(dirPath string) (bool, error) {
|
|||
return false, nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
|
@ -136,4 +136,4 @@ func (m *CompositeMatcher) ShouldInclude(path string, info os.FileInfo) bool {
|
|||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue