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

cacache.get.info returning path including cache dir, not relative path

hdgarrood opened this issue · comments

The documentation for cacache.get.info says that the path property in the returned object will contain the filesystem path relative to the cache argument where content is stored. However, this doesn't seem to be the case:

> const cacache = require('cacache');
undefined
> const cache = "test-cache"
undefined
> cacache.put(cache, 'key', 'example data').then(console.log);
Integrity {
  sha512: [
    Hash {
      source: 'sha512-7VnFdZqezlFs7AwGIxQtDp/nCifXUO7n/Tj0VQ1Qrd2HPQ+hpR/II8Hj1craID9KBdgyXKrLfT4HJ6cB8/B+Xw==',
      algorithm: 'sha512',
      digest: '7VnFdZqezlFs7AwGIxQtDp/nCifXUO7n/Tj0VQ1Qrd2HPQ+hpR/II8Hj1craID9KBdgyXKrLfT4HJ6cB8/B+Xw==',
      options: []
    }
  ]
}
> cacache.get.info(cache, 'key').then(console.log);
{
  key: 'key',
  integrity: 'sha512-7VnFdZqezlFs7AwGIxQtDp/nCifXUO7n/Tj0VQ1Qrd2HPQ+hpR/II8Hj1craID9KBdgyXKrLfT4HJ6cB8/B+Xw==',
  path: 'test-cache/content-v2/sha512/ed/59/c5759a9ece516cec0c0623142d0e9fe70a27d750eee7fd38f4550d50addd873d0fa1a51fc823c1e3d5cada203f4a05d8325caacb7d3e0727a701f3f07e5f',
  size: 12,
  time: 1560700127248,
  metadata: undefined
}

Note that the path property includes the test-cache/ prefix, whereas based on the docs I would have expected it to not include that prefix. I opened an issue because I'm not sure if this is a bug or a documentation error (or if I'm just misinterpreting).

It's probably best to update the documentation here to be more clear. This is definitely a wording issue -- changing the path field to be what the docs seem to say would be a pretty impactful breaking change.

Would you be up to filing a PR to fix the docs?

Yep, can do!