ClickHouse/dbms/Common/filesystemHelpers.h

43 lines
1.0 KiB
C++
Raw Normal View History

2019-10-01 18:51:33 +00:00
#pragma once
2019-11-27 09:39:44 +00:00
#include <Core/Types.h>
#include <Common/Exception.h>
2019-10-01 18:51:33 +00:00
2019-11-27 09:39:44 +00:00
#include <filesystem>
#include <memory>
#include <string>
#include <sys/statvfs.h>
2019-10-01 18:51:33 +00:00
#include <Poco/TemporaryFile.h>
2019-11-27 09:39:44 +00:00
2019-10-01 18:51:33 +00:00
namespace DB
{
2019-11-27 09:39:44 +00:00
namespace ErrorCodes
{
extern const int CANNOT_STATVFS;
}
2019-10-01 18:51:33 +00:00
using TemporaryFile = Poco::TemporaryFile;
2019-10-02 12:06:34 +00:00
bool enoughSpaceInDirectory(const std::string & path, size_t data_size);
2019-10-01 18:51:33 +00:00
std::unique_ptr<TemporaryFile> createTemporaryFile(const std::string & path);
2019-11-27 09:39:44 +00:00
/// Returns mount point of filesystem where absoulte_path (must exist) is located
std::filesystem::path getMountPoint(std::filesystem::path absolute_path);
/// Returns name of filesystem mounted to mount_point
#if !defined(__linux__)
[[noreturn]]
#endif
2019-12-03 13:37:40 +00:00
String getFilesystemName([[maybe_unused]] const String & mount_point);
2019-11-27 09:39:44 +00:00
inline struct statvfs getStatVFS(const String & path)
{
struct statvfs fs;
if (statvfs(path.c_str(), &fs) != 0)
throwFromErrnoWithPath("Could not calculate available disk space (statvfs)", path, ErrorCodes::CANNOT_STATVFS);
return fs;
}
2019-10-01 18:51:33 +00:00
}