From 579719a7f24079bc36939c6b7757030b7299ba29 Mon Sep 17 00:00:00 2001 From: Klaus Schmidinger Date: Sun, 18 Dec 2005 10:41:26 +0100 Subject: When displaying the amount of free disk space, the space consumed by "deleted" recordings is now taken into account --- tools.c | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'tools.c') diff --git a/tools.c b/tools.c index 4a4a3aa6..5937d857 100644 --- a/tools.c +++ b/tools.c @@ -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]; -- cgit v1.2.3