summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--combox/file.py9
-rw-r--r--tests/file_test.py12
2 files changed, 18 insertions, 3 deletions
diff --git a/combox/file.py b/combox/file.py
index 2f18823..81d15fe 100644
--- a/combox/file.py
+++ b/combox/file.py
@@ -41,10 +41,17 @@ def relative_path(p, config, comboxd=True):
combox.
"""
+ directory = None
if comboxd:
directory = '%s/' % config['combox_dir']
else:
- directory = '%s/' % get_nodedirs(config)[0]
+ for node in get_nodedirs(config):
+ if p.startswith(node):
+ directory = '%s/' % node
+
+ if directory is None:
+ err_msg = "invalid path %s" % p
+ raise ValueError, err_msg
return p.partition(directory)[2]
diff --git a/tests/file_test.py b/tests/file_test.py
index bd81fd7..d8a77ca 100644
--- a/tests/file_test.py
+++ b/tests/file_test.py
@@ -114,10 +114,14 @@ class TestFile(object):
test_file_shard_0 = '%s.shard.0' % test_file_basename
test_file_shard_0_abspath = path.join(get_nodedirs(self.config)[0],
test_file_shard_0)
+ test_file_shard_1 = '%s.shard.1' % test_file_basename
+ test_file_shard_1_abspath = path.join(get_nodedirs(self.config)[1],
+ test_file_shard_1)
assert test_file_shard_0 == relative_path(test_file_shard_0_abspath,
self.config, False)
-
+ assert test_file_shard_1 == relative_path(test_file_shard_1_abspath,
+ self.config, False)
def test_cbpath(self):
"""Tests the cb_path function"""
@@ -125,9 +129,13 @@ class TestFile(object):
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)
-
+ test_file_shard_1 = '%s.shard1' % path.basename(self.TEST_FILE)
+ test_file_shard_1_abspath = path.join(get_nodedirs(self.config)[1],
+ test_file_shard_1)
assert self.TEST_FILE == cb_path(test_file_shard_0_abspath,
self.config)
+ assert self.TEST_FILE == cb_path(test_file_shard_1_abspath,
+ self.config)
# a directory inside combox dir.
foo_dir = path.join(self.config['combox_dir'], 'foo')