Commit 07087ec8 authored by Carlos Ramos Carreño's avatar Carlos Ramos Carreño Committed by Kirill Smelkov

wcfs: _mntpt_4zurl: Fix it to accept strings.

Strings cannot be directly hashed without encoding them first, or
an error will be raised:

```python
______________________________ test_zsync_resync _______________________________

    @func
    def test_zsync_resync():
        zstor = testdb.getZODBStorage()
        defer(zstor.close)

>       db, zconn, wconn = _zsync_setup(zstor)

wcfs/client/_wczsync_test.py:112:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../../venvs/wendelin.core/lib/python3.9/site-packages/decorator.py:232: in fun
    return caller(func, *(extras + args), **kw)
../pygolang/golang/__init__.py:125: in _
    return f(*argv, **kw)
wcfs/client/_wczsync_test.py:53: in _zsync_setup
    wc = wcfs.join(zurl)
wcfs/__init__.py:201: in join
    mntpt = _mntpt_4zurl(zurl)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

zurl = 'file:///srv/slapgrid/slappart66/tmp/testdb_fs.xstpbg49/1.fs'

    def _mntpt_4zurl(zurl):
        # normalize zurl so that even if we have e.g. two neos:// urls coming
        # with different paths to ssl keys, or with different order in the list of
        # masters, we still have them associated with the same wcfs mountpoint.
        zurl = zurl_normalize_main(zurl)

        m = hashlib.sha1()
>       m.update(zurl)
E       TypeError: Strings must be encoded before hashing
```

We fix this error by encoding the string as UTF8 before hashing it.

--------
kirr:

Use b instead of doing

    if isinstance(zurl, six.text_type):
      zurl = zurl.encode("utf-8")

wcfs already takes this approach of using b in other places - for
example in tDB.change:

    # change schedules zf to be changed according to changeDelta at commit.
    #
    # changeDelta: {} blk -> data.
    # data can be both bytes and unicode.              <-- NOTE
    def change(t, zf, changeDelta):
        assert isinstance(zf, ZBigFile)
        zfDelta = t._changed.setdefault(zf, {})
        for blk, data in six.iteritems(changeDelta):
            data = b(data)                             <-- NOTE
            ...

/reviewed-by @kirr
/reviewed-on nexedi/wendelin.core!27
parent 594ff3fa
......@@ -73,7 +73,7 @@ from stat import S_ISDIR
from errno import ENOENT, ENOTCONN, EEXIST
from signal import SIGTERM, SIGQUIT, SIGKILL
from golang import chan, select, default, func, defer
from golang import chan, select, default, func, defer, b
from golang import context, errors, sync, time
from golang.gcompat import qq
......@@ -505,7 +505,7 @@ def _mntpt_4zurl(zurl):
zurl = zurl_normalize_main(zurl)
m = hashlib.sha1()
m.update(zurl)
m.update(b(zurl))
# WCFS mounts are located under /dev/shm/wcfs. /dev/shm is already used by
# userspace part of wendelin.core memory manager for dirtied pages.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment