Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
DVR: Use the system limits for the filename length, fixes #3038
  • Loading branch information
perexg committed Sep 8, 2015
1 parent 30fc455 commit 4570ce6
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/dvr/dvr_rec.c
Expand Up @@ -539,6 +539,7 @@ pvr_generate_filename(dvr_entry_t *de, const streaming_start_t *ss)
dvr_config_t *cfg;
htsmsg_t *m;
size_t l, j;
long max;

if (de == NULL)
return -1;
Expand Down Expand Up @@ -631,11 +632,14 @@ pvr_generate_filename(dvr_entry_t *de, const streaming_start_t *ss)
htsstr_unescape_to(path, filename, sizeof(filename));
if (makedirs(filename, cfg->dvr_muxcnf.m_directory_permissions, -1, -1) != 0)
return -1;
max = pathconf(filename, _PC_NAME_MAX);
if (max < 8)
max = NAME_MAX;
j = strlen(filename);
snprintf(filename + j, sizeof(filename) - j, "/%s", dirsep);
if (filename[j] == '/')
j++;

/* Unique filename loop */
while (1) {

Expand All @@ -645,6 +649,16 @@ pvr_generate_filename(dvr_entry_t *de, const streaming_start_t *ss)
} else {
number[0] = '\0';
}
/* Check the maximum filename length */
l = strlen(number);
if (l + strlen(filename + j) > max) {
l = j + (max - l);
if (filename[l - 1] == '$') /* not optimal */
filename[l + 1] = '\0';
else
filename[l] = '\0';
}

htsstr_substitute(filename + j, ptmp, sizeof(ptmp), '$', dvr_subs_tally, number);
s = cleanup_filename(cfg, ptmp);
if (s == NULL)
Expand Down

0 comments on commit 4570ce6

Please sign in to comment.