Bug #2287

ctselect doesn't work with prefixes beginning with 'g' or 'z'

Added by Cardenzana Josh over 6 years ago. Updated over 6 years ago.

Status:ClosedStart date:12/04/2017
Priority:NormalDue date:
Assigned To:Cardenzana Josh% Done:

100%

Category:-
Target version:1.5.0
Duration:

Description

ctselect includes a step where it strips the trailing '.gz' from the output filename if it is present (ctselect.cpp line 1277):
// Strip any ".gz" 
outname = gammalib::strip_chars(outname, ".gz");

However, the 'gammalib::strip_chars()' method will strip any '.', 'g’ or 'z’ from both ends of the filename. This can cause ctselect to fail or alter the filename if the output prefix begins with one of these characters. For example:
  • 'prefix=zselect_’ will save to files beginning with '-select_’.
  • 'prefix=gdir/select_’ will try to save to the sub-directory 'dir’, which isn’t the desired location and may not exist.

A quick search of the ctools code shows that the same method is also present in ctool.cpp (line 1151) for removing the trailing '.gz’ from a filename. This can be fixed by using the 'gammalib::rstrip_chars()' method which only removes these characters if they occur at the end of the filename.


Recurrence

No recurrence.

History

#1 Updated by Cardenzana Josh over 6 years ago

  • Status changed from New to Pull request
  • % Done changed from 0 to 90

The above changes have been made to ctool::set_outfile_name() and ctselect::set_outfile_name() and work as expected (i.e. a leading 'g’ or 'z’ in the output filename of ctselect is no longer removed from the output filename).

It should be noted that if a filename that ends with any of 'g’, 'z’ or '.' is passed, it will still be trimmed even if it doesn’t end in '.gz’ (for example 'image.jpg’ would be shorted to 'image.jp’). Since this hasn’t been an issue so far, I assume the above solution is sufficient.

Pull Branch:
Josh Cardenzana / ctools (branch: 2287-gz_filename_strip)

#2 Updated by Knödlseder Jürgen over 6 years ago

  • Target version set to 1.5.0

The methods in ctools.cpp and ctselect.cpp were in fact identical, I therefore removed the ctselect::set_outfile_name() method to prevent code duplication.

Although the proposed fix works it seems cleaner to strip only .gz strings. This is done by adding the following code:

// Strip any ".gz" from the outname
std::string            strip   = ".gz";
std::string::size_type i_start = outname.find(strip);
if (i_start != std::string::npos) {
    outname.erase(i_start, strip.length());
}

#3 Updated by Knödlseder Jürgen over 6 years ago

  • Status changed from Pull request to Closed
  • % Done changed from 90 to 100

Merged into devel.

Also available in: Atom PDF