Skip to content

Commit

Permalink
Merge pull request tvheadend#28 from nemphys/del-rec-dir.
Browse files Browse the repository at this point in the history
Also delete created directories (if they exist and are empty) when deleting a timer (recording)
  • Loading branch information
andoma committed May 3, 2011
2 parents 97b443d + f1cbc73 commit 206d129
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/dvr/dvr_db.c
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,34 @@ dvr_entry_delete(dvr_entry_t *de)
if(unlink(de->de_filename) && errno != ENOENT)
tvhlog(LOG_WARNING, "dvr", "Unable to remove file '%s' from disk -- %s",
de->de_filename, strerror(errno));

/* Also delete directories, if they were created for the recording and if they are empty */

dvr_config_t *cfg = dvr_config_find_by_name_default(de->de_config_name);
char path[500];

snprintf(path, sizeof(path), "%s", cfg->dvr_storage);

if(cfg->dvr_flags & DVR_DIR_PER_TITLE || cfg->dvr_flags & DVR_DIR_PER_CHANNEL || cfg->dvr_flags & DVR_DIR_PER_DAY) {
char *p;
int l;

l = strlen(de->de_filename);
p = alloca(l + 1);
memcpy(p, de->de_filename, l);
p[l--] = 0;

for(; l >= 0; l--) {
if(p[l] == '/') {
p[l] = 0;
if(strncmp(p, cfg->dvr_storage, strlen(p)) == 0)
break;
if(rmdir(p) == -1)
break;
}
}
}

}
dvr_entry_remove(de);
}
Expand Down

0 comments on commit 206d129

Please sign in to comment.