yorukot/superfile · error

error while counting files for %s: %s

Error message

error while counting files for %s: %s

What it means

validateCompressOperation wraps an error from countReadableFiles, which walks a source (usually a directory) counting readable files to size the progress bar. A failure means the walk hit an unreadable subdirectory/file or another traversal error, so the total file count and compression are aborted.

Source

Thrown at src/internal/file_operations_compress.go:39

	totalFiles := 0
	for _, src := range sources {
		stat, err := os.Stat(src)
		if os.IsNotExist(err) {
			return 0, fmt.Errorf("source path does not exist: %s", src)
		}
		if err != nil {
			return 0, fmt.Errorf("cannot access source path %s: %w", src, err)
		}
		if !stat.IsDir() {
			if err = checkFileReadable(src); err != nil {
				slog.Error("the file is not readable", "error", err)
				return 0, fmt.Errorf("the file is not readable: %s", err.Error())
			}
		}
		count, err := countReadableFiles(src)
		if err != nil {
			slog.Error("Error while zip file count files ", "error", err)
			return 0, fmt.Errorf("error while counting files for %s: %s", src, err.Error())
		}
		totalFiles += count
	}
	return totalFiles, nil
}

func (m *model) getCompressSelectedFilesCmd() tea.Cmd {
	panel := m.getFocusedFilePanel()

	if panel.Empty() {
		return nil
	}
	var filesToCompress []string
	var firstFile string

	if panel.SelectedCount() == 0 {
		firstFile = panel.GetFocusedItem().Location
		filesToCompress = append(filesToCompress, firstFile)

View on GitHub (pinned to b72f550bc6)

Solutions

  1. Find the offending entry via the wrapped error text and fix its permissions (chmod -R u+rX <dir>).
  2. Exclude unreadable subdirectories from the source selection.
  3. Run with sufficient privileges, or pre-walk with filepath.WalkDir yourself to collect readable files only.
  4. If symlinks cause loops, remove or restructure them before compressing.

Example fix

// before
err := ops.ZipSources([]string{bigDir}, target)
// after
if err := filepath.WalkDir(bigDir, func(p string, d fs.DirEntry, err error) error {
    if err != nil {
        return fmt.Errorf("unreadable entry %s: %w", p, err)
    }
    return nil
}); err != nil {
    return fmt.Errorf("fix permissions before compressing: %w", err)
}
return ops.ZipSources([]string{bigDir}, target)
Defensive patterns

Strategy: validation

Validate before calling

// pre-walk to detect unreadable entries
walkErr := filepath.WalkDir(dir, func(p string, d fs.DirEntry, err error) error {
    if err != nil {
        return fmt.Errorf("unreadable: %s", p)
    }
    return nil
})
if walkErr != nil {
    return walkErr // fix permissions first
}

Try / catch

if err := ops.ZipSources([]string{dir}, target); err != nil {
    if strings.Contains(err.Error(), "counting files") {
        // chmod -R u+rX the tree or exclude the offending subdir
    }
    return err
}

Prevention

When it happens

Trigger: Compressing a directory tree containing at least one unreadable subdirectory or file; walk errors such as EACCES, ELOOP on symlink cycles, or I/O errors mid-traversal.

Common situations: Directory trees with mixed ownership (root-owned subdirs); backup directories with locked files; symlink farms pointing outside the tree or forming loops.

Related errors


AI-assisted analysis of yorukot/superfile@b72f550bc6 (2026-09-01). Data as JSON: /api/errors/9152f72b87166ea6. Report an issue: GitHub.