diff options
author | Klaus Schmidinger <vdr@tvdr.de> | 2005-12-18 10:41:26 +0100 |
---|---|---|
committer | Klaus Schmidinger <vdr@tvdr.de> | 2005-12-18 10:41:26 +0100 |
commit | 579719a7f24079bc36939c6b7757030b7299ba29 (patch) | |
tree | 4c9ba173f8e58d16e96c993f3b561fb14a898c03 /tools.c | |
parent | db35165e25974df8719d253cde398831877c526d (diff) | |
download | vdr-579719a7f24079bc36939c6b7757030b7299ba29.tar.gz vdr-579719a7f24079bc36939c6b7757030b7299ba29.tar.bz2 |
When displaying the amount of free disk space, the space consumed by "deleted" recordings is now taken into account
Diffstat (limited to 'tools.c')
-rw-r--r-- | tools.c | 38 |
1 files changed, 37 insertions, 1 deletions
@@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: tools.c 1.104 2005/11/26 14:12:31 kls Exp $ + * $Id: tools.c 1.105 2005/12/18 10:33:04 kls Exp $ */ #include "tools.h" @@ -421,6 +421,42 @@ bool RemoveEmptyDirectories(const char *DirName, bool RemoveThis) return false; } +int DirSizeMB(const char *DirName) +{ + cReadDir d(DirName); + if (d.Ok()) { + int size = 0; + struct dirent *e; + while (size >= 0 && (e = d.Next()) != NULL) { + if (strcmp(e->d_name, ".") && strcmp(e->d_name, "..")) { + char *buffer; + asprintf(&buffer, "%s/%s", DirName, e->d_name); + struct stat st; + if (stat(buffer, &st) == 0) { + if (S_ISDIR(st.st_mode)) { + int n = DirSizeMB(buffer); + if (n >= 0) + size += n; + else + size = -1; + } + else + size += st.st_size / MEGABYTE(1); + } + else { + LOG_ERROR_STR(buffer); + size = -1; + } + free(buffer); + } + } + return size; + } + else + LOG_ERROR_STR(DirName); + return -1; +} + char *ReadLink(const char *FileName) { char RealName[PATH_MAX]; |