Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
implement minimal retention period
  • Loading branch information
Glenn-1990 authored and perexg committed Sep 30, 2016
1 parent 747ed01 commit eed35c0
Show file tree
Hide file tree
Showing 9 changed files with 226 additions and 136 deletions.
4 changes: 2 additions & 2 deletions src/api/api_dvr.c
Expand Up @@ -245,8 +245,8 @@ api_dvr_entry_create_by_event
e, 0, 0,
perm->aa_username,
perm->aa_representative,
NULL, DVR_PRIO_NORMAL, DVR_RET_DVRCONFIG,
DVR_RET_DVRCONFIG, comment);
NULL, DVR_PRIO_NORMAL, DVR_RET_REM_DVRCONFIG,
DVR_RET_REM_DVRCONFIG, comment);
if (de)
idnode_changed(&de->de_id);
}
Expand Down
45 changes: 25 additions & 20 deletions src/dvr/dvr.h
Expand Up @@ -54,6 +54,7 @@ typedef struct dvr_config {
int dvr_clone;
uint32_t dvr_rerecord_errors;
uint32_t dvr_retention_days;
uint32_t dvr_retention_minimal;
uint32_t dvr_removal_days;
uint32_t dvr_autorec_max_count;
uint32_t dvr_autorec_max_sched_count;
Expand Down Expand Up @@ -128,24 +129,25 @@ typedef enum {
} dvr_rs_state_t;

typedef enum {
DVR_RET_DVRCONFIG = 0,
DVR_RET_1DAY = 1,
DVR_RET_3DAY = 3,
DVR_RET_5DAY = 5,
DVR_RET_1WEEK = 7,
DVR_RET_2WEEK = 14,
DVR_RET_3WEEK = 21,
DVR_RET_1MONTH = (30+1),
DVR_RET_2MONTH = (60+2),
DVR_RET_3MONTH = (90+2),
DVR_RET_6MONTH = (180+3),
DVR_RET_1YEAR = (365+1),
DVR_RET_2YEARS = (2*365+1),
DVR_RET_3YEARS = (3*365+1),
DVR_RET_ONREMOVE = INT32_MAX-1, // for retention only
DVR_RET_SPACE = INT32_MAX-1, // for removal only
DVR_RET_FOREVER = INT32_MAX
} dvr_retention_t;
DVR_RET_MIN_DISABLED = 0, /* For dvr config minimal retention only */
DVR_RET_REM_DVRCONFIG = 0,
DVR_RET_REM_1DAY = 1,
DVR_RET_REM_3DAY = 3,
DVR_RET_REM_5DAY = 5,
DVR_RET_REM_1WEEK = 7,
DVR_RET_REM_2WEEK = 14,
DVR_RET_REM_3WEEK = 21,
DVR_RET_REM_1MONTH = (30+1),
DVR_RET_REM_2MONTH = (60+2),
DVR_RET_REM_3MONTH = (90+2),
DVR_RET_REM_6MONTH = (180+3),
DVR_RET_REM_1YEAR = (365+1),
DVR_RET_REM_2YEARS = (2*365+1),
DVR_RET_REM_3YEARS = (3*365+1),
DVR_RET_ONREMOVE = INT32_MAX-1, /* For retention only */
DVR_REM_SPACE = INT32_MAX-1, /* For removal only */
DVR_RET_REM_FOREVER = INT32_MAX
} dvr_retention_removal_t;

