Skip to content

Commit

Permalink
Test without suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Jan 17, 2023
1 parent 24703f7 commit 35b3cb6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/qgsfileutils.cpp
Expand Up @@ -539,7 +539,7 @@ QString QgsFileUtils::uniquePath( const QString &path )

QFileInfo info { path };
const QString suffix { info.completeSuffix() };
const QString pathPattern { QString( suffix.length() > 0 ? path.chopped( suffix.length() + 1 ) : path ).append( QStringLiteral( "_%1." ) ).append( suffix ) };
const QString pathPattern { QString( suffix.isEmpty() ? path : path.chopped( suffix.length() + 1 ) ).append( suffix.isEmpty() ? QStringLiteral( "_%1" ) : QStringLiteral( "_%1." ) ).append( suffix ) };
int i { 2 };
QString uniquePath { pathPattern.arg( i ) };
while ( QFileInfo::exists( uniquePath ) )
Expand Down
5 changes: 5 additions & 0 deletions tests/src/python/test_qgsfileutils.py
Expand Up @@ -330,6 +330,11 @@ def testUniquePath(self):
self.assertEqual(QgsFileUtils.uniquePath(os.path.join(temp_path, 'test.txt')), os.path.join(temp_path, 'test_3.txt'))
self.assertEqual(QgsFileUtils.uniquePath(os.path.join(temp_path, 'test_1.txt')), os.path.join(temp_path, 'test_1.txt'))

with open(os.path.join(temp_path, 'test'), 'w+') as f:
f.close()

self.assertEqual(QgsFileUtils.uniquePath(os.path.join(temp_path, 'test')), os.path.join(temp_path, 'test_2'))


if __name__ == '__main__':
unittest.main()

0 comments on commit 35b3cb6

Please sign in to comment.