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 977 : void OutputDestinationChecker::checkOutput(OutputStruct& output, LogIO& log) { 40 982 : String label = output.label; 41 982 : String name = *(output.outputFile); 42 977 : Bool required = output.required; 43 977 : Bool replaceable = output.replaceable; 44 977 : if (name.empty()) { 45 349 : ThrowIf( 46 : required, label + " cannot be blank" 47 : ); 48 349 : return; 49 : } 50 628 : LogIO::Command logLevel = required ? LogIO::SEVERE : LogIO::WARN; 51 628 : LogIO::Command logAction = required ? LogIO::EXCEPTION : LogIO::POST; 52 633 : File f(name); 53 628 : switch (f.getWriteStatus()) { 54 1 : case File::NOT_CREATABLE: 55 : log << logLevel << "Requested " << label << " " << name 56 1 : << " 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 50 : case File::OVERWRITABLE: 66 50 : 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 4 : << logAction; 71 0 : *(output.outputFile) = ""; 72 : } 73 46 : break; 74 577 : default: 75 577 : return; 76 : } 77 : } 78 : 79 958 : void OutputDestinationChecker::checkOutputs( 80 : std::vector<OutputStruct> * const output, LogIO& log 81 : ) { 82 958 : if (output) { 83 1916 : for( OutputStruct elem: *output ) { 84 958 : checkOutput(elem, log); 85 : } 86 : } 87 953 : } 88 : }