Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proper symlink handling for layers and projects #60140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/core/qgsarchive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,18 @@ bool QgsArchive::zip( const QString &filename )
return false;
}

QString target {filename};

// remove existing zip file
if ( QFile::exists( filename ) )
QFile::remove( filename );
if ( QFile::exists( target ) )
{
// If symlink -> we want to write to its target instead
const QFileInfo targetFileInfo( target );
target = targetFileInfo.canonicalFilePath();
// If target still exists, remove (might not exist if was a dangling symlink)
if ( QFile::exists( target ) )
QFile::remove( target );
}

#ifdef Q_OS_WIN
// Clear temporary flag (see GH #32118)
Expand All @@ -94,9 +103,9 @@ bool QgsArchive::zip( const QString &filename )
#endif // Q_OS_WIN

// save zip archive
if ( ! tmpFile.rename( filename ) )
if ( ! tmpFile.rename( target ) )
{
const QString err = QObject::tr( "Unable to save zip file '%1'" ).arg( filename );
const QString err = QObject::tr( "Unable to save zip file '%1'" ).arg( target );
QgsMessageLog::logMessage( err, QStringLiteral( "QgsArchive" ) );
return false;
}
Expand Down
8 changes: 5 additions & 3 deletions src/core/qgspathresolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ QString QgsPathResolver::readPath( const QString &f ) const
}
else
{
return vsiPrefix + fi.canonicalFilePath();
return vsiPrefix + QDir::cleanPath( fi.absoluteFilePath() );
}
}

Expand Down Expand Up @@ -266,7 +266,8 @@ QString QgsPathResolver::writePath( const QString &s ) const

// Get projPath even if project has not been created yet
const QFileInfo pfi( QFileInfo( mBaseFileName ).path() );
QString projPath = pfi.canonicalFilePath();
// readPath does not resolve symlink, so writePath should not either
QString projPath = pfi.absoluteFilePath();

// If project directory doesn't exit, fallback to absoluteFilePath : symbolic
// links won't be handled correctly, but that's OK as the path is "virtual".
Expand All @@ -291,7 +292,8 @@ QString QgsPathResolver::writePath( const QString &s ) const

const QFileInfo srcFileInfo( srcPath );
if ( srcFileInfo.exists() )
srcPath = srcFileInfo.canonicalFilePath();
// Do NOT resolve symlinks, but do remove '..' and '.'
srcPath = QDir::cleanPath( srcFileInfo.absoluteFilePath() );

// if this is a VSIFILE, remove the VSI prefix and append to final result
const QString vsiPrefix = QgsGdalUtils::vsiPrefixForPath( src );
Expand Down
Loading
Loading