/** Constructor. */ ConfigFileHandler::ConfigFileHandler( const String& currentFile, const String& plannedFile, const Boolean offLine) : _offLine(offLine) { String cFile; String pFile; // // Set the current and planned config files // cFile = ConfigManager::getHomedPath(currentFile); pFile = ConfigManager::getHomedPath(plannedFile); // // Initialize instance variables. // _currentFileExist = true; _plannedFileExist = true; _currentConfFile.reset(new ConfigFile(cFile)); _plannedConfFile.reset(new ConfigFile(pFile)); _currentConfig = new ConfigTable; _plannedConfig = new ConfigTable; // // check whether the planned file exists or not // if (!FileSystem::exists(pFile)) { _plannedFileExist = false; return; } // // check whether the file is readable or not // if (!FileSystem::canRead(pFile)) { throw FileNotReadable(pFile); } // // check whether the current file exists or not // if (!FileSystem::exists(cFile)) { _currentFileExist = false; // // Current file need not exist. // try creating one so that planned file contents // can be copied over. // FILE* is = Executor::openFile(cFile.getCString(), 'w'); if (!is) { // unable to create file PEG_TRACE((TRC_CONFIG, Tracer::LEVEL1, "Failed to create config file: %s", (const char*)cFile.getCString())); throw NoSuchFile(cFile); } fclose(is); } // // check whether the file is readable or not // if (!FileSystem::canRead(cFile)) { throw FileNotReadable(cFile); } }
/** Constructor. */ ConfigFileHandler::ConfigFileHandler ( const String& currentFile, const String& plannedFile, const Boolean offLine) : _offLine(offLine) { String cFile; String pFile; // // Set the current and planned config files // cFile = ConfigManager::getHomedPath(currentFile); pFile = ConfigManager::getHomedPath(plannedFile); // // Initialize instance variables. // _currentFileExist = true; _plannedFileExist = true; _currentConfFile.reset(new ConfigFile(cFile)); _plannedConfFile.reset(new ConfigFile(pFile)); _currentConfig = new ConfigTable; _plannedConfig = new ConfigTable; // // check whether the planned file exists or not // if (!FileSystem::exists(pFile)) { _plannedFileExist = false; return; } // // check whether the file is readable or not // if (!FileSystem::canRead(pFile)) { throw FileNotReadable(pFile); } // // check whether the current file exists or not // if (!FileSystem::exists(cFile)) { _currentFileExist = false; // // Current file need not exist. // try creating one so that planned file contents // can be copied over. // #if defined(PEGASUS_OS_OS400) ofstream ofs(cFile.getCString(), PEGASUS_STD(_CCSID_T(1208))); #else ofstream ofs(cFile.getCString()); #endif if (!ofs) { // unable to create file PEG_TRACE_STRING(TRC_CONFIG, Tracer::LEVEL4, "Failed to create config file: " + cFile + ", " + strerror(errno)); throw NoSuchFile(cFile); } ofs.close(); } // // check whether the file is readable or not // if (!FileSystem::canRead(cFile)) { throw FileNotReadable(cFile); } }