Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pybind/cephfs: add symlink and its unit test #6323

Merged
merged 1 commit into from Nov 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/pybind/cephfs.py
Expand Up @@ -509,6 +509,19 @@ def stat(self, path):
st_atime=statbuf.st_atime, st_mtime=statbuf.st_mtime,
st_ctime=statbuf.st_ctime)

def symlink(self, existing, newname):
if not isinstance(existing, str):
raise TypeError('existing must be a string')
if not isinstance(newname, str):
raise TypeError('newname must be a string')
self.require_state("mounted")
ret = self.libcephfs.ceph_symlink(
self.cluster,
c_char_p(existing),
c_char_p(newname))
if ret < 0:
raise make_ex(ret, "error in symlink")

def unlink(self, path):
self.require_state("mounted")
ret = self.libcephfs.ceph_unlink(
Expand Down
16 changes: 16 additions & 0 deletions src/test/pybind/test_cephfs.py
Expand Up @@ -81,3 +81,19 @@ def test_open():
cephfs.close(fd)
assert_raises(libcephfs.OperationNotSupported, cephfs.open, 'file-1', 'a')
cephfs.unlink('file-1')

def test_symlink():
fd = cephfs.open('file-1', 'w')
cephfs.write(fd, "1111", 0)
cephfs.close(fd)
cephfs.symlink('file-1', 'file-2')
fd = cephfs.open('file-2', 'r')
assert_equal(cephfs.read(fd, 0, 4), "1111")
cephfs.close(fd)
fd = cephfs.open('file-2', 'r+')
cephfs.write(fd, "2222", 4)
cephfs.close(fd)
fd = cephfs.open('file-1', 'r')
assert_equal(cephfs.read(fd, 0, 8), "11112222")
cephfs.close(fd)
cephfs.unlink('file-2')