{"record":{"id":"9152f72b87166ea6","repo":"yorukot/superfile","slug":"error-while-counting-files-for-s-s","errorCode":null,"errorMessage":"error while counting files for %s: %s","messagePattern":"error while counting files for (.+?): (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/internal/file_operations_compress.go","lineNumber":39,"sourceCode":"\ttotalFiles := 0\n\tfor _, src := range sources {\n\t\tstat, err := os.Stat(src)\n\t\tif os.IsNotExist(err) {\n\t\t\treturn 0, fmt.Errorf(\"source path does not exist: %s\", src)\n\t\t}\n\t\tif err != nil {\n\t\t\treturn 0, fmt.Errorf(\"cannot access source path %s: %w\", src, err)\n\t\t}\n\t\tif !stat.IsDir() {\n\t\t\tif err = checkFileReadable(src); err != nil {\n\t\t\t\tslog.Error(\"the file is not readable\", \"error\", err)\n\t\t\t\treturn 0, fmt.Errorf(\"the file is not readable: %s\", err.Error())\n\t\t\t}\n\t\t}\n\t\tcount, err := countReadableFiles(src)\n\t\tif err != nil {\n\t\t\tslog.Error(\"Error while zip file count files \", \"error\", err)\n\t\t\treturn 0, fmt.Errorf(\"error while counting files for %s: %s\", src, err.Error())\n\t\t}\n\t\ttotalFiles += count\n\t}\n\treturn totalFiles, nil\n}\n\nfunc (m *model) getCompressSelectedFilesCmd() tea.Cmd {\n\tpanel := m.getFocusedFilePanel()\n\n\tif panel.Empty() {\n\t\treturn nil\n\t}\n\tvar filesToCompress []string\n\tvar firstFile string\n\n\tif panel.SelectedCount() == 0 {\n\t\tfirstFile = panel.GetFocusedItem().Location\n\t\tfilesToCompress = append(filesToCompress, firstFile)","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/yorukot/superfile/blob/b72f550bc6e75913f48eb49fdd258e1a2df2fe88/src/internal/file_operations_compress.go#L21-L57","documentation":"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.","triggerScenarios":"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.","commonSituations":"Directory trees with mixed ownership (root-owned subdirs); backup directories with locked files; symlink farms pointing outside the tree or forming loops.","solutions":["Find the offending entry via the wrapped error text and fix its permissions (chmod -R u+rX <dir>).","Exclude unreadable subdirectories from the source selection.","Run with sufficient privileges, or pre-walk with filepath.WalkDir yourself to collect readable files only.","If symlinks cause loops, remove or restructure them before compressing."],"exampleFix":"// before\nerr := ops.ZipSources([]string{bigDir}, target)\n// after\nif err := filepath.WalkDir(bigDir, func(p string, d fs.DirEntry, err error) error {\n    if err != nil {\n        return fmt.Errorf(\"unreadable entry %s: %w\", p, err)\n    }\n    return nil\n}); err != nil {\n    return fmt.Errorf(\"fix permissions before compressing: %w\", err)\n}\nreturn ops.ZipSources([]string{bigDir}, target)","handlingStrategy":"validation","validationCode":"// pre-walk to detect unreadable entries\nwalkErr := filepath.WalkDir(dir, func(p string, d fs.DirEntry, err error) error {\n    if err != nil {\n        return fmt.Errorf(\"unreadable: %s\", p)\n    }\n    return nil\n})\nif walkErr != nil {\n    return walkErr // fix permissions first\n}","typeGuard":null,"tryCatchPattern":"if err := ops.ZipSources([]string{dir}, target); err != nil {\n    if strings.Contains(err.Error(), \"counting files\") {\n        // chmod -R u+rX the tree or exclude the offending subdir\n    }\n    return err\n}","preventionTips":["Run chmod -R u+rX on mixed-ownership trees before zipping.","Avoid symlink cycles in directories you compress.","Pre-walk the tree to identify unreadable entries early."],"tags":["go","filesystem","walk","compress"],"backgroundTag":"directory-not-readable","analyzedSha":"b72f550bc6e75913f48eb49fdd258e1a2df2fe88","analyzedAt":"2026-09-01T04:38:08.254Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}