From 67365f29e5799f0d505d8c39220705c1b9435d15 Mon Sep 17 00:00:00 2001 From: Dmytro Katyukha Date: Thu, 5 Oct 2023 18:51:44 +0300 Subject: [PATCH] [FIX] addons install/update/uninstall with non-existing logfile --- CHANGELOG.md | 9 ++++++++ .../cli/source/odood/cli/commands/addons.d | 23 ++++++++++++++++--- subpackages/lib/source/odood/lib/package.d | 2 +- 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0807a232..830497ab 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## Release 0.0.15 (Unreleased) + +### Fixes + +- Fix error when running `addons install/update/uninstall` with non-existing + logfile. This was caused by attempt to determine starting point of logfile + to search for errors happened during operation. + Now this case is handled correctly. + ## Release 0.0.14 (2023-10-04) ### Added diff --git a/subpackages/cli/source/odood/cli/commands/addons.d b/subpackages/cli/source/odood/cli/commands/addons.d index 78d97e4e..1e2a86ff 100644 --- a/subpackages/cli/source/odood/cli/commands/addons.d +++ b/subpackages/cli/source/odood/cli/commands/addons.d @@ -451,20 +451,37 @@ class CommandAddonsUpdateInstallUninstall: OdoodCommand { start_again=true; } - auto log_file = project.odoo.logfile.openFile("rt"); + File log_file; + if (project.odoo.logfile.exists) + // Open file only if file exists + log_file = project.odoo.logfile.openFile("rt"); + bool error = false; scope(exit) log_file.close(); foreach(db; dbnames) { - auto log_start = log_file.size(); + if (!log_file.isOpen && project.odoo.logfile.exists) + // If file is not opened but exists, open it. + // This is needed to correctly compute starting point + // for tracking log messages happened during operation (dg) + log_file.open(project.odoo.logfile.toString, "rt"); + + auto log_start = log_file.isOpen ? log_file.size() : 0; + try { // Try to apply delegate dg(db); } catch (ServerCommandFailedException e) { error = true; + if (!log_file.isOpen && project.odoo.logfile.exists) + // If file is not opened but exists, open it. + // This is needed to be able to read log messages + // happeded during execution of dg delegate + log_file.open(project.odoo.logfile.toString, "rt"); + // Print errors from logfile to stdout. - if (log_file.size > log_start) { + if (log_file.isOpen && log_file.size > log_start) { writeln("Following errors detected during install:".red); log_file.seek(log_start); foreach(log_line; OdooLogProcessor(log_file)) diff --git a/subpackages/lib/source/odood/lib/package.d b/subpackages/lib/source/odood/lib/package.d index 79c0e3fd..40a82570 100644 --- a/subpackages/lib/source/odood/lib/package.d +++ b/subpackages/lib/source/odood/lib/package.d @@ -1,6 +1,6 @@ module odood.lib; -public immutable string _version = "0.0.14"; +public immutable string _version = "0.0.15"; public import odood.lib.project;