Skip to content

Commit 4a803cc

Browse files
committed
Add safety in absolute file paths
1 parent 6f66b67 commit 4a803cc

File tree

14 files changed

+78
-66
lines changed

14 files changed

+78
-66
lines changed

dynadjust/dynadjust/dnaadjust/dnaadjust_printer.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <sstream>
2828
#include <filesystem>
2929
#include <include/functions/dnaiostreamfuncs.hpp>
30+
#include <include/functions/dnafilepathfuncs.hpp>
3031
#include <include/io/adj_file.hpp>
3132

3233
namespace dynadjust {
@@ -1116,7 +1117,7 @@ void DynAdjustPrinter::PrintStationFileHeader(std::ostream& os, std::string_view
11161117
print_file_header(os, std::string("DYNADJUST ") + std::string(file_type) + " OUTPUT FILE");
11171118

11181119
os << std::setw(PRINT_VAR_PAD) << std::left << "File name:" <<
1119-
std::filesystem::absolute(filename).string() << std::endl << std::endl;
1120+
safe_absolute_path(filename) << std::endl << std::endl;
11201121
}
11211122

11221123
void DynAdjustPrinter::PrintStationColumnHeaders(std::ostream& os, const std::string& stn_coord_types,
@@ -2632,7 +2633,7 @@ void DynAdjustPrinter::PrintPositionalUncertainty()
26322633

26332634
if (adjust_.projectSettings_.o._apply_type_b_file)
26342635
apu_file << std::setw(PRINT_VAR_PAD) << std::left << "Type B uncertainty file:" <<
2635-
std::filesystem::absolute(adjust_.projectSettings_.a.type_b_file).string() << std::endl;
2636+
safe_absolute_path(adjust_.projectSettings_.a.type_b_file) << std::endl;
26362637
}
26372638

26382639
apu_file << OUTPUTLINE << std::endl << std::endl;
@@ -3352,16 +3353,16 @@ void DynAdjustPrinter::PrintOutputFileHeaderInfo()
33523353
// Print formatted header
33533354
print_file_header(adjust_.xyz_file, "DYNADJUST COORDINATE OUTPUT FILE");
33543355

3355-
adjust_.adj_file << std::setw(PRINT_VAR_PAD) << std::left << "File name:" << std::filesystem::absolute(adjust_.projectSettings_.o._adj_file).string() << std::endl << std::endl;
3356-
adjust_.xyz_file << std::setw(PRINT_VAR_PAD) << std::left << "File name:" << std::filesystem::absolute(adjust_.projectSettings_.o._xyz_file).string() << std::endl << std::endl;
3356+
adjust_.adj_file << std::setw(PRINT_VAR_PAD) << std::left << "File name:" << safe_absolute_path(adjust_.projectSettings_.o._adj_file) << std::endl << std::endl;
3357+
adjust_.xyz_file << std::setw(PRINT_VAR_PAD) << std::left << "File name:" << safe_absolute_path(adjust_.projectSettings_.o._xyz_file) << std::endl << std::endl;
33573358

33583359
adjust_.adj_file << std::setw(PRINT_VAR_PAD) << std::left << "Command line arguments: ";
33593360
adjust_.adj_file << adjust_.projectSettings_.a.command_line_arguments << std::endl << std::endl;
33603361

33613362
if (adjust_.projectSettings_.i.input_files.empty())
33623363
{
3363-
adjust_.adj_file << std::setw(PRINT_VAR_PAD) << std::left << "Stations file:" << std::filesystem::absolute(adjust_.projectSettings_.a.bst_file).string() << std::endl;
3364-
adjust_.adj_file << std::setw(PRINT_VAR_PAD) << std::left << "Measurements file:" << std::filesystem::absolute(adjust_.projectSettings_.a.bms_file).string() << std::endl;
3364+
adjust_.adj_file << std::setw(PRINT_VAR_PAD) << std::left << "Stations file:" << safe_absolute_path(adjust_.projectSettings_.a.bst_file) << std::endl;
3365+
adjust_.adj_file << std::setw(PRINT_VAR_PAD) << std::left << "Measurements file:" << safe_absolute_path(adjust_.projectSettings_.a.bms_file) << std::endl;
33653366
}
33663367
else
33673368
{
@@ -3382,8 +3383,8 @@ void DynAdjustPrinter::PrintOutputFileHeaderInfo()
33823383

33833384

33843385
// Geoid model
3385-
adjust_.adj_file << std::setw(PRINT_VAR_PAD) << std::left << "Geoid model: " << std::filesystem::absolute(adjust_.projectSettings_.n.ntv2_geoid_file).string() << std::endl;
3386-
adjust_.xyz_file << std::setw(PRINT_VAR_PAD) << std::left << "Geoid model: " << std::filesystem::absolute(adjust_.projectSettings_.n.ntv2_geoid_file).string() << std::endl;
3386+
adjust_.adj_file << std::setw(PRINT_VAR_PAD) << std::left << "Geoid model: " << safe_absolute_path(adjust_.projectSettings_.n.ntv2_geoid_file) << std::endl;
3387+
adjust_.xyz_file << std::setw(PRINT_VAR_PAD) << std::left << "Geoid model: " << safe_absolute_path(adjust_.projectSettings_.n.ntv2_geoid_file) << std::endl;
33873388

33883389
switch (adjust_.projectSettings_.a.adjust_mode)
33893390
{
@@ -3445,9 +3446,9 @@ void DynAdjustPrinter::PrintOutputFileHeaderInfo()
34453446
if (adjust_.projectSettings_.o._apply_type_b_file)
34463447
{
34473448
adjust_.adj_file << std::setw(PRINT_VAR_PAD) << std::left << "Type B uncertainty file:" <<
3448-
std::filesystem::absolute(adjust_.projectSettings_.a.type_b_file).string() << std::endl;
3449+
safe_absolute_path(adjust_.projectSettings_.a.type_b_file) << std::endl;
34493450
adjust_.xyz_file << std::setw(PRINT_VAR_PAD) << std::left << "Type B uncertainty file:" <<
3450-
std::filesystem::absolute(adjust_.projectSettings_.a.type_b_file).string() << std::endl;
3451+
safe_absolute_path(adjust_.projectSettings_.a.type_b_file) << std::endl;
34513452
}
34523453
}
34533454

dynadjust/dynadjust/dnaadjustwrapper/dnaadjustwrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <filesystem>
21
//============================================================================
32
// Name : dnaadjustwrapper.cpp
43
// Author : Roger Fraser
@@ -25,6 +24,7 @@
2524
#include <dynadjust/dnaadjust/dnaadjust_printer.hpp>
2625

2726
#include <include/functions/dnastrutils.hpp>
27+
#include <include/functions/dnafilepathfuncs.hpp>
2828
#include <thread>
2929

3030
#include "threading_init.hpp"
@@ -1131,7 +1131,7 @@ int main(int argc, char* argv[])
11311131
std::cout << std::setw(PRINT_VAR_PAD) << std::left << " Reference frame: " << datum.GetName() << std::endl;
11321132
std::cout << std::setw(PRINT_VAR_PAD) << std::left << " Epoch: " << datum.GetEpoch_s() << std::endl;
11331133

1134-
std::cout << std::setw(PRINT_VAR_PAD) << std::left << " Geoid model: " << std::filesystem::absolute(p.n.ntv2_geoid_file).string() << std::endl;
1134+
std::cout << std::setw(PRINT_VAR_PAD) << std::left << " Geoid model: " << safe_absolute_path(p.n.ntv2_geoid_file) << std::endl;
11351135

11361136
if (p.a.scale_normals_to_unity)
11371137
std::cout << std::setw(PRINT_VAR_PAD) << std::left << " Scale normals to unity: " << "yes" << std::endl;

dynadjust/dynadjust/dnageoidwrapper/dnageoidwrapper.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <filesystem>
21
//============================================================================
32
// Name : dnageoidwrapper.cpp
43
// Author : Roger Fraser
@@ -24,6 +23,7 @@
2423
#include <dynadjust/dnageoidwrapper/dnageoidwrapper.hpp>
2524

2625
#include <include/functions/dnastrutils.hpp>
26+
#include <include/functions/dnafilepathfuncs.hpp>
2727

2828
using namespace dynadjust;
2929

@@ -139,8 +139,8 @@ void ReturnBadStationRecords(dna_geoid_interpolation* g, project_settings& p)
139139
badpoints_log << p.n.command_line_arguments << std::endl << std::endl;
140140

141141
badpoints_log << std::setw(PRINT_VAR_PAD) << std::left << "Network name:" << p.g.network_name << std::endl;
142-
badpoints_log << std::setw(PRINT_VAR_PAD) << std::left << "Stations file:" << std::filesystem::absolute(p.n.bst_file).string() << std::endl;
143-
badpoints_log << std::setw(PRINT_VAR_PAD) << std::left << "Geoid model: " << std::filesystem::absolute(p.n.ntv2_geoid_file).string() << std::endl << std::endl;
142+
badpoints_log << std::setw(PRINT_VAR_PAD) << std::left << "Stations file:" << safe_absolute_path(p.n.bst_file) << std::endl;
143+
badpoints_log << std::setw(PRINT_VAR_PAD) << std::left << "Geoid model: " << safe_absolute_path(p.n.ntv2_geoid_file) << std::endl << std::endl;
144144
badpoints_log << std::setw(PRINT_VAR_PAD) << std::left << "Stations not interpolated:" << g->PointsNotInterpolated() << std::endl;
145145
badpoints_log << OUTPUTLINE << std::endl << std::endl;
146146

@@ -1172,4 +1172,4 @@ int main(int argc, char* argv[])
11721172
std::cout << std::endl << formatedElapsedTime<std::string>(&elapsed_time, "+ Geoid file interpolation took ") << std::endl << std::endl;
11731173

11741174
return EXIT_SUCCESS;
1175-
}
1175+
}

