tv_rename/filesystem.cpp
2019-01-04 20:19:08 +01:00

30 lines
826 B
C++

#include "filesystem.hpp"
#include <sys/stat.h>
#include <stdlib.h>
#include <linux/limits.h>
bool FSLib::exists(const std::string &path) {
struct stat path_stat;
return stat( path.c_str(), &path_stat ) == 0;
}
bool FSLib::isDirectory(const std::string &path) {
struct stat path_stat;
stat( path.c_str(), &path_stat );
return S_ISDIR(path_stat.st_mode);
}
std::string FSLib::canonical(const std::string &path) {
char *canonical_path = static_cast<char *>(malloc(PATH_MAX));
if( realpath(path.c_str(), canonical_path) == nullptr )
return "";
std::string canonical_string{canonical_path};
free(canonical_path);
return canonical_string;
}
bool FSLib::rename(const std::string &file_a, const std::string &file_b) {
return ::rename( file_a.c_str(), file_b.c_str() ) == 0;
}