Skip to content

Commit 3410c3a

Browse files
authored
Added hash method to wrapfs (#266)
1 parent a0d3aed commit 3410c3a

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [2.4.1] - 2019-02-20
9+
10+
### Fixed
11+
12+
- Fixed hash method missing from WrapFS
13+
814
## [2.4.0] - 2019-02-15
915

1016
### Added

fs/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""Version, used in module and setup.py.
22
"""
3-
__version__ = "2.4.0"
3+
__version__ = "2.4.1"

fs/test.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,9 +1835,15 @@ def test_glob(self):
18351835
self.assertIsInstance(self.fs.glob, glob.BoundGlobber)
18361836

18371837
def test_hash(self):
1838-
self.fs.writebytes("hashme.txt", b"foobar" * 1024)
1838+
self.fs.makedir("foo").writebytes("hashme.txt", b"foobar" * 1024)
18391839
self.assertEqual(
1840-
self.fs.hash("hashme.txt", "md5"), "9fff4bb103ab8ce4619064109c54cb9c"
1840+
self.fs.hash("foo/hashme.txt", "md5"), "9fff4bb103ab8ce4619064109c54cb9c"
18411841
)
18421842
with self.assertRaises(errors.UnsupportedHash):
1843-
self.fs.hash("hashme.txt", "nohash")
1843+
self.fs.hash("foo/hashme.txt", "nohash")
1844+
1845+
with self.fs.opendir("foo") as foo_fs:
1846+
self.assertEqual(
1847+
foo_fs.hash("hashme.txt", "md5"), "9fff4bb103ab8ce4619064109c54cb9c"
1848+
)
1849+

fs/wrapfs.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,13 @@ def validatepath(self, path):
491491
path = abspath(normpath(path))
492492
return path
493493

494+
def hash(self, path, name):
495+
# type: (Text, Text) -> Text
496+
self.check()
497+
_fs, _path = self.delegate_path(path)
498+
with unwrap_errors(path):
499+
return _fs.hash(_path, name)
500+
494501
@property
495502
def walk(self):
496503
# type: () -> BoundWalker

0 commit comments

Comments
 (0)