Skip to content

Commit dfe7ddf

Browse files
feat(files): add support for folders
1 parent 4bd8c89 commit dfe7ddf

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

singlestoredb/management/files.py

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -774,11 +774,22 @@ def mkdir(self, path: PathLike, overwrite: bool = False) -> FilesObject:
774774
FilesObject
775775
776776
"""
777-
raise ManagementError(
778-
msg='Operation not supported: directories are currently not allowed '
779-
'in Files API',
777+
path_str = str(path)
778+
if not path_str.endswith('/'):
779+
path_str = path_str + '/'
780+
781+
if self.exists(path_str):
782+
if not overwrite:
783+
raise OSError(f'file path already exists: {path_str}')
784+
self.remove(path_str)
785+
786+
self._manager._put(
787+
f'files/fs/{self._location}/{path_str}',
788+
headers={'Content-Type': None},
780789
)
781790

791+
return self.info(path_str)
792+
782793
mkdirs = mkdir
783794

784795
def rename(
@@ -804,12 +815,6 @@ def rename(
804815
if not self.exists(old_path):
805816
raise OSError(f'file path does not exist: {old_path}')
806817

807-
if str(old_path).endswith('/') or str(new_path).endswith('/'):
808-
raise ManagementError(
809-
msg='Operation not supported: directories are currently not allowed '
810-
'in Files API',
811-
)
812-
813818
if self.exists(new_path):
814819
if not overwrite:
815820
raise OSError(f'file path already exists: {new_path}')
@@ -1088,10 +1093,11 @@ def rmdir(self, path: PathLike) -> None:
10881093
Path to the file location
10891094
10901095
"""
1091-
raise ManagementError(
1092-
msg='Operation not supported: directories are currently not allowed '
1093-
'in Files API',
1094-
)
1096+
path_str = str(path)
1097+
if not path_str.endswith('/'):
1098+
path_str = path_str + '/'
1099+
1100+
self._manager._delete(f'files/fs/{self._location}/{path_str}')
10951101

10961102
def __str__(self) -> str:
10971103
"""Return string representation."""

0 commit comments

Comments
 (0)