Browse Source

Fix stream renaming when the new path is a parent of the old

tags/nilmdb-1.4.7
Jim Paris 11 years ago
parent
commit
ebccfb3531
2 changed files with 13 additions and 4 deletions
  1. +9
    -2
      nilmdb/server/bulkdata.py
  2. +4
    -2
      tests/test_cmdline.py

+ 9
- 2
nilmdb/server/bulkdata.py View File

@@ -79,7 +79,12 @@ class BulkData(object):
if Table.exists(ospath):
raise ValueError("stream already exists at this path")
if os.path.isdir(ospath):
raise ValueError("subdirs of this path already exist")
# Look for any files in subdirectories. Fully empty subdirectories
# are OK; they might be there during a rename
for (root, dirs, files) in os.walk(ospath):
if len(files):
raise ValueError(
"non-empty subdirs of this path already exist")

def _create_parents(self, unicodepath):
"""Verify the path name, and create parent directories if they
@@ -188,7 +193,6 @@ class BulkData(object):
# Basic checks
if oldospath == newospath:
raise ValueError("old and new paths are the same")
self._create_check_ospath(newospath)

# Move the table to a temporary location
tmpdir = tempfile.mkdtemp(prefix = "rename-", dir = self.root)
@@ -196,6 +200,9 @@ class BulkData(object):
os.rename(oldospath, tmppath)

try:
# Check destination path
self._create_check_ospath(newospath)

# Create parent dirs for new location
self._create_parents(newunicodepath)



+ 4
- 2
tests/test_cmdline.py View File

@@ -1038,10 +1038,12 @@ class TestCmdline(object):
self.contain("old and new paths are the same")
check_path("newton", "prep")
self.fail("rename /newton/prep /newton")
self.contain("subdirs of this path already exist")
self.contain("path must contain at least one folder")
self.fail("rename /newton/prep /newton/prep/")
self.contain("invalid path")
self.ok("rename /newton/prep /newton/foo")
self.ok("rename /newton/prep /newton/foo/1")
check_path("newton", "foo", "1")
self.ok("rename /newton/foo/1 /newton/foo")
check_path("newton", "foo")
self.ok("rename /newton/foo /totally/different/thing")
check_path("totally", "different", "thing")


Loading…
Cancel
Save