В сообщении от Sunday 17 January 2021 02:49:31 Reuss András via Cin написал(а):
>  Reuss András

So, I modified your patch and now it  hopefully makes only 50
new copies of backup.prev_timestamp 

I tried to hit 'b' that many times, or do normal operations.

There is some complication

According to manual (section 6.3, page 159 by document's numeration) 
some backups from OpenEDL sub-timelines will be created 
as backup1.xml ... backup9.xml

I hope I covered this part in my filter line
"backup*.prev_*"

but testing (with caution!) as always welcomed

===

PS: 

I also think this functionality (OpenEDL) should have their own line in 
tips :}

And effect dragging via clips ..(BT#84)


diff --git a/cinelerra-5.1/cinelerra/mwindow.C b/cinelerra-5.1/cinelerra/mwindow.C
index 04549fde..e021d86c 100644
--- a/cinelerra-5.1/cinelerra/mwindow.C
+++ b/cinelerra-5.1/cinelerra/mwindow.C
@@ -296,6 +296,7 @@ MWindow::~MWindow()
 	plugin_gui_lock->unlock();
 	hide_keyframe_guis();
 	clean_indexes();
+	clean_backups();
 	save_defaults();
 // Give up and go to a movie
 //  cant run valgrind if this is used
@@ -984,6 +985,61 @@ void MWindow::init_preferences()
 	YUV::yuv.yuv_set_colors(preferences->yuv_color_space, preferences->yuv_color_range);
 }
 
+void MWindow::clean_backups()
+{
+    FileSystem fs;
+    int total_excess;
+    long oldest = 0;
+    int oldest_item = -1;
+    int result;
+    char string[BCTEXTLEN];
+
+// Delete extra backups
+    fs.set_filter("backup*.prev_*");
+    fs.complete_path(preferences->index_directory);
+    fs.update(preferences->index_directory);
+
+    // set to 50 for now
+    // total_excess = fs.dir_list.total - preferences->index_count;
+    total_excess = fs.dir_list.total - 50;
+    printf("Total excess of backups: %i \n", total_excess);
+
+//printf("MWindow::clean_backups 1 %d\n", fs.dir_list.total);
+
+    while(total_excess > 0)
+    {
+// Get oldest
+	for(int i = 0; i < fs.dir_list.total; i++)
+	{
+	    fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name);
+
+	    if(i == 0 || fs.get_date(string) <= oldest)
+	    {
+		oldest = fs.get_date(string);
+		oldest_item = i;
+	    }
+	}
+
+	if(oldest_item >= 0)
+	{
+// Remove backup file
+	    fs.join_names(string,
+		preferences->index_directory,
+		fs.dir_list[oldest_item]->name);
+//printf("MWindow::clean_backups 1 %s\n", string);
+	    if(remove(string))
+		perror("delete_backups");
+	    delete fs.dir_list[oldest_item];
+	    fs.dir_list.remove_number(oldest_item);
+
+	}
+
+	total_excess--;
+    }
+}
+
+
+
 void MWindow::clean_indexes()
 {
 	FileSystem fs;
@@ -4270,6 +4326,25 @@ void MWindow::get_backup_path(char *path, int len)
 	cp += snprintf(cp, ep-cp, idx ? BACKUPn_FILE : BACKUP_FILE, idx);
 }
 
+void MWindow::create_timestamped_copy_from_previous_backup(char *previouspath)
+{
+  if (previouspath == nullptr) return;
+  char backup_path[BCTEXTLEN];
+  backup_path[0] = 0;
+  time_t now = time(NULL);
+  struct tm* currenttime = localtime(&now);
+  snprintf(backup_path, sizeof(backup_path),
+      "%s/%s_%d%.2d%.2d_%.2d%.2d%.2d",
+      File::get_config_path(), BACKUP_FILE1,
+      currenttime->tm_year + 1900,
+      currenttime->tm_mon + 1,
+      currenttime->tm_mday,
+      currenttime->tm_hour,
+      currenttime->tm_min,
+      currenttime->tm_sec);
+	rename(previouspath, backup_path);
+}
+
 void MWindow::save_backup()
 {
 	FileXML file;
@@ -4280,6 +4355,7 @@ void MWindow::save_backup()
 	snprintf(backup_path1, sizeof(backup_path1), "%s/%s",
 		File::get_config_path(), BACKUP_FILE1);
 	get_backup_path(backup_path, sizeof(backup_path));
+  create_timestamped_copy_from_previous_backup(backup_path1);
 	rename(backup_path, backup_path1);
 	edl->save_xml(&file, backup_path);
 	file.terminate_string();
diff --git a/cinelerra-5.1/cinelerra/mwindow.h b/cinelerra-5.1/cinelerra/mwindow.h
index 8f9bfbb7..8634ea51 100644
--- a/cinelerra-5.1/cinelerra/mwindow.h
+++ b/cinelerra-5.1/cinelerra/mwindow.h
@@ -23,6 +23,7 @@
 
 #include <stdio.h>
 #include <stdint.h>
+#include <time.h>
 
 #include "apatchgui.h"
 #include "arraylist.h"
@@ -384,6 +385,7 @@ public:
 	void crop_video(int mode);
 	void update_plugins();
 	void get_backup_path(char *path, int len);
+  void create_timestamped_copy_from_previous_backup(char *previouspath);
 // Call after every edit operation
 	void save_backup();
 	void load_backup();
@@ -852,6 +854,7 @@ public:
 	int get_cpus(int out_w, int out_h);
 	int get_cpus();
 //
+	void clean_backups();
 	void clean_indexes();
 //	TimeBomb timebomb;
 	SigHandler *sighandler;
-- 
Cin mailing list
Cin@lists.cinelerra-gg.org
https://lists.cinelerra-gg.org/mailman/listinfo/cin

Reply via email to