| 1 | #pragma once |
|---|---|
| 2 | |
| 3 | #include <Core/Types.h> |
| 4 | #include <Common/Exception.h> |
| 5 | |
| 6 | #include <filesystem> |
| 7 | #include <memory> |
| 8 | #include <string> |
| 9 | #include <sys/statvfs.h> |
| 10 | #include <Poco/TemporaryFile.h> |
| 11 | |
| 12 | |
| 13 | namespace DB |
| 14 | { |
| 15 | namespace ErrorCodes |
| 16 | { |
| 17 | extern const int CANNOT_STATVFS; |
| 18 | } |
| 19 | |
| 20 | using TemporaryFile = Poco::TemporaryFile; |
| 21 | |
| 22 | bool enoughSpaceInDirectory(const std::string & path, size_t data_size); |
| 23 | std::unique_ptr<TemporaryFile> createTemporaryFile(const std::string & path); |
| 24 | |
| 25 | /// Returns mount point of filesystem where absoulte_path (must exist) is located |
| 26 | std::filesystem::path getMountPoint(std::filesystem::path absolute_path); |
| 27 | |
| 28 | /// Returns name of filesystem mounted to mount_point |
| 29 | #if !defined(__linux__) |
| 30 | [[noreturn]] |
| 31 | #endif |
| 32 | String getFilesystemName([[maybe_unused]] const String & mount_point); |
| 33 | |
| 34 | inline struct statvfs getStatVFS(const String & path) |
| 35 | { |
| 36 | struct statvfs fs; |
| 37 | if (statvfs(path.c_str(), &fs) != 0) |
| 38 | throwFromErrnoWithPath("Could not calculate available disk space (statvfs)", path, ErrorCodes::CANNOT_STATVFS); |
| 39 | return fs; |
| 40 | } |
| 41 | |
| 42 | } |
| 43 |