Skip to content
Permalink
Browse files

[processing] Ensure that any user set temporary folders actually exis…

…t, or things go wrong...
  • Loading branch information
nyalldawson committed Jan 21, 2020
1 parent 5e7ee69 commit 9e4a53b9c4c9474265cb3e46dce8e67fed11c51d
Showing with 12 additions and 3 deletions.
  1. +3 −0 src/core/processing/qgsprocessingutils.cpp
  2. +9 −3 tests/src/analysis/testqgsprocessing.cpp
@@ -764,6 +764,9 @@ QString QgsProcessingUtils::tempFolder()
}
else if ( sFolder.isEmpty() || !sFolder.startsWith( basePath ) || !sTempFolder )
{
if ( !QDir().exists( basePath ) )
QDir().mkpath( basePath );

const QString templatePath = QStringLiteral( "%1/processing_XXXXXX" ).arg( basePath );
// leak the previous folder -- we don't want it to be cleaned up, we don't know what was in it that may still
// be required for this session!
@@ -8548,8 +8548,12 @@ void TestQgsProcessing::tempUtils()
QVERIFY( tempFile3.startsWith( tempFolder ) );

// change temp folder in the settings
std::unique_ptr< QTemporaryDir > dir = qgis::make_unique< QTemporaryDir >();
const QString tempDirPath = dir->path();
dir.reset();

QgsSettings settings;
QString alternative_tempFolder1 = QStringLiteral( TEST_DATA_DIR ) + QStringLiteral( "/alternative_temp_test_one" );
QString alternative_tempFolder1 = tempDirPath + QStringLiteral( "/alternative_temp_test_one" );
settings.setValue( QStringLiteral( "Processing/Configuration/TEMP_PATH2" ), alternative_tempFolder1 );
// check folder and if it's constant with alternative temp folder 1
tempFolder = QgsProcessingUtils::tempFolder();
@@ -8561,17 +8565,19 @@ void TestQgsProcessing::tempUtils()
QVERIFY( alternativeTempFile1.startsWith( tempFolder ) );
QVERIFY( alternativeTempFile1.startsWith( alternative_tempFolder1 ) );
// change temp folder in the settings again
QString alternative_tempFolder2 = QStringLiteral( TEST_DATA_DIR ) + QStringLiteral( "/alternative_temp_test_two" );
QString alternative_tempFolder2 = tempDirPath + QStringLiteral( "/alternative_temp_test_two" );
settings.setValue( QStringLiteral( "Processing/Configuration/TEMP_PATH2" ), alternative_tempFolder2 );
// check folder and if it's constant constant with alternative temp folder 2
tempFolder = QgsProcessingUtils::tempFolder();
QVERIFY( tempFolder.startsWith( alternative_tempFolder2 ) );
QCOMPARE( tempFolder.left( alternative_tempFolder2.length() ), alternative_tempFolder2 );
QCOMPARE( QgsProcessingUtils::tempFolder(), tempFolder );
// create file
QString alternativeTempFile2 = QgsProcessingUtils::generateTempFilename( "alternative_temptest.txt" );
QVERIFY( alternativeTempFile2.endsWith( "alternative_temptest.txt" ) );
QVERIFY( alternativeTempFile2.startsWith( tempFolder ) );
QVERIFY( alternativeTempFile2.startsWith( alternative_tempFolder2 ) );
settings.setValue( QStringLiteral( "Processing/Configuration/TEMP_PATH2" ), QString() );

}

void TestQgsProcessing::convertCompatible()

0 comments on commit 9e4a53b

Please sign in to comment.
You can’t perform that action at this time.