Commit 630e59c5 authored by kulvait's avatar kulvait

fileExists renamed to pathExists

New functions to test existing directory and regular file added
isDirectory
isRegularFile
parent bd157a95
......@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.1)
project(CTIOL)
set(CMAKE_INSTALL_PREFIX $ENV{HOME}/bin)
set(CMAKE_CXX_STANDARD 14)#Supported values are 98, 11 and 14.
set(CMAKE_CXX_STANDARD 17)#Supported values are 98, 11 and 14.
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra")
message("Current value of flags is ${CMAKE_CXX_FLAGS} and debug is ${CMAKE_CXX_FLAGS_DEBUG} and release is ${CMAKE_CXX_FLAGS_RELEASE}")
......@@ -145,7 +145,7 @@ target_link_libraries(test_ctiol Catch)
target_link_libraries(test_ctiol CTIOL)
target_link_libraries(test_ctiol CTIOL_DENITK)
target_link_libraries(test_ctiol ctmal)
target_link_libraries(test_ctiol stdc++fs)
add_custom_target(formatWebkit
./formatWebkit
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
......
......@@ -76,7 +76,7 @@ namespace io {
this->sizez = dimz;
uint64_t elementByteSize = sizeof(T);
uint64_t totalFileSize = uint64_t(6) + elementByteSize * dimx * dimy * dimz;
if(io::fileExists(projectionsFile))
if(io::pathExists(projectionsFile))
{
uint64_t fileSize = io::getFileSize(projectionsFile);
if(fileSize != totalFileSize)
......
......@@ -28,7 +28,9 @@ namespace io {
void writeBytesFrom(std::string fileName, uint64_t fromPosition, uint8_t* buffer, uint64_t numBytes);
void appendBytes(std::string fileName, uint8_t* buffer, uint64_t numBytes);
void createEmptyFile(std::string fileName, uint64_t numBytes, bool overwrite);
bool fileExists(std::string fileName);
bool pathExists(std::string fileName);
bool isDirectory(const std::experimental::filesystem::path& p);
bool isRegularFile(const std::experimental::filesystem::path& p);
long getFileSize(std::string filename);
std::string getParent(const std::string& path);
std::string getBasename(const std::string& path);
......
......@@ -178,7 +178,17 @@ namespace io {
}
}
bool fileExists(std::string fileName) { return (access(fileName.c_str(), F_OK) != -1); }
bool pathExists(std::string fileName) { return (access(fileName.c_str(), F_OK) != -1); }
bool isDirectory(const std::experimental::filesystem::path& p)
{
return std::experimental::filesystem::is_directory(p);
}
bool isRegularFile(const std::experimental::filesystem::path& p)
{
return std::experimental::filesystem::is_regular_file(p);
}
std::string getParent(const std::string& path)
{
......@@ -217,7 +227,7 @@ namespace io {
void createEmptyFile(std::string fileName, uint64_t numBytes, bool overwrite)
{
if(!fileExists(fileName) || overwrite)
if(!pathExists(fileName) || overwrite)
{
std::ofstream ofs(
fileName,
......@@ -248,12 +258,18 @@ namespace io {
*/
std::string fileToString(const std::string& f)
{
if(!fileExists(f))
if(!pathExists(f))
{
std::string ERR = io::xprintf("File %s does not exist.", f.c_str());
LOGE << ERR;
io::throwerr(ERR);
}
if(!isRegularFile(f))
{
std::string ERR = io::xprintf("File %s is not a regular file.", f.c_str());
LOGE << ERR;
io::throwerr(ERR);
}
std::ifstream ifs(f.c_str(), std::ios::in | std::ios::binary | std::ios::ate);
std::ifstream::pos_type fileSize = ifs.tellg();
......@@ -269,7 +285,7 @@ namespace io {
bool overwrite,
std::initializer_list<std::string> inputFiles)
{
if(fileExists(outputFile) && !overwrite)
if(pathExists(outputFile) && !overwrite)
{
std::string ERR = io::xprintf("Ouptut file %s exists and overwrite is not set.",
outputFile.c_str());
......@@ -279,10 +295,10 @@ namespace io {
std::ofstream ofs(outputFile, std::ios_base::binary | std::ios::trunc);
for(std::string f : inputFiles)
{
if(!fileExists(f))
if(!isRegularFile(f))
{
std::string ERR
= io::xprintf("One of the files to concatenate %s does not exist!", f.c_str());
= io::xprintf("File %s from the files to concatenate is not regular file!", f.c_str());
LOGE << ERR;
throw std::ios_base::failure(ERR);
}
......
Subproject commit 59e547c3902e22996811bb6ec2caeea6210e166b
Subproject commit 75b87d6df46b03edb39e11e7cb126df02d4aa5d6
Subproject commit 54089c4c8c657ffb13d8f3a1425403335af5ba4d
Subproject commit 2c869e17e4803d30b3d5ca5b0d76387b9db97fa5
Subproject commit 5f69a631086bf038e2c0feee4319a485c34fa863
Subproject commit f4c22b03d5d3aa753cca8e716636ac4eb29b0917
......@@ -26,3 +26,11 @@ TEST_CASE("TEST: absolute path.", "rawop.h")
std::string p = io::getParent("abc");
//LOGE << p;
}
TEST_CASE("Filesystem operations", "[filesystem]")
{
REQUIRE(io::pathExists("/tmp"));
REQUIRE(io::isDirectory("/tmp"));
REQUIRE(!io::isRegularFile("/tmp"));
//LOGE << p;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment