diff --git a/newsfragments/cli-restoredb-manage-fs-data-in-sbubfloder.misc b/newsfragments/cli-restoredb-manage-fs-data-in-sbubfloder.misc new file mode 100644 index 0000000..20f54be --- /dev/null +++ b/newsfragments/cli-restoredb-manage-fs-data-in-sbubfloder.misc @@ -0,0 +1 @@ +Handles the case where the filestore data provided in the source is in a "filestore" subfolder diff --git a/odoo_openupgrade_wizard/cli/cli_restoredb.py b/odoo_openupgrade_wizard/cli/cli_restoredb.py index 5d607a8..4eb9ef6 100644 --- a/odoo_openupgrade_wizard/cli/cli_restoredb.py +++ b/odoo_openupgrade_wizard/cli/cli_restoredb.py @@ -59,6 +59,15 @@ def restoredb( "database-path should be inside the project path to allow " "postgresql to read to it." ) + + # Check db path exists + if not database_path.exists(): + ctx.fail(f"Database path {database_path} does not exist.") + + # Check filestore path exists + if not filestore_path.exists(): + ctx.fail(f"Filestore path {filestore_path} does not exist.") + # Restore the database output = execute_pg_restore( ctx, diff --git a/odoo_openupgrade_wizard/tools/tools_system.py b/odoo_openupgrade_wizard/tools/tools_system.py index 4f43de3..057736e 100644 --- a/odoo_openupgrade_wizard/tools/tools_system.py +++ b/odoo_openupgrade_wizard/tools/tools_system.py @@ -173,3 +173,12 @@ def restore_filestore( else: # works for "t" and "tgz" tar = tarfile.open(src_path) tar.extractall(path=filestore_path) + + # If a filestore/filestore/database/filestore directory exists, + # it means that the filestore was in a "filestore" subdirectory + # and we need to move this content to the parent directory. + filestore_subfolder = filestore_path / "filestore" + if filestore_subfolder.exists(): + for file in filestore_subfolder.iterdir(): + shutil.move(file, filestore_path) + shutil.rmtree(filestore_subfolder) diff --git a/tests/cli_23_restoredb_test.py b/tests/cli_23_restoredb_test.py index f452c5a..5d735cf 100644 --- a/tests/cli_23_restoredb_test.py +++ b/tests/cli_23_restoredb_test.py @@ -45,6 +45,38 @@ def test_cli_restoredb(mocker): # check filestore exists assert dest_filestore_path.exists() + # check the filestore content is at the right place + assert (dest_filestore_path / "01").exists() + + # Check database exists + assert_database(ctx, db_name, "present") + + # Delete filestore and database + shutil.rmtree(dest_filestore_path) + ensure_database(ctx, db_name, state="absent") + + shutil.copyfile( + pathlib.Path("../restoredb/test_with_nested_filestore_dir.tar.gz"), + filestore_path, + ) + + cli_runner_invoke( + [ + "restoredb", + f"--database={db_name}", + f"--database-path={database_path}", + "--database-format=c", + f"--filestore-path={filestore_path}", + "--filestore-format=tgz", + ], + ) + + # check filestore exists + assert dest_filestore_path.exists() + + # check the filestore content is at the right place + assert (dest_filestore_path / "01").exists() + # Check database exists assert_database(ctx, db_name, "present") diff --git a/tests/data/restoredb/test.tar.gz b/tests/data/restoredb/test.tar.gz index 7f5af3f..f755fe5 100644 Binary files a/tests/data/restoredb/test.tar.gz and b/tests/data/restoredb/test.tar.gz differ diff --git a/tests/data/restoredb/test_with_nested_filestore_dir.tar.gz b/tests/data/restoredb/test_with_nested_filestore_dir.tar.gz new file mode 100644 index 0000000..7f5af3f Binary files /dev/null and b/tests/data/restoredb/test_with_nested_filestore_dir.tar.gz differ