mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-23 13:04:23 +00:00
Change Utils::Fs::freeDiskSpaceOnPath() signature
refactor the function internals
This commit is contained in:
parent
0b313e0bc3
commit
5cf86d3677
@ -269,50 +269,43 @@ bool Utils::Fs::isValidFileSystemName(const QString &name, bool allowSeparators)
|
||||
return !name.contains(regex);
|
||||
}
|
||||
|
||||
qlonglong Utils::Fs::freeDiskSpaceOnPath(QString path)
|
||||
qulonglong Utils::Fs::freeDiskSpaceOnPath(const QString &path)
|
||||
{
|
||||
if (path.isEmpty()) return -1;
|
||||
QDir dir_path(path);
|
||||
if (!dir_path.exists()) {
|
||||
if (path.isEmpty()) return 0;
|
||||
|
||||
QDir dirPath(path);
|
||||
if (!dirPath.exists()) {
|
||||
QStringList parts = path.split("/");
|
||||
while (parts.size() > 1 && !QDir(parts.join("/")).exists()) {
|
||||
while (parts.size() > 1 && !QDir(parts.join("/")).exists())
|
||||
parts.removeLast();
|
||||
}
|
||||
dir_path = QDir(parts.join("/"));
|
||||
if (!dir_path.exists()) return -1;
|
||||
|
||||
dirPath = QDir(parts.join("/"));
|
||||
if (!dirPath.exists()) return 0;
|
||||
}
|
||||
Q_ASSERT(dir_path.exists());
|
||||
Q_ASSERT(dirPath.exists());
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
ULARGE_INTEGER bytesFree;
|
||||
if (GetDiskFreeSpaceExW((LPCTSTR)(toNativePath(dir_path.path())).utf16(), &bytesFree, NULL, NULL) == 0)
|
||||
return -1;
|
||||
return qlonglong(bytesFree.QuadPart);
|
||||
LPCWSTR nativePath = reinterpret_cast<LPCWSTR>((toNativePath(dirPath.path())).utf16());
|
||||
if (GetDiskFreeSpaceExW(nativePath, &bytesFree, NULL, NULL) == 0)
|
||||
return 0;
|
||||
return bytesFree.QuadPart;
|
||||
#elif defined(Q_OS_HAIKU)
|
||||
unsigned long long available;
|
||||
const QString statfs_path = dir_path.path() + "/.";
|
||||
dev_t device = dev_for_path (qPrintable(statfs_path));
|
||||
if (device >= 0) {
|
||||
fs_info info;
|
||||
if (fs_stat_dev(device, &info) == B_OK) {
|
||||
available = ((unsigned long long)(info.free_blocks * info.block_size));
|
||||
return available;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
const QString statfsPath = dirPath.path() + "/.";
|
||||
dev_t device = dev_for_path(qPrintable(statfsPath));
|
||||
if (device < 0)
|
||||
return 0;
|
||||
fs_info info;
|
||||
if (fs_stat_dev(device, &info) != B_OK)
|
||||
return 0;
|
||||
return ((qulonglong) info.free_blocks * (qulonglong) info.block_size);
|
||||
#else
|
||||
unsigned long long available;
|
||||
struct statfs stats;
|
||||
const QString statfs_path = dir_path.path() + "/.";
|
||||
const int ret = statfs(qPrintable(statfs_path), &stats);
|
||||
if (ret == 0) {
|
||||
available = ((unsigned long long)stats.f_bavail)
|
||||
* ((unsigned long long)stats.f_bsize);
|
||||
return available;
|
||||
}
|
||||
else {
|
||||
return -1;
|
||||
}
|
||||
const QString statfsPath = dirPath.path() + "/.";
|
||||
const int ret = statfs(qPrintable(statfsPath), &stats);
|
||||
if (ret != 0)
|
||||
return 0;
|
||||
return ((qulonglong) stats.f_bavail * (qulonglong) stats.f_bsize);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -50,7 +50,7 @@ namespace Utils
|
||||
bool sameFiles(const QString& path1, const QString& path2);
|
||||
QString toValidFileSystemName(const QString &name, bool allowSeparators = false);
|
||||
bool isValidFileSystemName(const QString& name, bool allowSeparators = false);
|
||||
qlonglong freeDiskSpaceOnPath(QString path);
|
||||
qulonglong freeDiskSpaceOnPath(const QString &path);
|
||||
QString branchPath(const QString& file_path, QString* removed = 0);
|
||||
bool sameFileNames(const QString& first, const QString& second);
|
||||
QString expandPath(const QString& path);
|
||||
|
Loading…
x
Reference in New Issue
Block a user