zkat / cacache

💩💵 but for your data. If you've got the hash, we've got the cache ™ (moved)

Home Page:https://github.com/npm/cacache

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Suggestion: ignore junk files e.g. .DS_Store while scanning cache directories

shinnn opened this issue · comments

Environment

$ sw_vers
ProductName:	Mac OS X
ProductVersion:	10.12.4
BuildVersion:	16E195

$ node -v
v7.10.0

$ npm ls cacache
...
└── cacache@9.2.2 

Problem

I'm trying to use cacache in my module. To verify it works correctly, I often open the cache directory by macOS Finder.app, and it creates .DS_Store file in every directories I've opened.

Those .DS_Store files causes ENOTDIRerrors while recursively calling readdir to the cache directory:

ENOTDIR: not a directory, scandir '/Users/shinnn/.npm/_cacache/index-v5/0b/.DS_Store'

Solution

I think we have 3 options to solve this problem:

  • i. Test the file path with junk module before calling readdir to it.
  • ii. fs.stat it and check if it's actually a directory before calling readdir to it.
    • This solution will lead considerable performance regression though.
  • iii. No need to solve this problem. Don't directly open the cache directories with the file explorer apps.

I prefer the first one, and can create a pull request if you prefer it too.

Thanks.

I went a 4th way: anything that looks out of place will be simply ignored. As of cacache@9.2.3, any ENOTDIR errors while listing entries will be ignored and treated as an empty directory.

This matches the approach to odd conditions that cacache takes: if it doesn't look right, just ignore it.

Ah, thank. Even better approach.