Commit 0ad1bf04 authored by Simon Persson's avatar Simon Persson

If error is detected in file digger: ask user if integrity check should run

Also check for permission problem if problem happens at startup, that way we can guide the user in correct direction.
parent 08a63c06
include_directories(${KDE4_INCLUDES})
include_directories("../daemon")
include_directories("../kioslave")
set(filedigger_SRCS
......
......@@ -60,15 +60,19 @@ int main(int pArgCount, char **pArgArray) {
lParsedArguments->getOption("branch"));
if(!lRepository->open()) {
KMessageBox::sorry(NULL, i18nc("@info:label messagebox, %1 is a folder path",
"The bup repository \"%1\" could not be opened. Check if the backups really are located there.",
"The backup archive \"%1\" could not be opened. Check if the backups really are located there.",
lParsedArguments->arg(0)));
return -1;
return 1;
}
if(!lRepository->readBranch()) {
KMessageBox::sorry(NULL, i18nc("@info:label messagebox, %1 is the name of a repository branch",
"The branch \"%1\" could not be read. Either it does not exist or you do not have permission to read it.",
lParsedArguments->getOption("branch")));
return -1;
if(!lRepository->permissionsOk()) {
KMessageBox::sorry(NULL, i18nc("@info:label messagebox",
"You do not have permission needed to read this backup archive."));
return 2;
} else {
lRepository->askForIntegrityCheck();
return 3;
}
}
FileDigger *lFileDigger = new FileDigger(lRepository);
......
......@@ -18,11 +18,15 @@
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "kupdaemon.h"
#include "mergedvfs.h"
#include "vfshelpers.h"
#include <QDebug>
#include <QDir>
#include <KLocale>
#include <KMessageBox>
#include <QDBusInterface>
#include <git2/branch.h>
#include <sys/stat.h>
......@@ -101,12 +105,27 @@ MergedNodeList &MergedNode::subNodes() {
return *mSubNodes;
}
void MergedNode::askForIntegrityCheck() {
int lAnswer = KMessageBox::questionYesNo(NULL, i18nc("@info:label messagebox",
"Could not read this backup archive. Perhaps some files "
"have become corrupted. Do you want to run an integrity "
"check to test this?"));
if(lAnswer == KMessageBox::Yes) {
QDBusInterface lInterface(KUP_DBUS_SERVICE_NAME, KUP_DBUS_OBJECT_PATH);
if(lInterface.isValid()) {
lInterface.call(QLatin1String("runIntegrityCheck"),
QDir::cleanPath(QString::fromLocal8Bit(git_repository_path(mRepository))));
}
}
}
void MergedNode::generateSubNodes() {
NameMap lSubNodeMap;
foreach(VersionData *lCurrentVersion, mVersionList) {
git_tree *lTree;
if(0 != git_tree_lookup(&lTree, mRepository, &lCurrentVersion->mOid)) {
continue;
askForIntegrityCheck();
continue; // try to be fault tolerant by not aborting...
}
git_blob *lMetadataBlob = NULL;
VintStream *lMetadataStream = NULL;
......@@ -244,6 +263,30 @@ bool MergedRepository::readBranch() {
return !lEmptyList;
}
bool MergedRepository::permissionsOk() {
if(mRepository == NULL) {
return false;
}
QDir lRepoDir(objectName());
if(!lRepoDir.exists()) {
return false;
}
QList<QDir> lDirectories;
lDirectories << lRepoDir;
while(!lDirectories.isEmpty()) {
QDir lDir = lDirectories.takeFirst();
foreach(QFileInfo lFileInfo, lDir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot)) {
if(!lFileInfo.isReadable()) {
return false;
}
if(lFileInfo.isDir()) {
lDirectories << QDir(lFileInfo.absoluteFilePath());
}
}
}
return true;
}
uint qHash(git_oid pOid) {
return qHash(QByteArray::fromRawData((char *)pOid.id, GIT_OID_RAWSZ));
}
......
......@@ -77,6 +77,7 @@ public:
virtual MergedNodeList &subNodes();
const VersionList *versionList() const { return &mVersionList; }
uint mode() const { return mMode; }
static void askForIntegrityCheck();
protected:
virtual void generateSubNodes();
......@@ -95,6 +96,7 @@ public:
bool open();
bool readBranch();
bool permissionsOk();
QString mBranchName;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment