Skip to content

Commit 139fa45

Browse files
author
Martin Durant
committed
small fixes
1 parent 83c0691 commit 139fa45

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

fsspec/implementations/cached.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,24 @@ def load_cache(self):
3030
def save_cache(self):
3131
fn = os.path.join(self.storage, 'cache.json')
3232
with open(fn, 'w') as f:
33-
ujson.dump(f, fn)
33+
ujson.dump(self.cache, f)
3434

3535
def _open(self, path, mode='rb', **kwargs):
3636
if mode != 'rb':
3737
return super()._open(path, mode=mode, **kwargs)
3838
if path in self.cache:
3939
detail = self.cache[path]
40-
fn, blocks = detail['fn'], set(detail['blocks'])
40+
hash, blocks = detail['fn'], detail['blocks']
41+
fn = os.path.join(self.storage, hash)
4142
if blocks is True:
4243
return open(fn)
44+
else:
45+
blocks = set(blocks)
4346
else:
4447
hash = hashlib.sha256(path.encode()).hexdigest()
4548
fn = os.path.join(self.storage, hash)
4649
blocks = set()
47-
self.cache[path] = {'fn': fn, 'blocks': blocks}
50+
self.cache[path] = {'fn': hash, 'blocks': blocks}
4851
f = super()._open(path, mode=mode, cache_type='none', **kwargs)
4952
f.cache = MMapCache(f.blocksize, f._fetch_range, f.size,
5053
fn, blocks)

0 commit comments

Comments
 (0)