diff --git a/runhouse/resources/hardware/cluster.py b/runhouse/resources/hardware/cluster.py index 532c89c2e..a1f62ad59 100644 --- a/runhouse/resources/hardware/cluster.py +++ b/runhouse/resources/hardware/cluster.py @@ -1840,3 +1840,6 @@ def _folder_mv( return self.client.folder_mv( path=path, dest_path=dest_path, overwrite=overwrite ) + + def _folder_exists(self, path: Union[str, Path]): + return self.client.folder_exists(path=path) diff --git a/runhouse/servers/http/http_client.py b/runhouse/servers/http/http_client.py index 33c2ed5bd..ec797724d 100644 --- a/runhouse/servers/http/http_client.py +++ b/runhouse/servers/http/http_client.py @@ -335,6 +335,12 @@ def folder_rm(self, path: Union[str, Path], contents: List, recursive: bool): "/folder/method/rm", req_type="post", json_dict=folder_params ) + def folder_exists(self, path: str): + folder_params = FolderParams(path=path).dict() + return self.request_json( + "/folder/method/exists", req_type="post", json_dict=folder_params + ) + def get_certificate(self): cert: bytes = self.request( "cert", diff --git a/runhouse/servers/http/http_server.py b/runhouse/servers/http/http_server.py index 0f05f7317..03c549290 100644 --- a/runhouse/servers/http/http_server.py +++ b/runhouse/servers/http/http_server.py @@ -81,19 +81,9 @@ async def wrapper(*args, **kwargs): func_call: bool = func.__name__ in ["post_call", "get_call"] - # restrict access for folder APIs + # restrict access for folder specific APIs access_level_required = ( - ResourceAccess.WRITE - if func.__name__ - in [ - "folder_ls_cmd", - "folder_mkdir_cmd", - "folder_get_cmd", - "folder_put_cmd", - "folder_rm_cmd", - "folder_mv_cmd", - ] - else None + ResourceAccess.WRITE if func.__name__.startswith("folder") else None ) token = get_token_from_request(request) diff --git a/tests/test_resources/test_clusters/test_cluster.py b/tests/test_resources/test_clusters/test_cluster.py index 147f1b490..2df900686 100644 --- a/tests/test_resources/test_clusters/test_cluster.py +++ b/tests/test_resources/test_clusters/test_cluster.py @@ -938,13 +938,14 @@ def test_cluster_mkdir_mv_and_rm(self, cluster): assert "new-folder" in [os.path.basename(f) for f in file_contents] - # Should not be able to mv to an existing directory unless `overwrite=True` - with pytest.raises(FileExistsError): - cluster._folder_mv(path="~/.rh/new-folder", dest_path="~/new-folder") - - cluster._folder_mv( - path="~/.rh/new-folder", dest_path="~/new-folder", overwrite=True - ) + # Should not be able to mv to an existing directory if `overwrite=False` + cluster._folder_mkdir(path="~/.rh/another-new-folder") + with pytest.raises(Exception): + cluster._folder_mv( + path="~/.rh/another-new-folder", + dest_path="~/new-folder", + overwrite=False, + ) # Delete folder contents and directory itself cluster._folder_rm(path="~/new-folder", recursive=True)