Do not prepend the output path to an already-absolute output name#1475
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1475 +/- ##
==========================================
- Coverage 25.10% 25.10% -0.01%
==========================================
Files 171 171
Lines 18843 18844 +1
==========================================
Hits 4731 4731
- Misses 14112 14113 +1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
I am in two minds with regard to this PR, do we really want to bypass the output path using absolute paths?
|
|
On Linux and similar operating systems you can already do this implicitly by setting I had problems using scripts on Windows to create output where it needed to be rather than in the aircraft (or script folder) that prevented me from using the scripts in a single library for testing variants of models. I guess this is more of a bugfix than a new feature. |
There is the method Lines 342 to 351 in 32aa2af Are you using it ? It's a much more portable and versatile way to prevent your aircraft and script folders from being polluted by output files. |
|
But there doesn't seem to be a command line argument, unless I'm missing it, to set the output path? So it looks like JSBSim defaults to the current directory? Line 397 in 32aa2af And if you're writing a C++ wrapper or using the Python wrapper then you can call Lines 842 to 863 in 32aa2af My understanding is that @Zaretto had script files/aircraft files with <output name="B737_datalog.csv" type="CSV" rate="20">
<property> velocities/vc-kts </property>
<velocities> ON </velocities>
</output>@Zaretto I'm not sure why you don't think this is an issue in Linux since your example But if you want an absolute path from the root then you will also run into this issue on Linux. |
True. But that will no longer be the case once the PR #1478 will be merged 😉 Note also that as you mentioned, the output files are by default written to the current directory when using the executable |
|
Hmm, in terms of 'current' directory, I had thought of mentioning above that @Zaretto could potentially change the current directory to where he wanted his output file to go, but I only just tried that for interest now with: C:\source\temp\FlightTests>C:\source\jsbsim\Debug\JSBSim.exe --root=\source\jsbsim\ C:\source\jsbsim\scripts\737_cruise.xmlWhere However I noticed that I guess the Lines 715 to 720 in d89e357 |
Yes, I am, and keeping the aircraft and script folders clean was exactly part of what I needed to solve. So we agree on the goal. My problem was twofold. First, setting the output to an absolute path on Windows (including the drive specification) produced mangled paths. An absolute name only works while the output path is unset. Once an output path is set, the name is appended to it:
That is why I see this as a bug fix rather than a feature change. Absolute output names are already accepted, they are just silently corrupted once an output path is also set. Second, I genuinely needed the output in two different places on disk, and a single output path only gives me one. For example, the parameter log from the test script goes to one location and the aircraft debug files to another. At the time I could not build JSBSim from source and had to use a prebuilt executable, so I worked around it with a batch file that ran JSBSim and then shuffled the output into the right places afterwards. Honouring absolute names lets JSBSim write each output to its final location directly and removes that step. |
Indeed. I had forgotten this subtlety. |
|
I'd suggest a slight rewording of the comment:
// If fname is a relative filepath then prepend the configured output path,
// otherwise use the absolute filepath. |
Yep! And move it in the Doxygen comments/docs just above: jsbsim/src/input_output/FGOutputFile.h Lines 97 to 102 in c9d0f18 |
|
Great catch @Zaretto, I also had similar problems. The PR looks good to me too. |
…path handling The rule for relative and absolute output names was only an inline comment in the method body. Move it into the method's Doxygen so the path-handling contract appears in the generated API documentation. Also correct the documented parameter name from name to fname.
|
Looks good. |
FGOutputFile::SetOutputName always joins the configured output path with the supplied name, which produces a malformed path when the name is itself absolute. Take an absolute name as-is; only relative names are resolved under the output path.
…path handling The rule for relative and absolute output names was only an inline comment in the method body. Move it into the method's Doxygen so the path-handling contract appears in the generated API documentation. Also correct the documented parameter name from name to fname.
b1f853d to
c083df8
Compare
Fix issue when FGOutputFile::SetOutputName joins the configured output path with the supplied name, which produces a malformed path when the name is itself absolute.
i.e.; Take an absolute name as-is; only relative names are resolved under the output path.