Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pyglove/core/io/file_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,8 @@ def rename(
raise FileNotFoundError(oldpath_str)

new_entry = self._locate(newpath_str)
if new_entry is entry:
return
if new_entry is not None:
if isinstance(entry, dict): # oldpath is dir
if not isinstance(new_entry, dict):
Expand Down
30 changes: 30 additions & 0 deletions pyglove/core/io/file_system_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,36 @@ def test_rename(self):
with self.assertRaises(FileNotFoundError):
fs.rename('/mem/non-existent', '/mem/y')

def test_rename_same_file(self):
fs = file_system.MemoryFileSystem()
fs.mkdirs('/mem/a')
path = '/mem/a/foo.txt'
with fs.open(path, 'w') as f:
f.write('foo')

fs.rename(path, path)

with fs.open(path) as f:
self.assertEqual(f.read(), 'foo')

def test_rename_same_directory(self):
for children in ([], ['b']):
with self.subTest(children=children):
fs = file_system.MemoryFileSystem()
fs.mkdirs('/mem/a')
for child in children:
fs.mkdir('/mem/a/' + child)

fs.rename('/mem/a', '/mem/a')

self.assertTrue(fs.isdir('/mem/a'))
self.assertEqual(fs.listdir('/mem/a'), children)

def test_rename_same_missing_path(self):
fs = file_system.MemoryFileSystem()
with self.assertRaises(FileNotFoundError):
fs.rename('/mem/missing', '/mem/missing')

def test_copy(self):
fs = file_system.MemoryFileSystem()
fs.mkdirs('/mem/a')
Expand Down
Loading