[Pkg-owncloud-commits] [owncloud-client] 103/219: FolderMan: Fix startFromScratch logic. #1989
Sandro Knauß
hefee-guest at moszumanska.debian.org
Sat Oct 11 14:43:15 UTC 2014
This is an automated email from the git hooks/post-receive script.
hefee-guest pushed a commit to branch master
in repository owncloud-client.
commit 20dd3b0a6915c805ed79c960bb80dd875ba15341
Author: Christian Kamm <kamm at incasoftware.de>
Date: Fri Sep 5 10:13:00 2014 +0200
FolderMan: Fix startFromScratch logic. #1989
(cherry picked from commit 4566ca3127fa14f83b60a05411b0321f966c38a8)
---
src/mirall/folderman.cpp | 40 +++++++++++++++++++++++++++-------------
1 file changed, 27 insertions(+), 13 deletions(-)
diff --git a/src/mirall/folderman.cpp b/src/mirall/folderman.cpp
index e07b571..b63c000 100644
--- a/src/mirall/folderman.cpp
+++ b/src/mirall/folderman.cpp
@@ -635,27 +635,41 @@ QString FolderMan::getBackupName( QString fullPathName ) const
bool FolderMan::startFromScratch( const QString& localFolder )
{
- if( localFolder.isEmpty() ) return false;
+ if( localFolder.isEmpty() ) {
+ return false;
+ }
QFileInfo fi( localFolder );
- if( fi.exists() && fi.isDir() ) {
- QDir file = fi.dir();
+ QDir parentDir( fi.dir() );
+ QString folderName = fi.fileName();
+
+ // Adjust for case where localFolder ends with a /
+ if ( fi.isDir() ) {
+ folderName = parentDir.dirName();
+ parentDir.cdUp();
+ }
- // check if there are files in the directory.
- if( file.count() == 0 ) {
- // directory is existing, but its empty. Use it.
+ if( fi.exists() ) {
+ // It exists, but is empty -> just reuse it.
+ if( fi.isDir() && fi.dir().count() == 0 ) {
qDebug() << "startFromScratch: Directory is empty!";
return true;
}
- QString newName = getBackupName( fi.absoluteFilePath() );
-
- if( file.rename( fi.absoluteFilePath(), newName )) {
- if( file.mkdir( fi.absoluteFilePath() ) ) {
- return true;
- }
+ // Make a backup of the folder/file.
+ QString newName = getBackupName( parentDir.absoluteFilePath( folderName ) );
+ if( !parentDir.rename( fi.absoluteFilePath(), newName ) ) {
+ qDebug() << "startFromScratch: Could not rename" << fi.absoluteFilePath()
+ << "to" << newName;
+ return false;
}
}
- return false;
+
+ if( !parentDir.mkdir( fi.absoluteFilePath() ) ) {
+ qDebug() << "startFromScratch: Could not mkdir" << fi.absoluteFilePath();
+ return false;
+ }
+
+ return true;
}
void FolderMan::setDirtyProxy(bool value)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git
More information about the Pkg-owncloud-commits
mailing list