]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
Fix #1547 - timeshift: do not create directories until needed
authorAdam Sutton <dev@adamsutton.me.uk>
Fri, 18 Jan 2013 17:22:44 +0000 (17:22 +0000)
committerAdam Sutton <dev@adamsutton.me.uk>
Fri, 18 Jan 2013 17:22:44 +0000 (17:22 +0000)
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
src/timeshift/timeshift_filemgr.c

index d0cdd8566fe625ad2dd5076d286deb94e9728987..2ecc39b4b636b6cb25251b9a15c2d17fdc528fd6 100644 (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;
index 4b90eb60db1e5a0f2005df88c1c70d09a1e2f8aa..635f4769fc868e3cc12daec942b623b68df90d52 100644 (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);