#include "common/file_system/file_system.h"
#include "common/exception/io.h"
#include "common/string_utils.h"
#include <format>
namespace lbug {
namespace common {
void FileSystem::overwriteFile(const std::string& , const std::string& ) {
UNREACHABLE_CODE;
}
void FileSystem::renameFile(const std::string& from, const std::string& to) {
std::error_code ec;
std::filesystem::rename(from, to, ec);
if (ec) {
throw IOException(
std::format("Error renaming file {} to {}. ErrorMessage: {}", from, to, ec.message()));
}
}
void FileSystem::copyFile(const std::string& , const std::string& ) {
UNREACHABLE_CODE;
}
void FileSystem::createDir(const std::string& ) const {
UNREACHABLE_CODE;
}
void FileSystem::removeFileIfExists(const std::string&, const main::ClientContext* ) {
UNREACHABLE_CODE;
}
bool FileSystem::fileOrPathExists(const std::string& , main::ClientContext* ) {
UNREACHABLE_CODE;
}
std::string FileSystem::expandPath(main::ClientContext* ,
const std::string& path) const {
return path;
}
std::string FileSystem::joinPath(const std::string& base, const std::string& part) {
return base + "/" + part;
}
std::string FileSystem::getFileExtension(const std::filesystem::path& path) {
auto extension = path.extension();
if (isCompressedFile(path)) {
extension = path.stem().extension();
}
return extension.string();
}
bool FileSystem::isCompressedFile(const std::filesystem::path& path) {
return isGZIPCompressed(path);
}
std::string FileSystem::getFileName(const std::filesystem::path& path) {
return path.filename().string();
}
void FileSystem::writeFile(FileInfo& , const uint8_t* , uint64_t ,
uint64_t ) const {
UNREACHABLE_CODE;
}
void FileSystem::truncate(FileInfo& , uint64_t ) const {
UNREACHABLE_CODE;
}
void FileSystem::reset(FileInfo& fileInfo) {
fileInfo.seek(0, SEEK_SET);
}
bool FileSystem::isGZIPCompressed(const std::filesystem::path& path) {
auto extensionLowerCase = StringUtils::getLower(path.extension().string());
return extensionLowerCase == ".gz" || extensionLowerCase == ".gzip";
}
} }