Skip to content

Commit 6435a20

Browse files
committed
Merge pull request #2686 from SebDieBln/FixPostgresWarnings
[Postgres] Remove the temporary SSL files only when they were created
2 parents f966c42 + ed80951 commit 6435a20

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/providers/postgres/qgspostgresconn.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -208,19 +208,19 @@ QgsPostgresConn::QgsPostgresConn( const QString& conninfo, bool readOnly, bool s
208208

209209
mConn = PQconnectdb( expandedConnectionInfo.toLocal8Bit() ); // use what is set based on locale; after connecting, use Utf8
210210

211-
// remove temporary cert/key/CA
211+
// remove temporary cert/key/CA if they exist
212212
QgsDataSourceURI expandedUri( expandedConnectionInfo );
213-
QString sslCertFile = expandedUri.param( "sslcert" );
214-
sslCertFile.remove( "'" );
215-
QFile::remove( sslCertFile );
216-
217-
QString sslKeyFile = expandedUri.param( "sslkey" );
218-
sslKeyFile.remove( "'" );
219-
QFile::remove( sslKeyFile );
220-
221-
QString sslCAFile = expandedUri.param( "sslrootcert" );
222-
sslCAFile.remove( "'" );
223-
QFile::remove( sslCAFile );
213+
QStringList parameters;
214+
parameters << "sslcert" << "sslkey" << "sslrootcert";
215+
Q_FOREACH ( const QString& param, parameters )
216+
{
217+
if ( expandedUri.hasParam( param ) )
218+
{
219+
QString fileName = expandedUri.param( param );
220+
fileName.remove( "'" );
221+
QFile::remove( fileName );
222+
}
223+
}
224224

225225
// check the connection status
226226
if ( PQstatus() != CONNECTION_OK )

0 commit comments

Comments
 (0)