mirror of
https://github.com/nextcloud/desktop.git
synced 2024-10-24 05:15:40 +03:00
FolderMan: Fix startFromScratch logic. #1989
(cherry picked from commit 4566ca3127
)
This commit is contained in:
parent
f348eabf19
commit
20dd3b0a69
1 changed files with 27 additions and 13 deletions
|
@ -635,27 +635,41 @@ QString FolderMan::getBackupName( QString fullPathName ) const
|
||||||
|
|
||||||
bool FolderMan::startFromScratch( const QString& localFolder )
|
bool FolderMan::startFromScratch( const QString& localFolder )
|
||||||
{
|
{
|
||||||
if( localFolder.isEmpty() ) return false;
|
if( localFolder.isEmpty() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QFileInfo fi( localFolder );
|
QFileInfo fi( localFolder );
|
||||||
if( fi.exists() && fi.isDir() ) {
|
QDir parentDir( fi.dir() );
|
||||||
QDir file = fi.dir();
|
QString folderName = fi.fileName();
|
||||||
|
|
||||||
// check if there are files in the directory.
|
// Adjust for case where localFolder ends with a /
|
||||||
if( file.count() == 0 ) {
|
if ( fi.isDir() ) {
|
||||||
// directory is existing, but its empty. Use it.
|
folderName = parentDir.dirName();
|
||||||
|
parentDir.cdUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
if( fi.exists() ) {
|
||||||
|
// It exists, but is empty -> just reuse it.
|
||||||
|
if( fi.isDir() && fi.dir().count() == 0 ) {
|
||||||
qDebug() << "startFromScratch: Directory is empty!";
|
qDebug() << "startFromScratch: Directory is empty!";
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
QString newName = getBackupName( fi.absoluteFilePath() );
|
// Make a backup of the folder/file.
|
||||||
|
QString newName = getBackupName( parentDir.absoluteFilePath( folderName ) );
|
||||||
if( file.rename( fi.absoluteFilePath(), newName )) {
|
if( !parentDir.rename( fi.absoluteFilePath(), newName ) ) {
|
||||||
if( file.mkdir( fi.absoluteFilePath() ) ) {
|
qDebug() << "startFromScratch: Could not rename" << fi.absoluteFilePath()
|
||||||
return true;
|
<< "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)
|
void FolderMan::setDirtyProxy(bool value)
|
||||||
|
|
Loading…
Reference in a new issue