traverso-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Traverso-commit] traverso/src/core ProjectManager.cpp


From: Remon Sijrier
Subject: [Traverso-commit] traverso/src/core ProjectManager.cpp
Date: Thu, 22 Nov 2007 16:46:22 +0000

CVSROOT:        /sources/traverso
Module name:    traverso
Changes by:     Remon Sijrier <r_sijrier>       07/11/22 16:46:22

Modified files:
        src/core       : ProjectManager.cpp 

Log message:
        * remove the oldest 200 backupfiles if the amount of files becomes > 
1000

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/traverso/src/core/ProjectManager.cpp?cvsroot=traverso&r1=1.49&r2=1.50

Patches:
Index: ProjectManager.cpp
===================================================================
RCS file: /sources/traverso/traverso/src/core/ProjectManager.cpp,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -b -r1.49 -r1.50
--- ProjectManager.cpp  5 Nov 2007 15:49:30 -0000       1.49
+++ ProjectManager.cpp  22 Nov 2007 16:46:21 -0000      1.50
@@ -505,7 +505,7 @@
        QString backupdir = project_path + "/projectfilebackup";
        
        // Check if the projectfilebackup directory still exist
-       QDir dir;
+       QDir dir(backupdir);
        if (!dir.exists(backupdir)) {
                create_projectfilebackup_dir(project_path);
        }
@@ -532,6 +532,35 @@
        stream << compressed;
        
        compressedWriter.close();
+       
+       // A map to insert files based on their time value,
+       // so it's sorted on date automatically
+       QMap<int, QString> map;
+       QStringList entrylist = dir.entryList(QDir::Files);
+       
+       // If there are more then 1000 saves, remove the last 200!
+       if (entrylist.size() > 1000) {
+               printf("more then thousand backup files, deleting oldest 
200\n");
+               
+               int key;
+               foreach (QString file, dir.entryList(QDir::Files)) {
+                       key = file.right(10).toUInt();
+                       map.insert(key, file);
+               }
+               
+               QList<QString> tobedeleted = map.values();
+               
+               if (tobedeleted.size() < 201) {
+                       return;
+               }
+
+               for(int i=0; i<200; ++i) {
+                       QFile file(backupdir + "/" + tobedeleted.at(i));
+                       if ( ! file.remove() ) {
+                               printf("Could not remove file %s (Reason: 
%s)\n", QS_C(tobedeleted.at(i)), 
QS_C(FileHelper::fileerror_to_string(file.error())));
+                       }
+               }
+       }
 }
 
 int ProjectManager::restore_project_from_backup(const QString& projectname, 
uint restoretime)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]