diff --git a/artifactory.py b/artifactory.py index 766b58a..bef94cb 100755 --- a/artifactory.py +++ b/artifactory.py @@ -1636,6 +1636,35 @@ def stat(self, pathobj=None): pathobj = pathobj or self return self._accessor.stat(pathobj=pathobj) + def mkdir(self, mode=0o777, parents=False, exist_ok=False): + """ + Create a new directory at this given path. + """ + try: + self._accessor.mkdir(self, mode) + except FileNotFoundError: + if not parents or self.parent == self: + raise + self.parent.mkdir(parents=True, exist_ok=True) + self.mkdir(mode, parents=False, exist_ok=exist_ok) + except OSError: + # Cannot rely on checking for EEXIST, since the operating system + # could give priority to other errors like EACCES or EROFS + if not exist_ok or not self.is_dir(): + raise + + def rmdir(self): + """ + Remove this directory. The directory must be empty. + """ + self._accessor.rmdir(self) + + def _scandir(self): + """ + Override Path._scandir. Only required on Python >= 3.11 + """ + return self._accessor.scandir(self) + def download_stats(self, pathobj=None): """ Item statistics record the number of times an item was downloaded, last download date and last downloader. diff --git a/tests/unit/test_artifactory_path.py b/tests/unit/test_artifactory_path.py index e4ef608..fbfaba0 100644 --- a/tests/unit/test_artifactory_path.py +++ b/tests/unit/test_artifactory_path.py @@ -455,6 +455,12 @@ def setUp(self): ], "uri": "http://artifactory.local/artifactory/api/storage/libs-release-local", } + self.dir_mkdir = { + "repo": "libs-release-local", + "path": "/testdir", + "created": "2014-02-18T15:35:29.361+04:00", + "uri": "http://artifactory.local/artifactory/api/storage/libs-release-local", + } self.property_data = """{ "properties" : { @@ -675,8 +681,39 @@ def test_listdir(self): self.assertRaises(OSError, a.listdir, path) + @responses.activate def test_mkdir(self): - pass + a = self.cls() + + # Directory + path = ArtifactoryPath( + "http://artifactory.local/artifactory/libs-release-local/testdir" + ) + + constructed_url_stat = "http://artifactory.local/artifactory/api/storage/libs-release-local/testdir" + constructed_url_mkdir = ( + "http://artifactory.local/artifactory/libs-release-local/testdir/" + ) + responses.add( + responses.GET, + constructed_url_stat, + status=404, + json=""" +{ + "errors" : [ { + "status" : 404, + "message" : "Not Found." + } ] +} +""", + ) + responses.add( + responses.PUT, + constructed_url_mkdir, + status=200, + json=self.dir_mkdir, + ) + a.mkdir(path, "") @responses.activate def test_get_properties(self):