dynadjust/dynadjust/dnaimport/dnainterop.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <filesystem>
21
//============================================================================
32
// Name : dnainterop.cpp
43
// Author : Roger Fraser
@@ -4944,11 +4943,11 @@ void dna_import::PrintMeasurementsToStations(std::string& m2s_file, MsrTally* pa
49444943
// Print formatted header
49454944
print_file_header(m2s_stream, "DYNADJUST MEASUREMENT TO STATION OUTPUT FILE");
49464945

4947-
m2s_stream << std::setw(PRINT_VAR_PAD) << std::left << "File name:" << std::filesystem::absolute(m2s_file).string() << std::endl << std::endl;
4946+
m2s_stream << std::setw(PRINT_VAR_PAD) << std::left << "File name:" << safe_absolute_path(m2s_file) << std::endl << std::endl;
49484947

4949-
m2s_stream << std::setw(PRINT_VAR_PAD) << std::left << "Associated measurement file: " << std::filesystem::absolute(aml_file).string() << std::endl;
4950-
m2s_stream << std::setw(PRINT_VAR_PAD) << std::left << "Stations file:" << std::filesystem::absolute(bst_file).string() << std::endl;
4951-
m2s_stream << std::setw(PRINT_VAR_PAD) << std::left << "Measurements file:" << std::filesystem::absolute(bms_file).string() << std::endl;
4948+
m2s_stream << std::setw(PRINT_VAR_PAD) << std::left << "Associated measurement file: " << safe_absolute_path(aml_file) << std::endl;
4949+
m2s_stream << std::setw(PRINT_VAR_PAD) << std::left << "Stations file:" << safe_absolute_path(bst_file) << std::endl;
4950+
m2s_stream << std::setw(PRINT_VAR_PAD) << std::left << "Measurements file:" << safe_absolute_path(bms_file) << std::endl;
49524951

49534952
// Print station count
49544953
m2s_stream << std::endl;

dynadjust/dynadjust/dnaimportwrapper/dnaimportwrapper.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
// Description : DynAdjust Interoperability library Executable
2020
//============================================================================
2121

22-
#include <filesystem>
2322
#include <dynadjust/dnaimportwrapper/dnaimportwrapper.hpp>
2423
#include <include/parameters/dnaepsg.hpp>
2524
#include <include/functions/dnastrutils.hpp>
25+
#include <include/functions/dnafilepathfuncs.hpp>
2626
#include <mutex>
2727
#include <thread>
2828

@@ -44,20 +44,20 @@ void PrintOutputFileHeaderInfo(std::ofstream* f_out, const std::string& out_file
4444
// Print formatted header
4545
print_file_header(*f_out, header);
4646

47-
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "File name:" << std::filesystem::absolute(out_file).string() << std::endl << std::endl;
47+
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "File name:" << safe_absolute_path(out_file) << std::endl << std::endl;
4848

4949
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Command line arguments: ";
5050
*f_out << p->i.command_line_arguments << std::endl << std::endl;
5151

5252
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Network name:" << p->g.network_name << std::endl;
53-
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Input folder: " << std::filesystem::absolute(p->g.input_folder).string() << std::endl;
54-
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Output folder: " << std::filesystem::absolute(p->g.output_folder).string() << std::endl;
55-
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Stations file:" << std::filesystem::absolute(p->i.bst_file).string() << std::endl;
56-
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Measurements file:" << std::filesystem::absolute(p->i.bms_file).string() << std::endl;
57-
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Associated station file:" << std::filesystem::absolute(p->i.asl_file).string() << std::endl;
58-
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Associated measurement file:" << std::filesystem::absolute(p->i.aml_file).string() << std::endl;
59-
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Duplicate stations output file:" << std::filesystem::absolute(p->i.dst_file).string() << std::endl;
60-
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Similar measurement output file:" << std::filesystem::absolute(p->i.dms_file).string() << std::endl;
53+
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Input folder: " << safe_absolute_path(p->g.input_folder) << std::endl;
54+
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Output folder: " << safe_absolute_path(p->g.output_folder) << std::endl;
55+
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Stations file:" << safe_absolute_path(p->i.bst_file) << std::endl;
56+
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Measurements file:" << safe_absolute_path(p->i.bms_file) << std::endl;
57+
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Associated station file:" << safe_absolute_path(p->i.asl_file) << std::endl;
58+
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Associated measurement file:" << safe_absolute_path(p->i.aml_file) << std::endl;
59+
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Duplicate stations output file:" << safe_absolute_path(p->i.dst_file) << std::endl;
60+
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Similar measurement output file:" << safe_absolute_path(p->i.dms_file) << std::endl;
6161

6262
if (!p->i.input_files.empty())
6363
{
@@ -126,7 +126,7 @@ void PrintOutputFileHeaderInfo(std::ofstream* f_out, const std::string& out_file
126126
}
127127

128128
if (!p->i.seg_file.empty())
129-
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Segmentation file:" << std::filesystem::absolute(p->i.seg_file).string() << std::endl;
129+
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Segmentation file:" << safe_absolute_path(p->i.seg_file) << std::endl;
130130

131131
if (p->i.import_block)
132132
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Import stns & msrs from block: " << p->i.import_block_number << std::endl;

dynadjust/dynadjust/dnaplot/dnaplot.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@
2020
//============================================================================
2121

2222
#include <dynadjust/dnaplot/dnaplot.hpp>
23-
#include <filesystem>
24-
#include <thread>
2523

2624
#include <include/functions/dnastrutils.hpp>
25+
#include <include/functions/dnafilepathfuncs.hpp>
2726
namespace dynadjust {
2827
namespace networkplot {
2928

@@ -217,7 +216,7 @@ void dna_plot::CreategnuplotGraphEnvironment(project_settings* pprj, const plotG
217216
void dna_plot::InvokeGnuplot()
218217
{
219218
// Invoke gnuplot using absolute path
220-
std::string system_file_cmd = "gnuplot " + std::filesystem::absolute(pprj_->p._gnuplot_cmd_file).string();
219+
std::string system_file_cmd = "gnuplot " + safe_absolute_path(pprj_->p._gnuplot_cmd_file);
221220

222221
// set up a thread group to execute the gnuplot in parallel
223222
std::thread gnuplot_thread{dna_create_threaded_process(system_file_cmd)};
@@ -1076,7 +1075,7 @@ void dna_plot::InitialiseGMTFilenames()
10761075
gmt_filename = pprj_->g.output_folder + FOLDER_SLASH + gmt_filename;
10771076

10781077
// Create absolute path
1079-
gmt_filename = std::filesystem::absolute(gmt_filename).string();
1078+
gmt_filename = safe_absolute_path(gmt_filename);
10801079

10811080
// Add to the list
10821081
v_gmt_cmd_filenames_.push_back(gmt_filename);

dynadjust/dynadjust/dnareftranwrapper/dnareftranwrapper.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#include <filesystem>
21
//============================================================================
32
// Name : dnareftranwrapper.cpp
43
// Author : Roger Fraser
@@ -24,6 +23,7 @@
2423
#include <dynadjust/dnareftranwrapper/dnareftranwrapper.hpp>
2524

2625
#include <include/functions/dnastrutils.hpp>
26+
#include <include/functions/dnafilepathfuncs.hpp>
2727

2828
using namespace dynadjust;
2929

@@ -32,16 +32,16 @@ void PrintOutputFileHeaderInfo(std::ofstream* f_out, const std::string& out_file
3232
// Print formatted header
3333
print_file_header(*f_out, header);
3434

35-
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "File name:" << std::filesystem::absolute(out_file).string() << std::endl << std::endl;
35+
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "File name:" << safe_absolute_path(out_file) << std::endl << std::endl;
3636

3737
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Command line arguments: ";
3838
*f_out << p->r.command_line_arguments << std::endl << std::endl;
3939

4040
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Network name:" << p->g.network_name << std::endl;
41-
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Input folder: " << std::filesystem::absolute(p->g.input_folder).string() << std::endl;
42-
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Output folder: " << std::filesystem::absolute(p->g.output_folder).string() << std::endl;
43-
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Stations file:" << std::filesystem::absolute(p->r.bst_file).string() << std::endl;
44-
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Measurements file:" << std::filesystem::absolute(p->r.bms_file).string() << std::endl;
41+
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Input folder: " << safe_absolute_path(p->g.input_folder) << std::endl;
42+
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Output folder: " << safe_absolute_path(p->g.output_folder) << std::endl;
43+
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Stations file:" << safe_absolute_path(p->r.bst_file) << std::endl;
44+
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Measurements file:" << safe_absolute_path(p->r.bms_file) << std::endl;
4545
*f_out << std::setw(PRINT_VAR_PAD) << std::left << "Target reference frame:" << p->r.reference_frame;
4646

4747
if (userSuppliedFrame)

dynadjust/dynadjust/metadata/precompile.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
/// \cond
1616
#include <windows.h>
1717

18-
#include <include/functions/dnatimer.hpp>
1918
#include <boost/date_time/posix_time/posix_time.hpp>
2019
#include <boost/thread.hpp>
2120
#include <boost/thread/mutex.hpp>
2221
#include <memory>
22+
#include <filesystem>
2323
#include <boost/program_options/options_description.hpp>
2424
#include <boost/program_options/parsers.hpp>
2525
#include <boost/program_options/variables_map.hpp>
26-
#include <filesystem>
2726
#include <boost/algorithm/string/predicate.hpp>
2827

2928
/// \endcond
3029

30+
#include <include/functions/dnatimer.hpp>
3131
#include <include/config/dnaversion.hpp>
3232
#include <include/config/dnaconsts.hpp>
3333
#include <include/config/dnaconsts-interface.hpp>

dynadjust/include/config/dnaprojectfile.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,15 +1725,15 @@ void CDnaProjectFile::PrintProjectFile()
17251725
dnaproj_file << OUTPUTLINE << std::endl;
17261726

17271727
PrintRecord(dnaproj_file, NETWORK_NAME, settings_.g.network_name); // network name
1728-
PrintRecord(dnaproj_file, INPUT_FOLDER, std::filesystem::absolute(settings_.g.input_folder).string()); // Path containing all input files
1729-
PrintRecord(dnaproj_file, OUTPUT_FOLDER, std::filesystem::absolute(settings_.g.output_folder).string()); // Path for all output files
1728+
PrintRecord(dnaproj_file, INPUT_FOLDER, safe_absolute_path(settings_.g.input_folder)); // Path containing all input files
1729+
PrintRecord(dnaproj_file, OUTPUT_FOLDER, safe_absolute_path(settings_.g.output_folder)); // Path for all output files
17301730
PrintRecord(dnaproj_file, VERBOSE, settings_.g.verbose); // Give detailed information about what dnainterop is doing.
17311731
// 0: No information (default)
17321732
// 1: Helpful information
17331733
// 2: Extended information\n3: Debug level information
17341734
PrintRecord(dnaproj_file, QUIET, yesno_string(settings_.g.quiet)); // Run quietly?
1735-
PrintRecord(dnaproj_file, PROJECT_FILE, std::filesystem::absolute(settings_.g.project_file).string()); // project file
1736-
PrintRecord(dnaproj_file, DYNADJUST_LOG_FILE, std::filesystem::absolute(settings_.g.log_file).string()); // dynadjust log file
1735+
PrintRecord(dnaproj_file, PROJECT_FILE, safe_absolute_path(settings_.g.project_file)); // project file
1736+
PrintRecord(dnaproj_file, DYNADJUST_LOG_FILE, safe_absolute_path(settings_.g.log_file)); // dynadjust log file
17371737

17381738
dnaproj_file << std::endl;
17391739

@@ -1851,7 +1851,7 @@ void CDnaProjectFile::PrintProjectFile()
18511851
dnaproj_file << OUTPUTLINE << std::endl;
18521852

18531853
// Output configured to populate binary station files
1854-
PrintRecord(dnaproj_file, NTV2_FILEPATH, std::filesystem::absolute(settings_.n.ntv2_geoid_file).string()); // Full file path to geoid file
1854+
PrintRecord(dnaproj_file, NTV2_FILEPATH, safe_absolute_path(settings_.n.ntv2_geoid_file)); // Full file path to geoid file
18551855

18561856
PrintRecord(dnaproj_file, METHOD, settings_.n.interpolation_method);
18571857
PrintRecord(dnaproj_file, DDEG_FORMAT, settings_.n.coordinate_format);

dynadjust/include/functions/dnafilepathfuncs.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <stdio.h>
3434
#include <stdarg.h>
3535
#include <string>
36+
#include <string_view>
3637

3738
#include <algorithm>
3839
#include <functional>
@@ -60,4 +61,15 @@ T leafStr(const T& filePath)
6061
return std::filesystem::path(filePath).filename().string();
6162
}
6263

64+
// Safe wrapper for std::filesystem::absolute that handles empty paths
65+
// On Linux, std::filesystem::absolute("") throws an exception
66+
// This function returns empty string for empty input
67+
// Accepts std::string_view for flexibility with both std::string and string_view
68+
inline std::string safe_absolute_path(std::string_view path)
69+
{
70+
if (path.empty())
71+
return "";
72+
return std::filesystem::absolute(std::string(path)).string();
73+
}
74+
6375
#endif //DNAFILEPATHFUNCS_H_

0 commit comments

Comments
 (0)