1
/* ---------------------------------- global.cpp ---------------------------------------------------------------------------
2
file containing all variables & functions used globaly
4
===============================================================================================================================
5
===============================================================================================================================
6
This file is part of "luckyBackup" project
7
Copyright 2008-2009, Loukas Avgeriou
8
luckyBackup is distributed under the terms of the GNU General Public License
9
luckyBackup is free software: you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation, either version 3 of the License, or
12
(at your option) any later version.
14
luckyBackup is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with luckyBackup. If not, see <http://www.gnu.org/licenses/>.
22
project version : Please see "main.cpp" for project version
25
last modified : 30 April 2009
26
===============================================================================================================================
27
===============================================================================================================================
30
#include "operationClass.h"
34
// loadProfile =====================================================================================================================================
35
// loads an existing profile
36
int loadProfile(QString profileToLoad)
39
profile.setFileName(profileToLoad);
41
if (!profile.open(QIODevice::ReadOnly)) //if the profile cannot be opened
47
QDataStream in(&profile);
48
in.setVersion(QDataStream::Qt_4_3);
50
QVariant v; //we will import everything as QVariant using this temp variable
51
QString vString; //temp variable to import "labels" of real data
52
QString tempAppName = "asxeto";
53
double tempAppVersion=0;
54
in>>v; if (v.toString()=="appName")
55
in >> v; tempAppName = v.toString(); //input the application name & version--------------------------
56
in>>v; if (v.toString()=="appVersion")
57
in >> v; tempAppVersion = v.toDouble();
59
if ( (tempAppName != appName) || (tempAppVersion < validProfileVersion) )//check if the file is a valid luckybackup profile
62
return 2; //profile is not valid
65
in>>v; if (v.toString()=="TotalOperations")
66
in >> v; TotalOperations = v.toInt(); //input the size of the operations list
68
currentOperation = 0; vString="";
69
while (currentOperation < TotalOperations)
71
operation *tempOp = new operation;
73
in>>v; vString = v.toString(); in >> v; //input a label in vString and real data in v
74
while (vString != "operation end")
76
if (vString == "Name") tempOp -> SetName(v.toString());
77
if (vString == "Args") tempOp -> SetArgs(v.toStringList());
79
if (vString == "AlsoCreateRestore") tempOp -> SetAlsoCreateRestore(v.toBool());
80
if (vString == "ConnectRestore") tempOp -> SetConnectRestore(v.toString());
82
if (vString == "TypeDirContents") tempOp -> SetTypeDirContents(v.toBool());
83
if (vString == "TypeDirName") tempOp -> SetTypeDirName(v.toBool());
84
if (vString == "TypeSync") tempOp -> SetTypeSync(v.toBool());
86
if (vString == "Source") tempOp -> SetSource(v.toString());
87
if (vString == "Destination") tempOp -> SetDestination(v.toString());
89
if (vString == "ExcludeTemp") tempOp -> SetExcludeTemp(v.toBool());
90
if (vString == "ExcludeCache") tempOp -> SetExcludeCache(v.toBool());
91
if (vString == "ExcludeBackup") tempOp -> SetExcludeBackup(v.toBool());
92
if (vString == "ExcludeMount") tempOp -> SetExcludeMount(v.toBool());
93
if (vString == "ExcludeLostFound") tempOp -> SetExcludeLostFound(v.toBool());
94
if (vString == "ExcludeSystem") tempOp -> SetExcludeSystem(v.toBool());
95
if (vString == "ExcludeTrash") tempOp -> SetExcludeTrash(v.toBool());
96
if (vString == "ExcludeListSize")
98
int excludeListSize = v.toInt();
100
while ( count < excludeListSize)
102
in >> v; tempOp -> AddExcludeListItem(v.toString());
106
tempOp -> SetExclude();
108
if (vString == "IncludeListSize")
110
int IncludeListSize = v.toInt();
112
while ( count < IncludeListSize)
115
tempOp -> AddIncludeListItem(v.toString());
119
tempOp -> SetInclude();
121
if (vString == "Remote") tempOp -> SetRemote(v.toBool());
122
if (vString == "RemoteModule") tempOp -> SetRemoteModule(v.toBool());
123
if (vString == "RemoteDestination") tempOp -> SetRemoteDestination(v.toBool());
124
if (vString == "RemoteSource") tempOp -> SetRemoteSource(v.toBool());
125
if (vString == "RemoteSSH") tempOp -> SetRemoteSSH(v.toBool());
126
if (vString == "RemoteHost") tempOp -> SetRemoteHost(v.toString());
127
if (vString == "RemoteUser") tempOp -> SetRemoteUser(v.toString());
128
if (vString == "RemotePassword") tempOp -> SetRemotePassword(v.toString());
129
if (vString == "RemoteSSHPassword") tempOp -> SetRemoteSSHPassword(v.toString());
130
if (vString == "RemoteSSHPort") tempOp -> SetRemoteSSHPort(v.toInt());
132
if (vString == "OptionsUpdate") tempOp -> SetOptionsUpdate(v.toBool());
133
if (vString == "OptionsDelete") tempOp -> SetOptionsDelete(v.toBool());
134
if (vString == "OptionsRecurse") tempOp -> SetOptionsRecurse(v.toBool());
135
if (vString == "OptionsOwnership") tempOp -> SetOptionsOwnership(v.toBool());
136
if (vString == "OptionsSymlinks") tempOp -> SetOptionsSymlinks(v.toBool());
137
if (vString == "OptionsPermissions") tempOp -> SetOptionsPermissions(v.toBool());
138
if (vString == "OptionsDevices") tempOp -> SetOptionsDevices(v.toBool());
139
if (vString == "OptionsCVS") tempOp -> SetOptionsCVS(v.toBool());
140
if (vString == "OptionsHardLinks") tempOp -> SetOptionsHardLinks(v.toBool());
141
if (vString == "OptionsListSize")
143
int OptionsListSize = v.toInt();
145
while ( count < OptionsListSize)
148
tempOp -> AddOptionsListItem(v.toString());
152
if (vString == "ExecuteBeforeListSize")
154
int ExecuteBeforeListSize = v.toInt();
156
while ( count < ExecuteBeforeListSize)
159
tempOp -> AddExecuteBeforeListItem(v.toString());
163
if (vString == "ExecuteAfterListSize")
165
int ExecuteAfterListSize = v.toInt();
167
while ( count < ExecuteAfterListSize)
170
tempOp -> AddExecuteAfterListItem(v.toString());
174
//import include checkbox state
175
if (vString == "IncludeState") tempOp -> SetIncluded(v.toBool());
176
in>>v; vString = v.toString();
177
if (vString!="operation end")
180
Operation[currentOperation] = tempOp;
188
// saveProfile =====================================================================================================================================
189
// saves an existing profile
190
bool saveProfile(QString profileToSave)
194
profile.setFileName(profileToSave);
196
if (!profile.open(QIODevice::WriteOnly)) // if the profile cannot be saved (or fails to create)
202
//write arrays to profile file
203
QDataStream out(&profile);
204
out.setVersion(QDataStream::Qt_4_3);
206
QVariant v; //we will export everything as QVariant using this temp variable
207
v = "appName"; out << v; v = appName; out << v; //output the application name
208
v = "appVersion"; out << v; v = appVersion; out << v; //output the application version
209
v = "TotalOperations"; out << v; v = TotalOperations; out << v; //output the size of the opeartions list
212
currentOperation = 0;
214
while ( currentOperation < TotalOperations )
216
v = "Name"; out << v; v = Operation[currentOperation] -> GetName(); out << v;
217
v = "Args"; out << v; v = Operation[currentOperation] -> GetArgs(); out << v;
219
v = "AlsoCreateRestore"; out << v; v = Operation[currentOperation] -> GetAlsoCreateRestore(); out << v;
220
v = "ConnectRestore"; out << v; v = Operation[currentOperation] -> GetConnectRestore(); out << v;
222
v = "TypeDirContents"; out << v; v = Operation[currentOperation] -> GetTypeDirContents(); out << v;
223
v = "TypeDirName"; out << v; v = Operation[currentOperation] -> GetTypeDirName(); out << v;
224
v = "TypeSync"; out << v; v = Operation[currentOperation] -> GetTypeSync(); out << v;
226
v = "Source"; out << v; v = Operation[currentOperation] -> GetSource(); out << v;
227
v = "Destination"; out << v; v = Operation[currentOperation] -> GetDestination(); out << v;
229
v = "Exclude"; out << v; v = Operation[currentOperation] -> GetExclude(); out << v;
230
v = "ExcludeTemp"; out << v; v = Operation[currentOperation] -> GetExcludeTemp(); out << v;
231
v = "ExcludeCache"; out << v; v = Operation[currentOperation] -> GetExcludeCache(); out << v;
232
v = "ExcludeBackup"; out << v; v = Operation[currentOperation] -> GetExcludeBackup(); out << v;
233
v = "ExcludeMount"; out << v; v = Operation[currentOperation] -> GetExcludeMount(); out << v;
234
v = "ExcludeLostFound"; out << v; v = Operation[currentOperation] -> GetExcludeLostFound(); out << v;
235
v = "ExcludeSystem"; out << v; v = Operation[currentOperation] -> GetExcludeSystem(); out << v;
236
v = "ExcludeTrash"; out << v; v = Operation[currentOperation] -> GetExcludeTrash(); out << v;
237
v = "ExcludeListSize"; out << v; v = Operation[currentOperation] -> GetExcludeListSize(); out << v;
239
while ( count < (Operation[currentOperation] -> GetExcludeListSize()) )
241
v = Operation[currentOperation] -> GetExcludeListItem(count); out << v;
245
v = "Include"; out << v; v = Operation[currentOperation] -> GetInclude(); out << v;
246
v = "IncludeListSize"; out << v; v = Operation[currentOperation] -> GetIncludeListSize(); out << v;
248
while ( count < (Operation[currentOperation] -> GetIncludeListSize()) )
250
v = Operation[currentOperation] -> GetIncludeListItem(count); out << v;
254
v = "Remote"; out << v; v = Operation[currentOperation] -> GetRemote(); out << v;
255
v = "RemoteModule"; out << v; v = Operation[currentOperation] -> GetRemoteModule(); out << v;
256
v = "RemoteDestination"; out << v; v = Operation[currentOperation] -> GetRemoteDestination(); out << v;
257
v = "RemoteSource"; out << v; v = Operation[currentOperation] -> GetRemoteSource(); out << v;
258
v = "RemoteSSH"; out << v; v = Operation[currentOperation] -> GetRemoteSSH(); out << v;
259
v = "RemoteHost"; out << v; v = Operation[currentOperation] -> GetRemoteHost(); out << v;
260
v = "RemoteUser"; out << v; v = Operation[currentOperation] -> GetRemoteUser(); out << v;
261
v = "RemotePassword"; out << v; v = Operation[currentOperation] -> GetRemotePassword(); out << v;
262
v = "RemoteSSHPassword"; out << v; v = Operation[currentOperation] -> GetRemoteSSHPassword(); out << v;
263
v = "RemoteSSHPort"; out << v; v = Operation[currentOperation] -> GetRemoteSSHPort(); out << v;
265
v = "OptionsUpdate"; out << v; v = Operation[currentOperation] -> GetOptionsUpdate(); out << v;
266
v = "OptionsDelete"; out << v; v = Operation[currentOperation] -> GetOptionsDelete(); out << v;
267
v = "OptionsRecurse"; out << v; v = Operation[currentOperation] -> GetOptionsRecurse(); out << v;
268
v = "OptionsOwnership"; out << v; v = Operation[currentOperation] -> GetOptionsOwnership(); out << v;
269
v = "OptionsSymlinks"; out << v; v = Operation[currentOperation] -> GetOptionsSymlinks(); out << v;
270
v = "OptionsPermissions"; out << v; v = Operation[currentOperation] -> GetOptionsPermissions(); out << v;
271
v = "OptionsDevices"; out << v; v = Operation[currentOperation] -> GetOptionsDevices(); out << v;
272
v = "OptionsCVS"; out << v; v = Operation[currentOperation] -> GetOptionsCVS(); out << v;
273
v = "OptionsHardLinks"; out << v; v = Operation[currentOperation] -> GetOptionsHardLinks(); out << v;
274
v = "OptionsListSize"; out << v; v = Operation[currentOperation] -> GetOptionsListSize(); out << v;
276
while ( count < (Operation[currentOperation] -> GetOptionsListSize()) )
278
v = Operation[currentOperation] -> GetOptionsListItem(count); out << v;
281
v = "ExecuteBeforeListSize"; out << v; v = Operation[currentOperation] -> GetExecuteBeforeListSize(); out << v;
283
while ( count < (Operation[currentOperation] -> GetExecuteBeforeListSize()) )
285
v = Operation[currentOperation] -> GetExecuteBeforeListItem(count); out << v;
288
v = "ExecuteAfterListSize"; out << v; v = Operation[currentOperation] -> GetExecuteAfterListSize(); out << v;
290
while ( count < (Operation[currentOperation] -> GetExecuteAfterListSize()) )
292
v = Operation[currentOperation] -> GetExecuteAfterListItem(count); out << v;
295
//export include state
296
v = "IncludeState"; out << v; v = Operation[currentOperation] -> GetIncluded(); out << v;
298
v = "operation end"; out << v;
301
v = "profile end"; out << v;
307
// checkTaskList =====================================================================================================================================
308
// Checks if the Task list is ok to proceed
312
QString tempConnect="";
316
NothingIncluded=TRUE;
318
if (TotalOperations==0) //check if the operations list is empty ------------------------------
320
message.append("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br><b>" +
321
QObject::tr("The task list is empty")+" !!</b><br>..."+
322
QObject::tr("nothing to start"));
323
messageCLI.append("\nThe task list is empty !!\n"
324
"nothing to start !!\n\n");
329
//first check if 2 connected operations have been selected for execution--------------------------------------------------------------
330
//set NothingInluded to FALSE if 1 or more operation is included
331
bool askTemp = FALSE; QString dirNames=""; QString dirNamesCLI=""; currentOperation=0;
332
while (currentOperation < TotalOperations)
334
if (Operation[currentOperation] -> GetIncluded()) //if the operations is "included"
336
NothingIncluded = FALSE;
338
tempConnect = Operation[currentOperation] -> GetConnectRestore();
339
if (tempConnect != "") //if it is connected to another operation
341
count = currentOperation+1;
342
while (count < TotalOperations)
344
if ( (Operation[count]->GetName() == tempConnect) //if 2 connected operations are both included
345
&& (Operation[count] -> GetIncluded()) )
347
dirNames.append("* " + Operation[currentOperation]->GetName() + "<br>* " + tempConnect + "<br>");
348
dirNamesCLI.append(Operation[currentOperation]->GetName() + "\n" + tempConnect + "\n\n");
349
askTemp = TRUE; ask=TRUE;
360
message.append("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>" +
361
QObject::tr("You have included both of the following connected tasks:")+"<b><br>" + dirNames +
362
"</b>" + QObject::tr("this is not allowed for obvious reasons")+" !!<br>"+
363
QObject::tr("Please <b>uncheck appropriate include boxes</b> before proceeding")+"... <br>");
364
messageCLI.append("\nYou have included both of the following connected tasks:\n" + dirNamesCLI +
365
"this is not allowed for obvious reasons !!\n"
366
"Please uncheck appropriate include boxes before proceeding...\n\n");
369
if ( (NothingIncluded) && (TotalOperations!=0) ) //if no checkboxes are selected show this message ---------------------
371
message.append("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br><b>"+
372
QObject::tr("You have not included any tasks")+" !!</b><br>"
373
"..." + QObject::tr("nothing to start"));
374
messageCLI.append("\nYou have not included any tasks !!\n\n"
375
"nothing to start !!\n\n");
380
//check if 2 or more identical destination directories are decleared & "Backup dir contents" is checked -------------------------------
381
currentOperation=0; askTemp = FALSE; dirNames=""; dirNamesCLI="";
382
QString dest1="", dest2="";
383
//the following loop compares an included operation (currentoperation) with all the other included
384
//to check if they share the same destination
385
while (currentOperation < TotalOperations)
387
dest1 = Operation[currentOperation] -> GetDestination();
388
if (dest1.endsWith("/")) dest1.chop(1);
390
if (Operation[currentOperation] -> GetIncluded())
393
while (count < TotalOperations)
395
if (count == currentOperation) count++;
398
dest2 = Operation[count] -> GetDestination();
399
if (dest2.endsWith("/")) dest2.chop(1);
401
//if this operation's destination is identical to another one's which is included and is of type 'Backup dir contents'
402
if ( (Operation[count] -> GetIncluded())
403
&& ( dest1 == dest2 )
404
&& ( ((Operation[count] -> GetTypeDirContents()) && (!Operation[count] -> GetIncluded())) ||
405
((Operation[currentOperation] -> GetTypeDirContents()) && (!Operation[currentOperation] -> GetIncluded()))) )
407
dirNames.append("* " + Operation[currentOperation]->GetName() + "<br>");
408
dirNamesCLI.append(Operation[currentOperation]->GetName() + "\n");
409
askTemp = TRUE; ask=TRUE;
420
message.append("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>" +
421
QObject::tr("The following included tasks <b>share the same destination directory</b> (all together or at groups) and at least one of them will backup the contents of a directory")+" :<br><b>"
423
"</b>" + QObject::tr("this will lead to one task canceling the other")+" !!<br>"+
424
QObject::tr("Please uncheck appropriate include boxes or change all task types to other than '<b>Backup dir contents</b>' "
425
" or use 'Backup dir contents' together with the '<b>Only include</b>' option, before proceeding")+"...");
427
messageCLI.append("\nThe following included tasks share the same destination directory (all together or at groups) and at least one of them will backup the contents of a directory :\n"
429
"\nthis will lead to one task canceling the other !!\n"
430
"Please uncheck appropriate include boxes or change all task types to other than 'Backup dir contents'\n "
431
"or use 'Backup dir contents' together with the 'Only include' option, before proceeding...\n\n");
437
// checkDeclaredDirs =================================================================================================================================
438
//Check if the declared data are ok by calling checkBackupDirs or checkSyncDirs
439
bool checkDeclaredDirs()
445
QString source, dest;
448
currentOperation = 0;
451
while (currentOperation < TotalOperations)
453
Operation[currentOperation] -> SetOK(FALSE);
454
Operation[currentOperation] -> SetWARNING(FALSE);
455
Operation[currentOperation] -> SetCRITICAL(FALSE);
456
Operation[currentOperation] -> SetSourcePerms(FALSE);
457
Operation[currentOperation] -> SetDestPerms(FALSE);
459
if (Operation[currentOperation] -> GetIncluded()) //if the operations is "included"
461
//first set variables source & dest as well as itsPerform which will finaly decide if the task will be preformed
462
source = Operation[currentOperation] -> GetSource();
463
dest = Operation[currentOperation] -> GetDestination();
464
Operation[currentOperation] -> SetIncluded(TRUE);
465
Operation[currentOperation] -> SetPerform(TRUE); //this will change at the next commands
467
if ( (Operation[currentOperation] -> GetTypeDirContents()) || (Operation[currentOperation] -> GetTypeDirName()) )
468
checkBackupDirs(source,dest); //if the operation is of type "backup dir ...'
469
if (Operation[currentOperation] -> GetTypeSync()) //if the operation is of type "sync dirs'
470
checkSyncDirs(source,dest);
474
Operation[currentOperation] -> SetIncluded(FALSE);
475
Operation[currentOperation] -> SetPerform(FALSE);
482
//===================================================================================================================================================
483
//Check if the directories to be synced are empty or don't exist
484
void checkSyncDirs(QString source, QString dest)
486
Operation[currentOperation] -> SetOK(FALSE);
487
Operation[currentOperation] -> SetWARNING(FALSE);
488
Operation[currentOperation] -> SetCRITICAL(FALSE);
489
Operation[currentOperation] -> SetSourcePerms(FALSE);
490
Operation[currentOperation] -> SetDestPerms(FALSE);
492
bool remoteSource = FALSE;
493
bool remoteDest = FALSE;
495
if ( (Operation[currentOperation] -> GetRemote()) && (Operation[currentOperation] -> GetRemoteSource()) )
497
if (Operation[currentOperation] -> GetRemoteModule())
499
source.prepend((Operation[currentOperation] -> GetRemoteHost())+":");
500
if (Operation[currentOperation] -> GetRemoteUser()!="")
501
source.prepend((Operation[currentOperation] -> GetRemoteUser())+"@");
505
if ( (Operation[currentOperation] -> GetRemote()) && (Operation[currentOperation] -> GetRemoteDestination()) )
507
if (Operation[currentOperation] -> GetRemoteModule())
509
dest.prepend((Operation[currentOperation] -> GetRemoteHost())+":");
510
if (Operation[currentOperation] -> GetRemoteUser()!="")
511
dest.prepend((Operation[currentOperation] -> GetRemoteUser())+"@");
515
//If user does not have sufficient permissions for the dirA or dirB, skip it
516
QFileInfo dirAFile(source);
517
QFileInfo dirBFile(dest);
519
if ( (dirAFile.exists()) && ((!dirAFile.isReadable()) || (!dirAFile.isExecutable())) && (!remoteSource) )
521
CheckedData.append(QObject::tr("status") + ": <font color=red><b>"+QObject::tr("WARNING")+"</font></b><br>");
522
CheckedData.append(QObject::tr("I do not have the permission to read/enter sync directory A")+":<b><br>");
523
CheckedData.append(source);
524
CheckedData.append("</b><br>"+QObject::tr("This task will be <font color=red><b>skipped</b></font> to avoid errors"));
526
CheckedDataCLI.append("[WARNING] -> ");
527
CheckedDataCLI.append(Operation[currentOperation] -> GetName());
528
CheckedDataCLI.append("\nI do not have the permission to read/enter sync directory A :\n");
529
CheckedDataCLI.append(source);
530
CheckedDataCLI.append("\nThis task will be skipped to avoid errors\n"
531
"_____________________________________________________________________________________________\n");
533
Operation[currentOperation] -> SetPerform(FALSE); //don't perform this operation
534
Operation[currentOperation] -> SetSourcePerms(TRUE);
535
ask=TRUE; //ask the user if he/she wants to continue
539
if ( (dirBFile.exists()) && ((!dirBFile.isReadable()) || (!dirBFile.isExecutable())) && (!remoteDest) )
541
CheckedData.append(QObject::tr("status") + ": <font color=red><b>"+QObject::tr("WARNING")+"</font></b><br>");
542
CheckedData.append(QObject::tr("I do not have the permission to read/enter sync directory B")+":<b><br>");
543
CheckedData.append(dest);
544
CheckedData.append("</b><br>"+QObject::tr("This task will be <font color=red><b>skipped</b></font> to avoid errors"));
546
CheckedDataCLI.append("[WARNING] -> ");
547
CheckedDataCLI.append(Operation[currentOperation] -> GetName());
548
CheckedDataCLI.append("\nI do not have the permission to read/enter sync directory B :\n");
549
CheckedDataCLI.append(dest);
550
CheckedDataCLI.append("\nThis task will be skipped to avoid errors\n"
551
"_____________________________________________________________________________________________\n");
553
ask=TRUE; //ask the user if he/she wants to continue
554
Operation[currentOperation] -> SetPerform(FALSE); //don't perform this operation
555
Operation[currentOperation] -> SetDestPerms(TRUE);
561
QStringList dirAList = dirA.entryList(QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot);
562
QStringList dirBList = dirB.entryList(QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot);
563
bool dirAIsEmpty, dirBIsEmpty;
564
if (dirAList.size() == 0)
568
if (dirBList.size() == 0)
573
//Do directories exist and are not emty ??(skip remote) -> [ Ok ]
574
if ( ( ((dirA.exists()) && !(dirAIsEmpty)) || (remoteSource) )
575
&& (((dirB.exists()) && !(dirBIsEmpty)) ||(remoteDest) ) )
577
CheckedData.append(QObject::tr("status") + ": <font color=green><b>" + QObject::tr("OK") + "</font></b><br>");
578
CheckedData.append(QObject::tr("Sync directory")+" A: <b>");
579
CheckedData.append(source);
581
CheckedData.append("<br><font color=magenta>("+QObject::tr("Using remote, check is skipped")+"...)</font>");
582
CheckedData.append("</b><br>" + QObject::tr("Sync directory")+" B: <b>");
583
CheckedData.append(dest);
585
CheckedData.append("<br><font color=magenta>("+QObject::tr("Using remote, check is skipped")+"...)</font>");
586
CheckedData.append("</b>");
588
CheckedDataCLI.append("[Ok] -> ");
589
CheckedDataCLI.append(Operation[currentOperation] -> GetName());
590
CheckedDataCLI.append("\nSync directory A : ");
591
CheckedDataCLI.append(source);
592
CheckedDataCLI.append("\nSync directory B : ");
593
CheckedDataCLI.append(dest);
594
CheckedDataCLI.append("\n_____________________________________________________________________________________________\n");
597
Operation[currentOperation] -> SetOK(TRUE);
600
//is one or both sync dirs non-existent ?? -> [ WARNING ]
601
else if ( !(dirA.exists()) || !(dirB.exists()) )
603
CheckedData.append(QObject::tr("status") + ": <font color=red><b>"+QObject::tr("WARNING")+"</font></b><br>");
604
CheckedData.append(QObject::tr("Directory")+" <b>");
605
CheckedData.append(source);
606
CheckedData.append("</b><br>"+QObject::tr("and/or")+" <b>");
607
CheckedData.append(dest);
608
CheckedData.append("</b><br><font color=red><b>"+QObject::tr("does not exist")+"</b></font>.<br>"+
609
QObject::tr("I will <font color=red><b>skip</b></font> this task for that reason"));
611
CheckedDataCLI.append("[WARNING] -> ");
612
CheckedDataCLI.append(Operation[currentOperation] -> GetName());
613
CheckedDataCLI.append("\nDirectory ");
614
CheckedDataCLI.append(source);
615
CheckedDataCLI.append("\nand/or ");
616
CheckedDataCLI.append(dest);
617
CheckedDataCLI.append("\ndoes not exist.\n"
618
"I will SKIP this task for that reason\n"
619
"_____________________________________________________________________________________________\n");
621
Operation[currentOperation] -> SetPerform(FALSE); //don't perform this operation
622
Operation[currentOperation] -> SetWARNING(TRUE);
626
//Is one or both of the directories empty ?? -> [ CRITICAL ]
629
CheckedData.append(QObject::tr("status") + ": <font color=orange><b>"+QObject::tr("CRITICAL")+"</font></b><br>");
630
CheckedData.append(QObject::tr("Directory")+" <b>");
631
CheckedData.append(source);
632
CheckedData.append("</b><br>"+QObject::tr("and/or")+" <b>");
633
CheckedData.append(dest);
634
CheckedData.append("</b><br><font color=orange><b>"+QObject::tr("is empty")+"</b></font>.<br>"+
635
QObject::tr("I will <font color=orange><b>not skip</b></font> this task. Synchronizing is going to be performed anyway"));
637
CheckedDataCLI.append("[CRITICAL] -> ");
638
CheckedDataCLI.append(Operation[currentOperation] -> GetName());
639
CheckedDataCLI.append("\nDirectory ");
640
CheckedDataCLI.append(source);
641
CheckedDataCLI.append("\nand/or ");
642
CheckedDataCLI.append(dest);
643
CheckedDataCLI.append("\nis empty.\n"
644
"I will NOT skip this task (unless '--skip-critical' is given as argument).\n"
645
"Synchronizing is going to be performed anyway !!\n"
646
"_____________________________________________________________________________________________\n");
648
ask=TRUE; //ask the user if he/she wants to continue
650
Operation[currentOperation] -> SetCRITICAL(TRUE);
655
//===================================================================================================================================================
656
//Check if the source and destination backup directories are empty or don't exist
657
void checkBackupDirs(QString source, QString dest)
659
Operation[currentOperation] -> SetOK(FALSE);
660
Operation[currentOperation] -> SetWARNING(FALSE);
661
Operation[currentOperation] -> SetCRITICAL(FALSE);
662
Operation[currentOperation] -> SetSourcePerms(FALSE);
663
Operation[currentOperation] -> SetDestPerms(FALSE);
665
bool remoteSource = FALSE;
666
bool remoteDest = FALSE;
668
//first check if a remote source or dest is used so that to skip checks
669
if ( (Operation[currentOperation] -> GetRemote()) && (Operation[currentOperation] -> GetRemoteSource()) )
671
if (Operation[currentOperation] -> GetRemoteModule())
673
source.prepend((Operation[currentOperation] -> GetRemoteHost())+":");
674
if (Operation[currentOperation] -> GetRemoteUser()!="")
675
source.prepend((Operation[currentOperation] -> GetRemoteUser())+"@");
678
if ( (Operation[currentOperation] -> GetRemote()) && (Operation[currentOperation] -> GetRemoteDestination()) )
680
if (Operation[currentOperation] -> GetRemoteModule())
682
dest.prepend((Operation[currentOperation] -> GetRemoteHost())+":");
683
if (Operation[currentOperation] -> GetRemoteUser()!="")
684
dest.prepend((Operation[currentOperation] -> GetRemoteUser())+"@");
688
//If user does not have sufficient permissions for the source or dest, skip it
689
QFileInfo destFile(dest);
690
QFileInfo sourceFile(source);
692
if ( (sourceFile.exists()) && ((!sourceFile.isReadable()) || (!sourceFile.isExecutable())) && (!remoteSource) )
694
CheckedData.append(QObject::tr("status") + ": <font color=red><b>"+QObject::tr("WARNING")+"</font></b><br>");
695
CheckedData.append(QObject::tr("I do not have the permission to read/enter the source directory")+":<b><br>");
696
CheckedData.append(source);
697
CheckedData.append("</b><br>"+QObject::tr("This task will be <font color=red><b>skipped</b></font> to avoid errors"));
699
CheckedDataCLI.append("[WARNING] -> ");
700
CheckedDataCLI.append(Operation[currentOperation] -> GetName());
701
CheckedDataCLI.append("\nI do not have the permission to read/enter the source directory :\n");
702
CheckedDataCLI.append(source);
703
CheckedDataCLI.append("\nThis task will be skipped to avoid errors\n"
704
"_____________________________________________________________________________________________\n");
706
Operation[currentOperation] -> SetPerform(FALSE); //don't perform this operation
707
ask=TRUE; //ask the user if he/she wants to continue
708
Operation[currentOperation] -> SetSourcePerms(TRUE);
712
if ( (destFile.exists()) && ((!destFile.isReadable()) || (!destFile.isExecutable())) && (!remoteDest) )
714
CheckedData.append(QObject::tr("status") + ": <font color=red><b>"+QObject::tr("WARNING")+"</font></b><br>");
715
CheckedData.append(QObject::tr("I do not have the permission to read/enter the destination directory")+":<b><br>");
716
CheckedData.append(dest);
717
CheckedData.append("</b><br>"+QObject::tr("This task will be <font color=red><b>skipped</b></font> to avoid errors"));
719
CheckedDataCLI.append("[WARNING] -> ");
720
CheckedDataCLI.append(Operation[currentOperation] -> GetName());
721
CheckedDataCLI.append("\nI do not have the permission to read/enter the destination directory :\n");
722
CheckedDataCLI.append(dest);
723
CheckedDataCLI.append("\nThis task will be skipped to avoid errors\n"
724
"_____________________________________________________________________________________________\n");
726
Operation[currentOperation] -> SetPerform(FALSE); //don't perform this operation
727
ask=TRUE; //ask the user if he/she wants to continue
728
Operation[currentOperation] -> SetDestPerms(TRUE);
732
QDir sourceDir (source);
734
QStringList sourceList = sourceDir.entryList(QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot);
735
QStringList destList = destDir.entryList(QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot);
736
bool SourceIsEmpty, DestIsEmpty;
737
if (sourceList.size() == 0)
738
SourceIsEmpty = TRUE;
740
SourceIsEmpty = FALSE;
741
if (destList.size() == 0)
746
//Does the source directory exist and it is not empty OR we're using remote source??
747
if ( ((sourceDir.exists()) && !(SourceIsEmpty)) || (remoteSource) )
749
//Does the destination directory exist and it is not empty ?? -> [ Ok ]
750
if ( ((destDir.exists()) && !(DestIsEmpty)) || (remoteDest) )
752
CheckedData.append(QObject::tr("status") + ": <font color=green><b>" + QObject::tr("OK") + "</font></b><br>");
753
CheckedData.append(QObject::tr("Source directory")+": <b>");
754
CheckedData.append(source);
756
CheckedData.append("<br><font color=magenta>("+QObject::tr("Using remote, check is skipped")+"...)</font>");
757
CheckedData.append("</b><br>"+QObject::tr("Destination directory")+": <b>");
758
CheckedData.append(dest);
760
CheckedData.append("<br><font color=magenta>("+QObject::tr("Using remote, check is skipped")+"...)</font></b>");
762
CheckedDataCLI.append("[Ok] -> ");
763
CheckedDataCLI.append(Operation[currentOperation] -> GetName());
764
CheckedDataCLI.append("\nSource directory : ");
765
CheckedDataCLI.append(source);
767
CheckedDataCLI.append(" (Using remote, check is skipped...)");
768
CheckedDataCLI.append("\nDestination directory : ");
769
CheckedDataCLI.append(dest);
771
CheckedDataCLI.append(" (Using remote, check is skipped...)");
772
CheckedDataCLI.append("\n_____________________________________________________________________________________________\n");
774
Operation[currentOperation] -> SetOK(TRUE);
777
else //The destination directory does not exist or it is empty -> [ CRITICAL ]
779
CheckedData.append(QObject::tr("status") + ": <font color=orange><b>"+QObject::tr("CRITICAL")+"</font></b><br>");
780
CheckedData.append(QObject::tr("Destination directory")+": <b>");
781
CheckedData.append(dest);
782
CheckedData.append("<br><font color=orange> "+QObject::tr("is empty or does not exist")+"</font>.</b><br>"+
783
QObject::tr("This task will <font color=orange><b>not be skipped")+"</b></font> <br>"+
784
QObject::tr("The Destination Directory will be created if it doesn't exist and filled with new backup data")+".");
786
CheckedDataCLI.append("[CRITICAL] -> ");
787
CheckedDataCLI.append(Operation[currentOperation] -> GetName());
788
CheckedDataCLI.append("\nSource directory : ");
789
CheckedDataCLI.append(source);
791
CheckedDataCLI.append(" <font color=magenta>(Using remote, check is skipped...)</font>");
792
CheckedDataCLI.append("\nDestination directory : ");
793
CheckedDataCLI.append(dest);
794
CheckedDataCLI.append(" is empty or does not exist.\n"
795
"This task will NOT be skipped (unless '--skip-critical' is given as argument)\n"
796
"The Destination Directory will be created if it doesn't exist and filled with new backup data.\n"
797
"_____________________________________________________________________________________________\n");
799
ask=TRUE; //ask the user if he/she wants to continue
801
Operation[currentOperation] -> SetCRITICAL(TRUE);
804
else //The source directory does not exist or it is empty -> [WARNING ]
806
CheckedData.append(QObject::tr("status") + ": <font color=red><b>"+QObject::tr("WARNING")+"</font></b><br>");
807
CheckedData.append(QObject::tr("Source directory")+": <b>");
808
CheckedData.append(source);
809
CheckedData.append("<br><font color=red> "+QObject::tr("is empty or does not exist")+"</font>.</b><br>");
810
CheckedData.append(QObject::tr("This task will be <font color=red><b>skipped</b></font> to protect your backup data (if any !!)"));
812
CheckedDataCLI.append("[WARNING] -> ");
813
CheckedDataCLI.append(Operation[currentOperation] -> GetName());
814
CheckedDataCLI.append("\nSource directory : ");
815
CheckedDataCLI.append(source);
816
CheckedDataCLI.append(" is empty or does not exist.\n"
817
"Destination directory : ");
818
CheckedDataCLI.append(dest);
820
CheckedDataCLI.append(" (Using remote, check is skipped...)");
821
CheckedDataCLI.append("\nThis task will be SKIPPED to protect your backup data (if any !!)\n"
822
"_____________________________________________________________________________________________\n");
824
Operation[currentOperation] -> SetPerform(FALSE); //don't perform this operation
825
Operation[currentOperation] -> SetWARNING(TRUE);
826
ask=TRUE; //ask the user if he/she wants to continue
831
// /AppendArguments =======================================================================================================
832
//function to append "arguments" object at a given operation according to the fields of the modify window
833
QStringList AppendArguments(operation *operationToAppend)
835
QStringList arguments; int count;
836
arguments << "-h" << "--progress" << "--stats"; //These are the standard arguments used by rsync
838
//add rsync arguments --------------------------------------------------------------------------------------------------
839
if (operationToAppend -> GetOptionsRecurse()) arguments.append("-r");
840
if (operationToAppend -> GetOptionsOwnership()) arguments.append("-tgo");
841
if (operationToAppend -> GetOptionsSymlinks()) arguments.append("-l");
842
if (operationToAppend -> GetOptionsPermissions()) arguments.append("-p");
843
if (operationToAppend -> GetOptionsDevices()) arguments.append("-D");
844
if (operationToAppend -> GetOptionsCVS()) arguments.append("-C");
845
if (operationToAppend -> GetOptionsHardLinks()) arguments.append("-H");
846
if (operationToAppend -> GetOptionsUpdate()) arguments.append("--update");
847
if (operationToAppend -> GetOptionsDelete()) arguments.append("--delete-after");
849
while ( count < (operationToAppend -> GetOptionsListSize()) )
851
arguments.append(operationToAppend -> GetOptionsListItem(count));
855
//add excluded items if groupbox is checked------------------------------------------------------------------------------
856
if (operationToAppend -> GetExclude())
858
if (operationToAppend -> GetOptionsDelete()) arguments.append("--delete-excluded");
859
if (operationToAppend -> GetExcludeTemp()) arguments.append("--exclude=**/*tmp*/");
860
if (operationToAppend -> GetExcludeCache()){ arguments.append("--exclude=**/*cache*/");
861
arguments.append("--exclude=**/*Cache*/");}
862
if (operationToAppend -> GetExcludeBackup()) arguments.append("--exclude=**~");
863
if (operationToAppend -> GetExcludeMount()){ arguments.append("--exclude=/mnt/*/**");
864
arguments.append("--exclude=/media/*/**");}
865
if (operationToAppend -> GetExcludeLostFound()) arguments.append("--exclude=**/lost+found*/");
866
if (operationToAppend -> GetExcludeSystem()){ arguments.append("--exclude=/var/**");
867
arguments.append("--exclude=/proc/**");
868
arguments.append("--exclude=/dev/**");
869
arguments.append("--exclude=/sys/**");}
870
if (operationToAppend -> GetExcludeTrash()){ arguments.append("--exclude=**/*Trash*/");
871
arguments.append("--exclude=**/*trash*/");}
873
//also read the custom exclude list
875
while ( count < (operationToAppend -> GetExcludeListSize()) )
877
arguments.append("--exclude=" + (operationToAppend -> GetExcludeListItem(count)) );
881
//add included items if groupbox is checked------------------------------------------------------------------------------
882
if (operationToAppend -> GetInclude())
885
while ( count < (operationToAppend -> GetIncludeListSize()) )
887
arguments.append("--include=" + (operationToAppend -> GetIncludeListItem(count)) );
890
arguments.append("--include=*/");
891
arguments.append("--exclude=*");
892
arguments.append("--prune-empty-dirs");
895
//set temp strings sourceString & destString accordingly if groupbox "remote" is checked--------------------------------------------
896
//also add -e ssh if "ssh" is checked & --password-file=FILE
897
QString sourceString, destString, remoteHost = ""; //temp strings
898
if (operationToAppend -> GetRemote())
900
if (operationToAppend -> GetRemoteUser() != "") //append remote user@ if applicable to temp string
901
remoteHost.append(operationToAppend -> GetRemoteUser() + "@");
903
if (operationToAppend -> GetRemoteModule()) //append remote host: (or :: if it's a module) to temp string
905
remoteHost.append(operationToAppend -> GetRemoteHost() + "::");
906
//add --password-file=FILE if password file lineEdit is not empty
907
if (operationToAppend -> GetRemotePassword() != "")
908
arguments.append("--password-file=" + (operationToAppend -> GetRemotePassword()) );
911
remoteHost.append(operationToAppend -> GetRemoteHost() + ":");
913
if (operationToAppend -> GetRemoteDestination()) //set temp source & destination strings
914
{ remoteHost.append(operationToAppend -> GetDestination());
915
destString = remoteHost;
916
sourceString = operationToAppend -> GetSource();}
917
else { remoteHost.append(operationToAppend -> GetSource());
918
sourceString = remoteHost;
919
destString = operationToAppend -> GetDestination();}
921
//add argument for ssh if the checkbox is checked & ssh keyfile
922
if (operationToAppend -> GetRemoteSSH())
924
if (operationToAppend -> GetRemoteSSHPassword() != "")
925
//arguments.append("-e \"ssh -i " + uiM.lineEdit_sshPassword -> text() + "\"");
926
if (operationToAppend -> GetRemoteSSHPort() != 0)
927
arguments.append("-e ssh -i " + operationToAppend -> GetRemoteSSHPassword() +
928
" -p " + countStr.setNum(operationToAppend -> GetRemoteSSHPort()) );
930
arguments.append("-e ssh -i " + operationToAppend -> GetRemoteSSHPassword());
932
if (operationToAppend -> GetRemoteSSHPort() != 0)
933
arguments.append("-e ssh -p " + countStr.setNum(operationToAppend -> GetRemoteSSHPort()) );
935
arguments.append("-e ssh");
938
else //Operate locally----------------------------------------------------------------------------------------
940
sourceString = operationToAppend -> GetSource();
941
destString = operationToAppend -> GetDestination();
944
//set source & destination according to sourceString & destString ---------------------------------------------------------
945
arguments.append(sourceString);
946
arguments.append(destString);
950
// end of global.cpp ---------------------------------------------------------------------------