diff --git a/docs/html/config_timeshift.html b/docs/html/config_timeshift.html
index 3265118b..bf1e6052 100644
--- a/docs/html/config_timeshift.html
+++ b/docs/html/config_timeshift.html
@@ -29,7 +29,6 @@
If checked, this allows the timeshift buffer to grow unbounded until
your storage media runs out of space (WARNING: this could be dangerous!).
-
Changes to any of these settings must be confirmed by pressing the
diff --git a/src/timeshift.h b/src/timeshift.h
index 5281e8b5..342c7c66 100644
--- a/src/timeshift.h
+++ b/src/timeshift.h
@@ -27,6 +27,9 @@ extern uint32_t timeshift_max_period;
extern int timeshift_unlimited_size;
extern size_t timeshift_max_size;
+extern size_t timeshift_total_size;
+extern pthread_mutex_t timeshift_size_lock;
+
void timeshift_init ( void );
void timeshift_term ( void );
void timeshift_save ( void );
diff --git a/src/timeshift/timeshift_filemgr.c b/src/timeshift/timeshift_filemgr.c
index 2e2661bd..fc097bc4 100644
--- a/src/timeshift/timeshift_filemgr.c
+++ b/src/timeshift/timeshift_filemgr.c
@@ -38,6 +38,9 @@ static pthread_t timeshift_reaper_thread;
static pthread_mutex_t timeshift_reaper_lock;
static pthread_cond_t timeshift_reaper_cond;
+pthread_mutex_t timeshift_size_lock;
+size_t timeshift_total_size;
+
/* **************************************************************************
* File reaper thread
* *************************************************************************/
@@ -72,6 +75,10 @@ static void* timeshift_reaper_callback ( void *p )
if (errno != ENOTEMPTY)
tvhlog(LOG_ERR, "timeshift", "failed to remove %s [e=%s]",
dpath, strerror(errno));
+ pthread_mutex_lock(×hift_size_lock);
+ assert(tsf->size >= timeshift_total_size);
+ timeshift_total_size -= tsf->size;
+ pthread_mutex_unlock(×hift_size_lock);
/* Free memory */
while ((ti = TAILQ_FIRST(&tsf->iframes))) {
@@ -218,8 +225,13 @@ timeshift_file_t *timeshift_filemgr_get ( timeshift_t *ts, int create )
}
/* Check size */
- // TODO: need to implement this
-
+ pthread_mutex_lock(×hift_size_lock);
+ if (!timeshift_unlimited_size && timeshift_total_size >= timeshift_max_size) {
+ tvhlog(LOG_DEBUG, "timshift", "ts %d buffer full", ts->id);
+ ts->full = 1;
+ }
+ pthread_mutex_unlock(×hift_size_lock);
+
/* Create new file */
tsf_tmp = NULL;
if (!ts->full) {
@@ -304,6 +316,10 @@ void timeshift_filemgr_init ( void )
timeshift_filemgr_get_root(path, sizeof(path));
rmtree(path);
+ /* Size processing */
+ timeshift_total_size = 0;
+ pthread_mutex_init(×hift_size_lock, NULL);
+
/* Start the reaper thread */
timeshift_reaper_run = 1;
pthread_mutex_init(×hift_reaper_lock, NULL);
diff --git a/src/timeshift/timeshift_writer.c b/src/timeshift/timeshift_writer.c
index 0fb3129f..8bf6be03 100644
--- a/src/timeshift/timeshift_writer.c
+++ b/src/timeshift/timeshift_writer.c
@@ -224,6 +224,9 @@ static inline ssize_t _process_msg0
if (err > 0) {
tsf->last = sm->sm_time;
tsf->size += err;
+ pthread_mutex_lock(×hift_size_lock);
+ timeshift_total_size += err;
+ pthread_mutex_unlock(×hift_size_lock);
}
return err;
}
diff --git a/src/webui/static/app/timeshift.js b/src/webui/static/app/timeshift.js
index 059aae78..02335006 100644
--- a/src/webui/static/app/timeshift.js
+++ b/src/webui/static/app/timeshift.js
@@ -56,15 +56,13 @@ tvheadend.timeshift = function() {
fieldLabel: 'Max. Size (MB)',
name: 'timeshift_max_size',
allowBlank: false,
- width: 300,
- hidden : true
+ width: 300
});
var timeshiftUnlSize = new Ext.form.Checkbox({
fieldLabel: ' (unlimited)',
name: 'timeshift_unlimited_size',
- Width: 300,
- hidden : true
+ Width: 300
});
/* ****************************************************************