From cfd8b313c3a2b8b25dc84182e1e663f7caccb5d2 Mon Sep 17 00:00:00 2001 From: ayushjariyal Date: Tue, 28 Jan 2025 15:47:49 +0530 Subject: [PATCH 1/7] Solving bug in rename function --- src/aiida/transports/plugins/ssh.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/aiida/transports/plugins/ssh.py b/src/aiida/transports/plugins/ssh.py index f5d0e7053..9f9827259 100644 --- a/src/aiida/transports/plugins/ssh.py +++ b/src/aiida/transports/plugins/ssh.py @@ -1375,9 +1375,9 @@ def rename(self, oldpath: TransportPath, newpath: TransportPath): # why to raise an OSError if the newpath does not exist? # ofcourse newpath shouldn't exist, that's why we are renaming it! # issue opened here: https://github.com/aiidateam/aiida-core/issues/6725 - if not self.isfile(newpath): - if not self.isdir(newpath): - raise OSError(f'Destination {newpath} does not exist') + + if self.isfile(newpath) or self.isdir(newpath): + raise OSError(f"Destination {newpath} already exist") return self.sftp.rename(oldpath, newpath) From 790204e2ac954f5ff4408b7d5e62ec10dce9a054 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 28 Jan 2025 18:36:09 +0000 Subject: [PATCH 2/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/aiida/transports/plugins/ssh.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/aiida/transports/plugins/ssh.py b/src/aiida/transports/plugins/ssh.py index 9f9827259..47390f123 100644 --- a/src/aiida/transports/plugins/ssh.py +++ b/src/aiida/transports/plugins/ssh.py @@ -1375,9 +1375,9 @@ def rename(self, oldpath: TransportPath, newpath: TransportPath): # why to raise an OSError if the newpath does not exist? # ofcourse newpath shouldn't exist, that's why we are renaming it! # issue opened here: https://github.com/aiidateam/aiida-core/issues/6725 - + if self.isfile(newpath) or self.isdir(newpath): - raise OSError(f"Destination {newpath} already exist") + raise OSError(f'Destination {newpath} already exist') return self.sftp.rename(oldpath, newpath) From d4b2b4dec075a406028e6cc6a89cafd8dcadcc79 Mon Sep 17 00:00:00 2001 From: ayushjariyal Date: Wed, 29 Jan 2025 15:23:11 +0530 Subject: [PATCH 3/7] Applying review on issue 6735 --- src/aiida/transports/plugins/ssh.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/aiida/transports/plugins/ssh.py b/src/aiida/transports/plugins/ssh.py index 47390f123..45feeb133 100644 --- a/src/aiida/transports/plugins/ssh.py +++ b/src/aiida/transports/plugins/ssh.py @@ -1371,6 +1371,7 @@ def rename(self, oldpath: TransportPath, newpath: TransportPath): if not self.isfile(oldpath): if not self.isdir(oldpath): raise OSError(f'Source {oldpath} does not exist') +<<<<<<< HEAD # TODO: this seems to be a bug (?) # why to raise an OSError if the newpath does not exist? # ofcourse newpath shouldn't exist, that's why we are renaming it! @@ -1378,6 +1379,11 @@ def rename(self, oldpath: TransportPath, newpath: TransportPath): if self.isfile(newpath) or self.isdir(newpath): raise OSError(f'Destination {newpath} already exist') +======= + + if self.path_exists(newpath): + raise OSError(f"Destination {newpath} already exist") +>>>>>>> 5ecb0476b (Appling review on issue #6735) return self.sftp.rename(oldpath, newpath) From a826a4c680771578ec2f59e6c85c5c553ea529e1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 29 Jan 2025 09:54:43 +0000 Subject: [PATCH 4/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/aiida/transports/plugins/ssh.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aiida/transports/plugins/ssh.py b/src/aiida/transports/plugins/ssh.py index 45feeb133..55ca13f9a 100644 --- a/src/aiida/transports/plugins/ssh.py +++ b/src/aiida/transports/plugins/ssh.py @@ -1380,7 +1380,7 @@ def rename(self, oldpath: TransportPath, newpath: TransportPath): if self.isfile(newpath) or self.isdir(newpath): raise OSError(f'Destination {newpath} already exist') ======= - + if self.path_exists(newpath): raise OSError(f"Destination {newpath} already exist") >>>>>>> 5ecb0476b (Appling review on issue #6735) From 484a9f79f3862c77fdf6f0425b5acfa78ca66670 Mon Sep 17 00:00:00 2001 From: ayushjariyal Date: Wed, 29 Jan 2025 15:55:19 +0530 Subject: [PATCH 5/7] Resolved merge conflict in rename method --- src/aiida/transports/plugins/ssh.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/aiida/transports/plugins/ssh.py b/src/aiida/transports/plugins/ssh.py index 45feeb133..cbe2348b6 100644 --- a/src/aiida/transports/plugins/ssh.py +++ b/src/aiida/transports/plugins/ssh.py @@ -1371,19 +1371,9 @@ def rename(self, oldpath: TransportPath, newpath: TransportPath): if not self.isfile(oldpath): if not self.isdir(oldpath): raise OSError(f'Source {oldpath} does not exist') -<<<<<<< HEAD - # TODO: this seems to be a bug (?) - # why to raise an OSError if the newpath does not exist? - # ofcourse newpath shouldn't exist, that's why we are renaming it! - # issue opened here: https://github.com/aiidateam/aiida-core/issues/6725 - - if self.isfile(newpath) or self.isdir(newpath): - raise OSError(f'Destination {newpath} already exist') -======= - + if self.path_exists(newpath): raise OSError(f"Destination {newpath} already exist") ->>>>>>> 5ecb0476b (Appling review on issue #6735) return self.sftp.rename(oldpath, newpath) From 2023dbe27e05b0d3c7b2932388cf13289afe10e3 Mon Sep 17 00:00:00 2001 From: ayushjariyal Date: Wed, 29 Jan 2025 22:08:26 +0530 Subject: [PATCH 6/7] applying review --- src/aiida/transports/plugins/ssh.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aiida/transports/plugins/ssh.py b/src/aiida/transports/plugins/ssh.py index ab861b497..e6b85eca8 100644 --- a/src/aiida/transports/plugins/ssh.py +++ b/src/aiida/transports/plugins/ssh.py @@ -1372,7 +1372,7 @@ def rename(self, oldpath: TransportPath, newpath: TransportPath): if not self.isdir(oldpath): raise OSError(f'Source {oldpath} does not exist') - if self.isfile(newpath) or self.isdir(newpath): + if self.path_exists(newpath): raise OSError(f'Destination {newpath} already exist') return self.sftp.rename(oldpath, newpath) From e2c34db667b3e04fe139e0c57da30d4f25812533 Mon Sep 17 00:00:00 2001 From: ayushjariyal Date: Thu, 30 Jan 2025 14:17:25 +0530 Subject: [PATCH 7/7] Update docstring --- src/aiida/transports/plugins/ssh.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/aiida/transports/plugins/ssh.py b/src/aiida/transports/plugins/ssh.py index e6b85eca8..c67ee1a74 100644 --- a/src/aiida/transports/plugins/ssh.py +++ b/src/aiida/transports/plugins/ssh.py @@ -1357,7 +1357,7 @@ def rename(self, oldpath: TransportPath, newpath: TransportPath): :param str oldpath: existing name of the file or folder :param str newpath: new name for the file or folder - :raises OSError: if oldpath/newpath is not found + :raises OSError: if oldpath is not found :raises ValueError: if sroldpathc/newpath is not a valid path """ if not oldpath: