mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-30 08:51:04 +02:00
CFileHelpers: add function getDirSize()
Origin commit data
------------------
Branch: ni/coolstream
Commit: 1b095e725e
Author: Thilo Graf <dbt@novatux.de>
Date: 2015-02-07 (Sat, 07 Feb 2015)
------------------
No further description and justification available within origin commit message!
------------------
This commit was generated by Migit
This commit is contained in:
@@ -722,6 +722,34 @@ bool CFileHelpers::removeDir(const char *Dir)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u_int64_t CFileHelpers::getDirSize(const char *dirname)
|
||||||
|
{
|
||||||
|
DIR *d;
|
||||||
|
struct dirent *de;
|
||||||
|
struct stat buf;
|
||||||
|
int exists;
|
||||||
|
u_int64_t total_size = 0;
|
||||||
|
|
||||||
|
d = opendir(dirname);
|
||||||
|
if (d == NULL) {
|
||||||
|
perror("prsize");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (de = readdir(d); de != NULL; de = readdir(d)) {
|
||||||
|
exists = stat(de->d_name, &buf);
|
||||||
|
if (exists < 0) {
|
||||||
|
fprintf(stderr, "Couldn't stat %s\n", de->d_name);
|
||||||
|
} else {
|
||||||
|
total_size += buf.st_size;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closedir(d);
|
||||||
|
|
||||||
|
return total_size;
|
||||||
|
}
|
||||||
|
|
||||||
static int hdd_open_dev(const char * fname)
|
static int hdd_open_dev(const char * fname)
|
||||||
{
|
{
|
||||||
FILE * fp;
|
FILE * fp;
|
||||||
|
@@ -91,6 +91,8 @@ class CFileHelpers
|
|||||||
static int createDir(std::string& Dir, mode_t mode = 755);
|
static int createDir(std::string& Dir, mode_t mode = 755);
|
||||||
static int createDir(const char *Dir, mode_t mode = 755){std::string dir = std::string(Dir);return createDir(dir, mode);}
|
static int createDir(const char *Dir, mode_t mode = 755){std::string dir = std::string(Dir);return createDir(dir, mode);}
|
||||||
static bool removeDir(const char *Dir);
|
static bool removeDir(const char *Dir);
|
||||||
|
static uint64_t getDirSize(const char *dir);
|
||||||
|
static uint64_t getDirSize(const std::string& dir){return getDirSize(dir.c_str());};
|
||||||
};
|
};
|
||||||
|
|
||||||
std::string to_string(int);
|
std::string to_string(int);
|
||||||
|
Reference in New Issue
Block a user