typedef struct dvr_entry {

Expand Down Expand Up @@ -205,6 +207,7 @@ typedef struct dvr_entry {
int de_pri;
int de_dont_reschedule;
int de_dont_rerecord;
uint32_t de_file_removed;
uint32_t de_retention;
uint32_t de_removal;

Expand Down Expand Up @@ -450,7 +453,7 @@ void dvr_config_destroy_by_profile(profile_t *pro, int delconf);

static inline uint32_t dvr_retention_cleanup(uint32_t val)
{
return val > DVR_RET_FOREVER ? DVR_RET_FOREVER : val;
return val > DVR_RET_REM_FOREVER ? DVR_RET_REM_FOREVER : val;
}

/*
Expand Down Expand Up @@ -585,7 +588,9 @@ void dvr_entry_dec_ref(dvr_entry_t *de);

int dvr_entry_delete(dvr_entry_t *de);

void dvr_entry_cancel_delete(dvr_entry_t *de, int rerecord);
void dvr_entry_cancel_delete(dvr_entry_t *de, int rerecord, int forcedestroy);

void dvr_entry_trydestroy(dvr_entry_t *de);

int dvr_entry_file_moved(const char *src, const char *dst);

Expand Down
16 changes: 8 additions & 8 deletions src/dvr/dvr_autorec.c
Expand Up @@ -125,7 +125,7 @@ dvr_autorec_completed(dvr_autorec_entry_t *dae, int error_code)
if (de_prev) {
tvhinfo(LS_DVR, "autorec %s removing recordings %s (allowed count %u total %u)",
dae->dae_name, idnode_uuid_as_str(&de_prev->de_id, ubuf), max_count, total);
dvr_entry_cancel_delete(de_prev, 0);
dvr_entry_cancel_delete(de_prev, 0, 0);
}
}
}
Expand Down Expand Up @@ -1189,7 +1189,7 @@ const idclass_t dvr_autorec_entry_class = {
.id = "retention",
.name = N_("DVR log retention"),
.desc = N_("Number of days to retain infomation about recording."),
.def.i = DVR_RET_DVRCONFIG,
.def.i = DVR_RET_REM_DVRCONFIG,
.off = offsetof(dvr_autorec_entry_t, dae_retention),
.list = dvr_entry_class_retention_list,
.opts = PO_HIDDEN | PO_EXPERT | PO_DOC_NLIST,
Expand All @@ -1199,7 +1199,7 @@ const idclass_t dvr_autorec_entry_class = {
.id = "removal",
.name = N_("DVR file retention period"),
.desc = N_("Number of days to keep the recorded file."),
.def.i = DVR_RET_DVRCONFIG,
.def.i = DVR_RET_REM_DVRCONFIG,
.off = offsetof(dvr_autorec_entry_t, dae_removal),
.list = dvr_entry_class_removal_list,
.opts = PO_HIDDEN | PO_ADVANCED | PO_DOC_NLIST,
Expand Down Expand Up @@ -1506,12 +1506,12 @@ uint32_t
dvr_autorec_get_retention_days( dvr_autorec_entry_t *dae )
{
if (dae->dae_retention > 0) {
if (dae->dae_retention > DVR_RET_FOREVER)
return DVR_RET_FOREVER;
if (dae->dae_retention > DVR_RET_REM_FOREVER)
return DVR_RET_REM_FOREVER;

uint32_t removal = dvr_autorec_get_removal_days(dae);
/* As we need the db entry when deleting the file on disk */
if (removal != DVR_RET_FOREVER && removal > dae->dae_retention)
if (removal != DVR_RET_REM_FOREVER && removal > dae->dae_retention)
return DVR_RET_ONREMOVE;

return dae->dae_retention;
Expand All @@ -1526,8 +1526,8 @@ uint32_t
dvr_autorec_get_removal_days( dvr_autorec_entry_t *dae )
{
if (dae->dae_removal > 0) {
if (dae->dae_removal > DVR_RET_FOREVER)
return DVR_RET_FOREVER;
if (dae->dae_removal > DVR_RET_REM_FOREVER)
return DVR_RET_REM_FOREVER;

return dae->dae_removal;
}
Expand Down
109 changes: 72 additions & 37 deletions src/dvr/dvr_config.c
Expand Up @@ -178,7 +178,8 @@ dvr_config_create(const char *name, const char *uuid, htsmsg_t *conf)
cfg->dvr_enabled = 1;
cfg->dvr_config_name = strdup(name);
cfg->dvr_retention_days = DVR_RET_ONREMOVE;
cfg->dvr_removal_days = DVR_RET_FOREVER;
cfg->dvr_retention_minimal = DVR_RET_MIN_DISABLED;
cfg->dvr_removal_days = DVR_RET_REM_FOREVER;
cfg->dvr_clone = 1;
cfg->dvr_tag_files = 1;
cfg->dvr_skip_commercials = 1;
Expand Down Expand Up @@ -531,13 +532,13 @@ dvr_config_changed(dvr_config_t *cfg)
dvr_config_storage_check(cfg);
if (cfg->dvr_cleanup_threshold_free < 50)
cfg->dvr_cleanup_threshold_free = 50; // as checking is only periodically, lower is not save
if (cfg->dvr_removal_days != DVR_RET_FOREVER &&
if (cfg->dvr_removal_days != DVR_RET_REM_FOREVER &&
cfg->dvr_removal_days > cfg->dvr_retention_days)
cfg->dvr_retention_days = DVR_RET_ONREMOVE;
if (cfg->dvr_removal_days > DVR_RET_FOREVER)
cfg->dvr_removal_days = DVR_RET_FOREVER;
if (cfg->dvr_retention_days > DVR_RET_FOREVER)
cfg->dvr_retention_days = DVR_RET_FOREVER;
if (cfg->dvr_removal_days > DVR_RET_REM_FOREVER)
cfg->dvr_removal_days = DVR_RET_REM_FOREVER;
if (cfg->dvr_retention_days > DVR_RET_REM_FOREVER)
cfg->dvr_retention_days = DVR_RET_REM_FOREVER;
}


Expand Down Expand Up @@ -719,21 +720,21 @@ static htsmsg_t *
dvr_config_class_removal_list ( void *o, const char *lang )
{
static const struct strtab_u32 tab[] = {
{ N_("1 day"), DVR_RET_1DAY },
{ N_("3 days"), DVR_RET_3DAY },
{ N_("5 days"), DVR_RET_5DAY },
{ N_("1 week"), DVR_RET_1WEEK },
{ N_("2 weeks"), DVR_RET_2WEEK },
{ N_("3 weeks"), DVR_RET_3WEEK },
{ N_("1 month"), DVR_RET_1MONTH },
{ N_("2 months"), DVR_RET_2MONTH },
{ N_("3 months"), DVR_RET_3MONTH },
{ N_("6 months"), DVR_RET_6MONTH },
{ N_("1 year"), DVR_RET_1YEAR },
{ N_("2 years"), DVR_RET_2YEARS },
{ N_("3 years"), DVR_RET_3YEARS },
{ N_("Maintained space"), DVR_RET_SPACE },
{ N_("Forever"), DVR_RET_FOREVER },
{ N_("1 day"), DVR_RET_REM_1DAY },
{ N_("3 days"), DVR_RET_REM_3DAY },
{ N_("5 days"), DVR_RET_REM_5DAY },
{ N_("1 week"), DVR_RET_REM_1WEEK },
{ N_("2 weeks"), DVR_RET_REM_2WEEK },
{ N_("3 weeks"), DVR_RET_REM_3WEEK },
{ N_("1 month"), DVR_RET_REM_1MONTH },
{ N_("2 months"), DVR_RET_REM_2MONTH },
{ N_("3 months"), DVR_RET_REM_3MONTH },
{ N_("6 months"), DVR_RET_REM_6MONTH },
{ N_("1 year"), DVR_RET_REM_1YEAR },
{ N_("2 years"), DVR_RET_REM_2YEARS },
{ N_("3 years"), DVR_RET_REM_3YEARS },
{ N_("Maintained space"), DVR_REM_SPACE },
{ N_("Forever"), DVR_RET_REM_FOREVER },
};
return strtab2htsmsg_u32(tab, 1, lang);
}
Expand All @@ -742,21 +743,44 @@ static htsmsg_t *
dvr_config_class_retention_list ( void *o, const char *lang )
{
static const struct strtab_u32 tab[] = {
{ N_("1 day"), DVR_RET_1DAY },
{ N_("3 days"), DVR_RET_3DAY },
{ N_("5 days"), DVR_RET_5DAY },
{ N_("1 week"), DVR_RET_1WEEK },
{ N_("2 weeks"), DVR_RET_2WEEK },
{ N_("3 weeks"), DVR_RET_3WEEK },
{ N_("1 month"), DVR_RET_1MONTH },
{ N_("2 months"), DVR_RET_2MONTH },
{ N_("3 months"), DVR_RET_3MONTH },
{ N_("6 months"), DVR_RET_6MONTH },
{ N_("1 year"), DVR_RET_1YEAR },
{ N_("2 years"), DVR_RET_2YEARS },
{ N_("3 years"), DVR_RET_3YEARS },
{ N_("1 day"), DVR_RET_REM_1DAY },
{ N_("3 days"), DVR_RET_REM_3DAY },
{ N_("5 days"), DVR_RET_REM_5DAY },
{ N_("1 week"), DVR_RET_REM_1WEEK },
{ N_("2 weeks"), DVR_RET_REM_2WEEK },
{ N_("3 weeks"), DVR_RET_REM_3WEEK },
{ N_("1 month"), DVR_RET_REM_1MONTH },
{ N_("2 months"), DVR_RET_REM_2MONTH },
{ N_("3 months"), DVR_RET_REM_3MONTH },
{ N_("6 months"), DVR_RET_REM_6MONTH },
{ N_("1 year"), DVR_RET_REM_1YEAR },
{ N_("2 years"), DVR_RET_REM_2YEARS },
{ N_("3 years"), DVR_RET_REM_3YEARS },
{ N_("On file removal"), DVR_RET_ONREMOVE },
{ N_("Forever"), DVR_RET_FOREVER },
{ N_("Forever"), DVR_RET_REM_FOREVER },
};
return strtab2htsmsg_u32(tab, 1, lang);
}

static htsmsg_t *
dvr_config_class_retention_list_minimal ( void *o, const char *lang )
{
static const struct strtab_u32 tab[] = {
{ N_("Disabled"), DVR_RET_MIN_DISABLED },
{ N_("1 day"), DVR_RET_REM_1DAY },
{ N_("3 days"), DVR_RET_REM_3DAY },
{ N_("5 days"), DVR_RET_REM_5DAY },
{ N_("1 week"), DVR_RET_REM_1WEEK },
{ N_("2 weeks"), DVR_RET_REM_2WEEK },
{ N_("3 weeks"), DVR_RET_REM_3WEEK },
{ N_("1 month"), DVR_RET_REM_1MONTH },
{ N_("2 months"), DVR_RET_REM_2MONTH },
{ N_("3 months"), DVR_RET_REM_3MONTH },
{ N_("6 months"), DVR_RET_REM_6MONTH },
{ N_("1 year"), DVR_RET_REM_1YEAR },
{ N_("2 years"), DVR_RET_REM_2YEARS },
{ N_("3 years"), DVR_RET_REM_3YEARS },
{ N_("Forever"), DVR_RET_REM_FOREVER },
};
return strtab2htsmsg_u32(tab, 1, lang);
}
Expand Down Expand Up @@ -900,20 +924,31 @@ const idclass_t dvr_config_class = {
.type = PT_U32,
.id = "retention-days",
.name = N_("DVR log retention period"),
.desc = N_("Number of days to retain infomation about recordings."),
.desc = N_("Number of days to retain information about recordings. Once this period is exceeded, duplicate detection will not be possible for this recording."),
.off = offsetof(dvr_config_t, dvr_retention_days),
.def.u32 = DVR_RET_ONREMOVE,
.list = dvr_config_class_retention_list,
.opts = PO_EXPERT | PO_DOC_NLIST,
.group = 1,
},
{
.type = PT_U32,
.id = "retention-minimal",
.name = N_("Minimal log retention period"),
.desc = N_("Minimal number of days to retain information from recordings that where deleted manually. Once this period is exceeded, duplicate detection will not be possible for this recording."),
.off = offsetof(dvr_config_t, dvr_retention_minimal),
.def.u32 = DVR_RET_MIN_DISABLED,
.list = dvr_config_class_retention_list_minimal,
.opts = PO_EXPERT | PO_DOC_NLIST,
.group = 1,
},
{
.type = PT_U32,
.id = "removal-days",
.name = N_("DVR file retention period"),
.desc = N_("Number of days to keep the recorded files."),
.off = offsetof(dvr_config_t, dvr_removal_days),
.def.u32 = DVR_RET_FOREVER,
.def.u32 = DVR_RET_REM_FOREVER,
.list = dvr_config_class_removal_list,
.opts = PO_DOC_NLIST,
.group = 1,
Expand Down

0 comments on commit eed35c0

Please sign in to comment.