namespace {
-unsigned long long getAvailableSpace(const std::string& mountPoint)
+off_t getAvailableSpace(const std::string& mountPoint)
{
struct statfs statbuf;
if (::statfs(mountPoint.c_str(), &statbuf)) {
throw runtime::Exception("Failed to access " + mountPoint);
}
- return (unsigned long long)statbuf.f_bfree * statbuf.f_bsize;
+ return statbuf.f_bfree * statbuf.f_bsize;
}
bool wasEncrypted(const std::string &path)
#endif
}
-unsigned long long getEncryptedSize(const runtime::File &file) {
- unsigned long long originalSize = file.size();
- unsigned long long result = 0;
+off_t getEncryptedSize(const runtime::File &file) {
+ off_t originalSize = file.size();
+ off_t result = 0;
if (originalSize % 4096) {
originalSize = (1 + originalSize / 4096) * 4096;
//TODO : block size have to not hard-coded.
// If there is a better way, the followings have to be changed.
- unsigned int blockSize = 4096;
+ blksize_t blockSize = 4096;
if (result % blockSize) {
result = (1 + result / blockSize) * blockSize;
}
return result;
}
-unsigned long long getDecryptedSize(const runtime::File &file) {
- unsigned long long originalSize = file.size();
- unsigned long long result = originalSize;
+off_t getDecryptedSize(const runtime::File &file) {
+ off_t originalSize = file.size();
+ off_t result = originalSize;
if (wasEncrypted(file.getPath())) {
if (originalSize > 2 * 4096) {
//TODO : block size have to not hard-coded.
// If there is a better way, the followings have to be changed.
- unsigned int blockSize = 4096;
+ blksize_t blockSize = 4096;
if (result % blockSize) {
result = (1 + result / blockSize) * blockSize;
}
}
bool isEnoughToCopyInPlace(const std::string& path,
- const std::function<unsigned long long(const runtime::File&)> getSizeFunc)
+ const std::function<off_t(const runtime::File&)> getSizeFunc)
{
- unsigned long long availableSpace = getAvailableSpace(path);
+ off_t availableSpace = getAvailableSpace(path);
std::function<bool(const std::string &path)> check;
check = [&check, &getSizeFunc, availableSpace](const std::string &path) {
void copyInPlace(const std::string& source, const std::string& destination,
const std::string& temp,
const std::function<bool(const std::string&)> &isTarget,
- const std::function<void(unsigned long long)> &addProgress)
+ const std::function<void(off_t)> &addProgress)
{
for (runtime::DirectoryIterator iter(source), end;
iter != end; ++iter) {
}
try {
- unsigned long long totalSize = getAvailableSpace(source), current;
+ off_t totalSize = getAvailableSpace(source), current;
runtime::File tempDir(destination + "/" ENCRYPTION_TMP_DIR);
if (tempDir.exists()) {
[](const std::string &file) {
return true;
},
- [¤t, &totalSize, this](unsigned long long size) {
+ [¤t, &totalSize, this](off_t size) {
current += size;
this->progress.update(current * 100 / totalSize);
});
progress.update(0);
try {
- unsigned long long totalSize = getAvailableSpace(source), current;
+ off_t totalSize = getAvailableSpace(source), current;
runtime::File tempDir(source + "/" ENCRYPTION_TMP_DIR);
runtime::File tempMountpoint(tempDir.getPath() + "/mount");
copyInPlace(tempMountpoint.getPath(), source,
tempDir.getPath(), wasEncrypted,
- [¤t, &totalSize, this](unsigned long long size) {
+ [¤t, &totalSize, this](off_t size) {
current += size;
this->progress.update(current * 100 / totalSize);
});