Skip to content

Commit

Permalink
Fix Stage directory issues
Browse files Browse the repository at this point in the history
  • Loading branch information
kesmit13 committed Feb 12, 2024
1 parent e029b28 commit 72cd56c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions singlestoredb/management/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ def remove(self) -> None:
msg='No Stage object is associated with this object.',
)

if self.type == 'directory':
raise IsADirectoryError(
f'path is a directory; use rmdir or removedirs {self.path}',
)

self._stage.remove(self.path)

def rmdir(self) -> None:
Expand All @@ -224,6 +229,11 @@ def rmdir(self) -> None:
msg='No Stage object is associated with this object.',
)

if self.type != 'directory':
raise NotADirectoryError(
f'path is not a directory: {self.path}',
)

self._stage.rmdir(self.path)

def removedirs(self) -> None:
Expand All @@ -233,6 +243,11 @@ def removedirs(self) -> None:
msg='No Stage object is associated with this object.',
)

if self.type != 'directory':
raise NotADirectoryError(
f'path is not a directory: {self.path}',
)

self._stage.removedirs(self.path)

def rename(self, new_path: PathLike, *, overwrite: bool = False) -> None:
Expand Down
2 changes: 1 addition & 1 deletion singlestoredb/tests/test_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ def test_os_directories(self):
assert 'mkdir_test_2/' not in after
assert list(sorted(before)) == list(sorted(after + ['mkdir_test_2/']))

with self.assertRaises(NotADirectoryError):
with self.assertRaises(s2.ManagementError):
st.removedirs('mkdir_test.sql')

def test_os_files(self):
Expand Down

0 comments on commit 72cd56c

Please sign in to comment.