Fix #1547 - timeshift: do not create directories until needed

This tries to minimise what is written to disk (inc dirs) when
using on-demand mode. This could result in the failure to write
the buffer not being detected till later and not entirely sure
how clients might handle that.
This commit is contained in:
Adam Sutton 2013-01-18 17:22:44 +00:00
parent 7f89b3d552
commit 2dcbc36327
2 changed files with 12 additions and 7 deletions

View file

@ -215,7 +215,8 @@ timeshift_destroy(streaming_target_t *pad)
if (ts->smt_start)
streaming_start_unref(ts->smt_start);
free(ts->path);
if (ts->path)
free(ts->path);
free(ts);
}
@ -228,20 +229,15 @@ timeshift_destroy(streaming_target_t *pad)
streaming_target_t *timeshift_create
(streaming_target_t *out, time_t max_time)
{
char buf[512];
timeshift_t *ts = calloc(1, sizeof(timeshift_t));
/* Must hold global lock */
lock_assert(&global_lock);
/* Create directories */
if (timeshift_filemgr_makedirs(timeshift_index, buf, sizeof(buf)))
return NULL;
/* Setup structure */
TAILQ_INIT(&ts->files);
ts->output = out;
ts->path = strdup(buf);
ts->path = NULL;
ts->max_time = max_time;
ts->state = TS_INIT;
ts->full = 0;

View file

@ -240,6 +240,15 @@ timeshift_file_t *timeshift_filemgr_get ( timeshift_t *ts, int create )
/* Create new file */
tsf_tmp = NULL;
if (!ts->full) {
/* Create directories */
if (!ts->path) {
if (timeshift_filemgr_makedirs(ts->id, path, sizeof(path)))
return NULL;
ts->path = strdup(path);
}
/* Create File */
snprintf(path, sizeof(path), "%s/tvh-%"PRItime_t, ts->path, time);
#ifdef TSHFT_TRACE
tvhlog(LOG_DEBUG, "timeshift", "ts %d create file %s", ts->id, path);