LCOV - code coverage report
Current view: top level - imageanalysis/IO - OutputDestinationChecker.cc (source / functions) Hit Total Coverage
Test: ctest_coverage.info Lines: 0 34 0.0 %
Date: 2023-11-02 14:27:30 Functions: 0 4 0.0 %

          Line data    Source code
       1             : 
       2             : //# Copyright (C) 1998,1999,2000,2001,2003
       3             : //# Associated Universities, Inc. Washington DC, USA.
       4             : //#
       5             : //# This program is free software; you can redistribute it and/or modify it
       6             : //# under the terms of the GNU General Public License as published by the Free
       7             : //# Software Foundation; either version 2 of the License, or (at your option)
       8             : //# any later version.
       9             : //#
      10             : //# This program is distributed in the hope that it will be useful, but WITHOUT
      11             : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
      13             : //# more details.
      14             : //#
      15             : //# You should have received a copy of the GNU General Public License along
      16             : //# with this program; if not, write to the Free Software Foundation, Inc.,
      17             : //# 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      18             : //#
      19             : //# Correspondence concerning AIPS++ should be addressed as follows:
      20             : //#        Internet email: aips2-request@nrao.edu.
      21             : //#        Postal address: AIPS++ Project Office
      22             : //#                        National Radio Astronomy Observatory
      23             : //#                        520 Edgemont Road
      24             : //#                        Charlottesville, VA 22903-2475 USA
      25             : //#
      26             : 
      27             : #include <imageanalysis/IO/OutputDestinationChecker.h>
      28             : 
      29             : #include <casacore/casa/OS/File.h>
      30             : 
      31             : 
      32             : using namespace casacore;
      33             : namespace casa {
      34             : 
      35           0 : OutputDestinationChecker::OutputDestinationChecker() {}
      36             : 
      37           0 : OutputDestinationChecker::~OutputDestinationChecker() {}
      38             : 
      39           0 : void OutputDestinationChecker::checkOutput(OutputStruct& output, LogIO& log) {
      40           0 :         String label = output.label;
      41           0 :         String name = *(output.outputFile);
      42           0 :         Bool required = output.required;
      43           0 :         Bool replaceable = output.replaceable;
      44           0 :         if (name.empty()) {
      45           0 :                 ThrowIf(
      46             :                         required, label + " cannot be blank"
      47             :                 );
      48           0 :                 return;
      49             :         }
      50           0 :         LogIO::Command logLevel = required ? LogIO::SEVERE : LogIO::WARN;
      51           0 :         LogIO::Command logAction = required ? LogIO::EXCEPTION : LogIO::POST;
      52           0 :         File f(name);
      53           0 :         switch (f.getWriteStatus()) {
      54           0 :         case File::NOT_CREATABLE:
      55             :                 log << logLevel << "Requested " << label << " " << name
      56           0 :                         << " cannot be created so will not be written" << logAction;
      57           0 :                 *(output.outputFile) = "";
      58           0 :                 break;
      59           0 :         case File::NOT_OVERWRITABLE:
      60             :                 log << logLevel << "There is already a file or directory named "
      61             :                         << name << " which cannot be overwritten so the " << label
      62           0 :                         << " will not be written" << logAction;
      63           0 :                 *(output.outputFile) = "";
      64           0 :                 break;
      65           0 :         case File::OVERWRITABLE:
      66           0 :                 if (! replaceable) {
      67             :                         log << logLevel << "Replaceable flag is false and there is "
      68             :                                 << "already a file or directory named " << name
      69             :                                 << " so the " << label << " will not be written"
      70           0 :                                 << logAction;
      71           0 :                         *(output.outputFile) = "";
      72             :                 }
      73           0 :                 break;
      74           0 :         default:
      75           0 :                 return;
      76             :         }
      77             : }
      78             : 
      79           0 : void OutputDestinationChecker::checkOutputs(
      80             :         std::vector<OutputStruct> * const output, LogIO& log
      81             : ) {
      82           0 :         if (output) {
      83           0 :                 for( OutputStruct elem: *output ) {
      84           0 :                         checkOutput(elem, log);
      85             :                 }
      86             :         }
      87           0 : }
      88             : } 

Generated by: LCOV version 1.16