mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-25 22:46:04 +03:00
Wizards: allow adding a folder in a non-existing directory and create that folder
The owncloud wizard already created the directory, but the recent addition of FolderMan::checkPathValidityForNewFolder stopped allowing unexisting directories. So change FolderMan::checkPathValidityForNewFolder to allow non existing directory and whange the FolderWizard to create the directory if it does not exist. Issue #3492
This commit is contained in:
parent
22013eb528
commit
ec86d1a151
4 changed files with 59 additions and 10 deletions
|
@ -196,6 +196,20 @@ void AccountSettings::slotFolderWizardAccepted()
|
|||
definition.localPath = folderWizard->field(QLatin1String("sourceFolder")).toString();
|
||||
definition.targetPath = folderWizard->property("targetPath").toString();
|
||||
|
||||
{
|
||||
QDir dir(definition.localPath);
|
||||
if (!dir.exists()) {
|
||||
qDebug() << "Creating folder" << definition.localPath;
|
||||
if (!dir.mkpath(".")) {
|
||||
QMessageBox::warning(this, tr("Folder creation failed"),
|
||||
tr("<p>Could not create local folder <i>%1</i>.")
|
||||
.arg(QDir::toNativeSeparators(definition.localPath)));
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
bool ignoreHidden = true;
|
||||
/* take the value from the definition of already existing folders. All folders have
|
||||
* the same setting so far, that's why it's ok to check the first one.
|
||||
|
|
|
@ -1097,15 +1097,21 @@ QString FolderMan::statusToString( SyncResult syncStatus, bool paused ) const
|
|||
return folderMessage;
|
||||
}
|
||||
|
||||
QString FolderMan::checkPathValidityForNewFolder(const QString& path)
|
||||
QString FolderMan::checkPathValidityForNewFolder(const QString& path, bool forNewDirectory)
|
||||
{
|
||||
if (path.isEmpty()) {
|
||||
return tr("No valid folder selected!");
|
||||
}
|
||||
|
||||
QFileInfo selFile( path );
|
||||
QString userInput = selFile.canonicalFilePath();
|
||||
|
||||
QStringList warnStrings;
|
||||
if (!selFile.exists()) {
|
||||
return checkPathValidityForNewFolder(selFile.dir().path(), true);
|
||||
}
|
||||
|
||||
if( !selFile.isDir() ) {
|
||||
return tr("No valid local folder selected!");
|
||||
return tr("The selected path is not a directory!");
|
||||
}
|
||||
|
||||
if ( !selFile.isWritable() ) {
|
||||
|
@ -1127,12 +1133,12 @@ QString FolderMan::checkPathValidityForNewFolder(const QString& path)
|
|||
return tr("The local path %1 is already an upload folder. Please pick another one!")
|
||||
.arg(QDir::toNativeSeparators(userInput));
|
||||
}
|
||||
if (QDir::cleanPath(folderDir).startsWith(QDir::cleanPath(userInput)+'/')) {
|
||||
if (!forNewDirectory && QDir::cleanPath(folderDir).startsWith(QDir::cleanPath(userInput)+'/')) {
|
||||
return tr("An already configured folder is contained in the current entry.");
|
||||
}
|
||||
|
||||
QString absCleanUserFolder = QDir::cleanPath(QDir(userInput).canonicalPath())+'/';
|
||||
if (QDir::cleanPath(folderDir).startsWith(absCleanUserFolder) ) {
|
||||
if (!forNewDirectory && QDir::cleanPath(folderDir).startsWith(absCleanUserFolder) ) {
|
||||
return tr("The selected folder is a symbolic link. An already configured "
|
||||
"folder is contained in the folder this link is pointing to.");
|
||||
}
|
||||
|
|
|
@ -93,9 +93,11 @@ public:
|
|||
* Check if @a path is a valid path for a new folder considering the already sync'ed items.
|
||||
* Make sure that this folder, or any subfolder is not sync'ed alrady.
|
||||
*
|
||||
* \a forNewDirectory is internal and is used for recursion.
|
||||
*
|
||||
* @returns an empty string if it is allowed, or an error if it is not allowed
|
||||
*/
|
||||
QString checkPathValidityForNewFolder(const QString &path);
|
||||
QString checkPathValidityForNewFolder(const QString &path, bool forNewDirectory = false);
|
||||
|
||||
signals:
|
||||
/**
|
||||
|
|
|
@ -46,6 +46,11 @@ private slots:
|
|||
QVERIFY(dir2.mkpath("ownCloud2"));
|
||||
QVERIFY(dir2.mkpath("sub/free"));
|
||||
QVERIFY(dir2.mkpath("free2/sub"));
|
||||
{
|
||||
QFile f(dir.path() + "/sub/file.txt");
|
||||
f.open(QFile::WriteOnly);
|
||||
f.write("hello");
|
||||
}
|
||||
|
||||
FolderMan *folderman = FolderMan::instance();
|
||||
QCOMPARE(folderman, &_fm);
|
||||
|
@ -54,11 +59,15 @@ private slots:
|
|||
|
||||
|
||||
// those should be allowed
|
||||
QVERIFY(folderman->checkPathValidityForNewFolder(dir.path() + "/sub/free").isNull());
|
||||
QVERIFY(folderman->checkPathValidityForNewFolder(dir.path() + "/free2/").isNull());
|
||||
QCOMPARE(folderman->checkPathValidityForNewFolder(dir.path() + "/sub/free"), QString());
|
||||
QCOMPARE(folderman->checkPathValidityForNewFolder(dir.path() + "/free2/"), QString());
|
||||
// Not an existing directory -> Ok
|
||||
QCOMPARE(folderman->checkPathValidityForNewFolder(dir.path() + "/sub/bliblablu"), QString());
|
||||
QCOMPARE(folderman->checkPathValidityForNewFolder(dir.path() + "/sub/free/bliblablu"), QString());
|
||||
QCOMPARE(folderman->checkPathValidityForNewFolder(dir.path() + "/sub/bliblablu/some/more"), QString());
|
||||
|
||||
// Not an existing directory -> Error
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/bliblablu").isNull());
|
||||
// A file -> Error
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/file.txt").isNull());
|
||||
|
||||
// There are folders configured in those folders: -> ERROR
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/ownCloud1").isNull());
|
||||
|
@ -85,6 +94,24 @@ private slots:
|
|||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/link3").isNull());
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/link4").isNull());
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/link3/folder").isNull());
|
||||
|
||||
|
||||
// test some non existing sub path (error)
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/ownCloud1/some/sub/path").isNull());
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/ownCloud2/blublu").isNull());
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/sub/ownCloud1/folder/g/h").isNull());
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder(dir.path() + "/link3/folder/neu_folder").isNull());
|
||||
|
||||
// Subfolder of links
|
||||
QVERIFY(folderman->checkPathValidityForNewFolder(dir.path() + "/link1/subfolder").isNull());
|
||||
QVERIFY(folderman->checkPathValidityForNewFolder(dir.path() + "/link2/free/subfolder").isNull());
|
||||
|
||||
// Invalid paths
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder("").isNull());
|
||||
|
||||
// Should not have the rights
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder("/").isNull());
|
||||
QVERIFY(!folderman->checkPathValidityForNewFolder("/usr/bin/somefolder").isNull());
|
||||
#else
|
||||
QSKIP("Test not supported with Qt4", SkipSingle);
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue