Skip to content

Commit

Permalink
Added hash method to wrapfs
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Feb 20, 2019
1 parent a0d3aed commit 22191ab
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [2.4.1] - 2019-02-20

### Fixed

- Fixed hash method missing from WrapFS

## [2.4.0] - 2019-02-15

### Added
Expand Down
2 changes: 1 addition & 1 deletion fs/_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Version, used in module and setup.py.
"""
__version__ = "2.4.0"
__version__ = "2.4.1"
12 changes: 9 additions & 3 deletions fs/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1835,9 +1835,15 @@ def test_glob(self):
self.assertIsInstance(self.fs.glob, glob.BoundGlobber)

def test_hash(self):
self.fs.writebytes("hashme.txt", b"foobar" * 1024)
self.fs.makedir("foo").writebytes("hashme.txt", b"foobar" * 1024)
self.assertEqual(
self.fs.hash("hashme.txt", "md5"), "9fff4bb103ab8ce4619064109c54cb9c"
self.fs.hash("foo/hashme.txt", "md5"), "9fff4bb103ab8ce4619064109c54cb9c"
)
with self.assertRaises(errors.UnsupportedHash):
self.fs.hash("hashme.txt", "nohash")
self.fs.hash("foo/hashme.txt", "nohash")

with self.fs.opendir("foo") as foo_fs:
self.assertEqual(
foo_fs.hash("hashme.txt", "md5"), "9fff4bb103ab8ce4619064109c54cb9c"
)

7 changes: 7 additions & 0 deletions fs/wrapfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,13 @@ def validatepath(self, path):
path = abspath(normpath(path))
return path

def hash(self, path, name):
# type: (Text, Text) -> Text
self.check()
_fs, _path = self.delegate_path(path)
with unwrap_errors(path):
return _fs.hash(_path, name)

@property
def walk(self):
# type: () -> BoundWalker
Expand Down

0 comments on commit 22191ab

Please sign in to comment.