From d160e7b5bd655d23adf63399c19f10f36a216df3 Mon Sep 17 00:00:00 2001 From: Suman Michael Date: Thu, 17 Jul 2025 20:00:47 +0530 Subject: [PATCH] Fix file path handling for separate index and special output files - Use proper file path construction with fileparse() and File::Spec->catfile() for all INDEXES_, AUTOINCREMENT_, and LOGICAL_ output files - Ensures correct directory handling when OUTPUT_DIR is specified - Fixes potential issues with file creation in different directory structures - Affects TBSP_INDEXES_, PARTITION_INDEXES_, AUTOINCREMENT_, LOGICAL_, INDEXES_, and FTS_INDEXES_ file generation - Improves consistency with existing file handling patterns in the codebase --- lib/Ora2Pg.pm | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/lib/Ora2Pg.pm b/lib/Ora2Pg.pm index 6cf2cca3..e8d7211d 100644 --- a/lib/Ora2Pg.pm +++ b/lib/Ora2Pg.pm @@ -7468,8 +7468,10 @@ sub export_tablespace if ($self->{file_per_index} && (scalar keys %{$self->{tablespaces}} > 0)) { my $fhdl = undef; - $self->logit("Dumping tablespace alter indexes to one separate file : TBSP_INDEXES_$self->{output}\n", 1); - $fhdl = $self->open_export_file("TBSP_INDEXES_$self->{output}"); + my ($filename, $dirname) = fileparse($self->{output}); + my $tbsp_indexes_file = File::Spec->catfile($dirname, "TBSP_INDEXES_$filename"); + $self->logit("Dumping tablespace alter indexes to one separate file : $tbsp_indexes_file\n", 1); + $fhdl = $self->open_export_file($tbsp_indexes_file); $self->set_binmode($fhdl) if (!$self->{compress}); $sql_output = ''; foreach my $tb_type (sort keys %{$self->{tablespaces}}) @@ -8319,12 +8321,14 @@ FOR EACH ROW EXECUTE PROCEDURE $trg(); if ($partition_indexes) { my $fhdl = undef; - $self->logit("Dumping partition indexes to file : PARTITION_INDEXES_$self->{output}\n", 1); + my ($filename, $dirname) = fileparse($self->{output}); + my $partition_indexes_file = File::Spec->catfile($dirname, "PARTITION_INDEXES_$filename"); + $self->logit("Dumping partition indexes to file : $partition_indexes_file\n", 1); $sql_header = "-- Generated by Ora2Pg, the Oracle database Schema converter, version $VERSION\n"; $sql_header .= "-- Copyright 2000-2025 Gilles DAROLD. All rights reserved.\n"; $sql_header .= "-- DATASOURCE: $self->{oracle_dsn}\n\n"; $sql_header = '' if ($self->{no_header}); - $fhdl = $self->open_export_file("PARTITION_INDEXES_$self->{output}"); + $fhdl = $self->open_export_file($partition_indexes_file); $self->set_binmode($fhdl) if (!$self->{compress}); $self->dump($sql_header . $partition_indexes, $fhdl); $self->close_export_file($fhdl); @@ -9271,8 +9275,10 @@ LANGUAGE PLPGSQL; }; $sequence_output = $fct_sequence . $sequence_output; $sequence_output .= "DROP FUNCTION ora2pg_upd_autoincrement_seq(text, text);\n"; - $self->logit("Dumping DDL to restart autoincrement sequences into separate file : AUTOINCREMENT_$self->{output}\n", 1); - $fhdl = $self->open_export_file("AUTOINCREMENT_$self->{output}"); + my ($filename, $dirname) = fileparse($self->{output}); + my $autoincrement_file = File::Spec->catfile($dirname, "AUTOINCREMENT_$filename"); + $self->logit("Dumping DDL to restart autoincrement sequences into separate file : $autoincrement_file\n", 1); + $fhdl = $self->open_export_file($autoincrement_file); $self->set_binmode($fhdl) if (!$self->{compress}); $sequence_output = $self->set_search_path() . $sequence_output; $self->dump($sql_header . $sequence_output, $fhdl); @@ -9282,8 +9288,10 @@ LANGUAGE PLPGSQL; if ($self->{type} ne 'FDW') { my $fhdl = undef; - $self->logit("Dumping replicat identity information to one separate file : LOGICAL_$self->{output}\n", 1); - $fhdl = $self->open_export_file("LOGICAL_$self->{output}"); + my ($filename, $dirname) = fileparse($self->{output}); + my $logical_file = File::Spec->catfile($dirname, "LOGICAL_$filename"); + $self->logit("Dumping replicat identity information to one separate file : $logical_file\n", 1); + $fhdl = $self->open_export_file($logical_file); $self->set_binmode($fhdl) if (!$self->{compress}); $replicat_identity = "-- Nothing found of type indexes\n" if (!$replicat_identity && !$self->{no_header}); $replicat_identity = $self->set_search_path() . $replicat_identity; @@ -9293,8 +9301,10 @@ LANGUAGE PLPGSQL; if ($self->{file_per_index} && ($self->{type} ne 'FDW')) { my $fhdl = undef; - $self->logit("Dumping indexes to one separate file : INDEXES_$self->{output}\n", 1); - $fhdl = $self->open_export_file("INDEXES_$self->{output}"); + my ($filename, $dirname) = fileparse($self->{output}); + my $indexes_file = File::Spec->catfile($dirname, "INDEXES_$filename"); + $self->logit("Dumping indexes to one separate file : $indexes_file\n", 1); + $fhdl = $self->open_export_file($indexes_file); $self->set_binmode($fhdl) if (!$self->{compress}); $indices = "-- Nothing found of type indexes\n" if (!$indices && !$self->{no_header}); $indices =~ s/\n+/\n/gs; @@ -9328,8 +9338,10 @@ RETURNS text AS }; } # FTS TRIGGERS are exported in a separated file to be able to parallelize index creation - $self->logit("Dumping triggers for FTS indexes to one separate file : FTS_INDEXES_$self->{output}\n", 1); - $fhdl = $self->open_export_file("FTS_INDEXES_$self->{output}"); + my ($filename, $dirname) = fileparse($self->{output}); + my $fts_indexes_file = File::Spec->catfile($dirname, "FTS_INDEXES_$filename"); + $self->logit("Dumping triggers for FTS indexes to one separate file : $fts_indexes_file\n", 1); + $fhdl = $self->open_export_file($fts_indexes_file); $self->set_binmode($fhdl) if (!$self->{compress}); $self->_restore_comments(\$fts_indices); $fts_indices = $self->set_search_path() . $fts_indices;