From 2dcbc3632736a2323ecdeb6f1853e0b134836f3c Mon Sep 17 00:00:00 2001 From: Adam Sutton Date: Fri, 18 Jan 2013 17:22:44 +0000 Subject: [PATCH] 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. --- src/timeshift.c | 10 +++------- src/timeshift/timeshift_filemgr.c | 9 +++++++++ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/timeshift.c b/src/timeshift.c index d0cdd856..2ecc39b4 100644 --- a/src/timeshift.c +++ b/src/timeshift.c @@ -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; diff --git a/src/timeshift/timeshift_filemgr.c b/src/timeshift/timeshift_filemgr.c index 4b90eb60..635f4769 100644 --- a/src/timeshift/timeshift_filemgr.c +++ b/src/timeshift/timeshift_filemgr.c @@ -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);