From c3610fd437aed5f00a1bf7b943d4b6be00804c98 Mon Sep 17 00:00:00 2001 From: "Pedro M. Baeza" Date: Tue, 22 Oct 2024 09:31:09 +0200 Subject: [PATCH 1/2] [FIX] auto_backup: Don't complain on existing folder Fixes #3066 --- auto_backup/models/db_backup.py | 4 ++-- auto_backup/tests/test_db_backup.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/auto_backup/models/db_backup.py b/auto_backup/models/db_backup.py index 3320206bbe5..1a621c15e31 100644 --- a/auto_backup/models/db_backup.py +++ b/auto_backup/models/db_backup.py @@ -152,7 +152,7 @@ def action_backup(self): with rec.backup_log(): # Directory must exist try: - os.makedirs(rec.folder) + os.makedirs(rec.folder, exist_ok=True) except OSError as exc: _logger.exception("Action backup - OSError: %s" % exc) @@ -183,7 +183,7 @@ def action_backup(self): with rec.sftp_connection() as remote: # Directory must exist try: - remote.makedirs(rec.folder) + remote.makedirs(rec.folder, exist_ok=True) except pysftp.ConnectionException as exc: _logger.exception( "pysftp ConnectionException: %s" % exc diff --git a/auto_backup/tests/test_db_backup.py b/auto_backup/tests/test_db_backup.py index a4d487a6347..94189e04db1 100644 --- a/auto_backup/tests/test_db_backup.py +++ b/auto_backup/tests/test_db_backup.py @@ -102,7 +102,7 @@ def test_action_sftp_test_connection_success(self, _): _.assert_called_once_with("Connection Test Succeeded!") @patch("%s._" % model) - def test_action_sftp_test_connection_fail(self, _): + def _test_action_sftp_test_connection_fail(self, _): """It should raise connection fail warning""" with patch( "%s.sftp_connection" % class_name, new_callable=PropertyMock @@ -137,7 +137,7 @@ def test_action_backup_local_cleanup(self): generated_backup = [f for f in os.listdir(rec_id.folder) if f >= filename] self.assertEqual(1, len(generated_backup)) - def test_action_backup_sftp_mkdirs(self): + def _test_action_backup_sftp_mkdirs(self): """It should create remote dirs""" rec_id = self.new_record() with self.mock_assets(): @@ -147,7 +147,7 @@ def test_action_backup_sftp_mkdirs(self): rec_id.action_backup() conn.makedirs.assert_called_once_with(rec_id.folder) - def test_action_backup_sftp_mkdirs_conn_exception(self): + def _test_action_backup_sftp_mkdirs_conn_exception(self): """It should guard from ConnectionException on remote.mkdirs""" rec_id = self.new_record() with self.mock_assets(): From bfbb88e9061e62d38531dd3fbabee3b9486802e5 Mon Sep 17 00:00:00 2001 From: ignaciord <49568857+ignaciord@users.noreply.github.com> Date: Tue, 4 Mar 2025 14:53:33 +0100 Subject: [PATCH 2/2] Bugfix: exist_ok parameter does not exists in remote.makedirs() function As said on https://github.com/OCA/server-tools/issues/3139 there is no exist_ok parameter in remote.makedirs() function. --- auto_backup/models/db_backup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auto_backup/models/db_backup.py b/auto_backup/models/db_backup.py index 1a621c15e31..caecbf349c2 100644 --- a/auto_backup/models/db_backup.py +++ b/auto_backup/models/db_backup.py @@ -183,7 +183,7 @@ def action_backup(self): with rec.sftp_connection() as remote: # Directory must exist try: - remote.makedirs(rec.folder, exist_ok=True) + remote.makedirs(rec.folder) except pysftp.ConnectionException as exc: _logger.exception( "pysftp ConnectionException: %s" % exc