Commit 70c3666b authored by Marco De Marco's avatar Marco De Marco
Browse files

Check if file exists on get property method

parent 89bd658e
Loading
Loading
Loading
Loading
+31 −1
Original line number Diff line number Diff line
@@ -44,7 +44,9 @@
#include <Configuration.h>
#include <PlainServer.h>
#include <SSLServer.h>
#include <bits/c++config.h>
#include <bits/c++config.h> //@todo: controllare

#include <boost/filesystem.hpp>

/*----- PROTECTED REGION END -----*/	//	MetadataExporter.cpp

@@ -399,11 +401,17 @@ void MetadataExporter::get_device_property()
            if(certificateFile.empty())
                throw(invalid_argument("CertificateFile property is empty or not defined"));

            checkIfFileExists(certificateFile);

            if(privateKeyFile.empty())
                throw(invalid_argument("PrivateKeyFile property is empty or not defined"));

            checkIfFileExists(privateKeyFile);

            if(dHTempFile.empty())
                throw(invalid_argument("DHTempFile property is empty or not defined"));

            checkIfFileExists(dHTempFile);
        }

        if(databaseHost.empty())
@@ -633,5 +641,27 @@ void MetadataExporter::importAuthorisedUsers(std::vector<std::string>& authorise
        }
}

//==============================================================================
//      MetadataExporter::checkIfFileExists()
//==============================================================================
void MetadataExporter::checkIfFileExists(std::string fileName)
    throw(std::invalid_argument)
{
    boost::filesystem::path path(fileName);

    if(!boost::filesystem::exists(path))
    {
        std::stringstream errorStream;
        errorStream << "File " << fileName
            << " not exists" << std::endl;
        throw std::invalid_argument(errorStream.str());
    }

    #ifdef VERBOSE_DEBUG
        INFO_STREAM << "FILE: " << fileName << " -> OK" << endl;
        INFO_STREAM << "-------------------------------------------------" << endl;
    #endif
}

/*----- PROTECTED REGION END -----*/	//	MetadataExporter::namespace_ending
} //	namespace
+3 −0
Original line number Diff line number Diff line
@@ -225,6 +225,9 @@ protected:
        std::map<const std::string, const std::string>&)
        throw(std::invalid_argument);

    virtual void checkIfFileExists(std::string)
        throw(std::invalid_argument);

/*----- PROTECTED REGION END -----*/	//	MetadataExporter::Additional Method prototypes
};