fix(Sheets): cheatsheets in hidden directories (#690)

Fix an issue whereby cheatsheets that were contained within hidden
directories were prevented from being loaded.
This commit is contained in:
Christopher Allen Lane 2022-08-08 19:17:59 -04:00
parent b53a14b1a7
commit 77f9c3fdd0

View File

@ -49,17 +49,18 @@ func Load(cheatpaths []cp.Cheatpath) ([]map[string]sheet.Sheet, error) {
string(os.PathSeparator), string(os.PathSeparator),
) )
// ignore hidden files and directories. Otherwise, we'll likely load // Don't walk the `.git` directory. Doing so creates
// .git/* and .DS_Store. // hundreds/thousands of needless syscalls and could
// potentially harm performance on machines with slow disks.
// //
// NB: this is still somewhat brittle in that it will miss files // NB: We _do_ want to walk hidden directories, however, so we
// contained within hidden directories in the middle of a path, though // should not constrain this further (perhaps to include all
// that should not realistically occur. // hidden directories). In the wild, many users appear to store
if strings.HasPrefix(title, ".") || strings.HasPrefix(info.Name(), ".") { // cheatsheets in a `.config` directory (seemingly a default
// Do not walk hidden directories. This is important, // behavior of `brew`), and `cheat` explicitly supports a
// because it's common for cheatsheets to be stored in // local `.cheat` directory. Constraining further here will
// version-control, and a `.git` directory can easily // break those use-cases - and has done so in the past!
// contain thousands of files. if strings.Contains(path, ".git") {
return fs.SkipDir return fs.SkipDir
} }