summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--combox/file.py20
-rw-r--r--tests/file_test.py9
2 files changed, 23 insertions, 6 deletions
diff --git a/combox/file.py b/combox/file.py
index f5b38f5..3b3219e 100644
--- a/combox/file.py
+++ b/combox/file.py
@@ -49,14 +49,24 @@ def relative_path(p, config, comboxd=True):
return p.partition(directory)[2]
-def cb_path(shard_path, config):
+def cb_path(node_path, config):
"""
- Returns abs. path of file (in combox dir.) corresponding to the shard with path `shard_path'
+ Returns abs. path of file (in combox dir.) given the node_path.
"""
- rel_shard_path = relative_path(shard_path, config, False)
- rel_file_path = rel_shard_path.partition('.shard')[0]
- return path.join(config['combox_dir'], rel_file_path)
+ if path.isfile(node_path):
+ # partition function is used to remove the `.shard.N' from the
+ # file name.
+ rel_file_path = relative_path(node_path,
+ config,
+ False).partition('.shard')[0]
+ file_cb_path = path.join(config['combox_dir'],
+ rel_file_path)
+ else:
+ file_cb_path = path.join(config['combox_dir'],
+ relative_path(node_path, config, False))
+
+ return file_cb_path
def mk_nodedir(directory, config):
diff --git a/tests/file_test.py b/tests/file_test.py
index 5cbd371..3e14343 100644
--- a/tests/file_test.py
+++ b/tests/file_test.py
@@ -115,13 +115,20 @@ class TestFile(object):
def test_cbpath(self):
"""Tests the get_cbpath function"""
split_and_encrypt(self.TEST_FILE, self.config)
- test_file_shard_0 = '%s.shard.0' % path.basename(self.TEST_FILE)
+ test_file_shard_0 = '%s.shard0' % path.basename(self.TEST_FILE)
test_file_shard_0_abspath = path.join(get_nodedirs(self.config)[0],
test_file_shard_0)
assert self.TEST_FILE == cb_path(test_file_shard_0_abspath,
self.config)
+ # a directory inside combox dir.
+ foo_dir = path.join(self.config['combox_dir'], 'foo')
+ mk_nodedir(foo_dir, self.config)
+ foo_nodedir = path.join(get_nodedirs(self.config)[0],
+ 'foo')
+ assert foo_dir == cb_path(foo_nodedir, self.config)
+
@classmethod
def teardown_class(self):
"""Purge the mess created by this test."""