vdr-1.3.22: do not create zero-sized vdr.nnn files
Commit Message
The following patch avoids the creation of zero sized vdr.nnn files if a
recording is disturbed (loss of signal etc.). Without this patch it is
possible to fill up a recording directory with 0-sized files up to the
maximum vdr.255 quite fast.
Testers and feedback welcome.
Wolfgang
Comments
On Sat, Mar 12, 2005 at 08:04:58PM +0100, Wolfgang Fritz wrote:
> The following patch avoids the creation of zero sized vdr.nnn files if a
> recording is disturbed (loss of signal etc.). Without this patch it is
> possible to fill up a recording directory with 0-sized files up to the
> maximum vdr.255 quite fast.
Great idea !!!
> Testers and feedback welcome.
So far it works great here ;-)
Thank you very much for the patch.
===================================================================
@@ -1124,8 +1124,25 @@
fileNumber = Number;
sprintf(pFileNumber, RECORDFILESUFFIX, fileNumber);
if (record) {
- if (access(fileName, F_OK) == 0) // file exists, let's try next suffix
- return SetOffset(Number + 1);
+ if (access(fileName, F_OK) == 0) {
+ // files exists, check if it has non-zero size
+ struct stat buf;
+ if (stat(fileName, &buf) == 0) {
+ if (buf.st_size != 0) {
+ // file exists and has non zero size, let's try next suffix
+ return SetOffset(Number + 1);
+ }
+ else {
+ // Zero size file. Remove it.
+ dsyslog ("cFileName::SetOffset: Removing zero-sized file %s\n", fileName);
+ unlink (fileName);
+ }
+ }
+ else {
+ // error with fstat. Should not happen, just to be on the safe side
+ return SetOffset(Number + 1);
+ }
+ }
else if (errno != ENOENT) { // something serious has happened
LOG_ERROR_STR(fileName);
return -1;