Resolve symlinks before saving so we don't "break" them

Summary: BUGS: 399870

Reviewers: ngraham

Reviewed By: ngraham

Subscribers: shubham, ngraham, okular-devel

Tags: #okular

Differential Revision: https://phabricator.kde.org/D16364
remotes/origin/Applications/18.08
Albert Astals Cid 7 years ago
parent 27197b5f76
commit 99fe8fa6cf
  1. 14
      part.cpp

@ -2536,6 +2536,10 @@ bool Part::saveAs( const QUrl & saveUrl, SaveAsFlags flags )
fileName = tf.fileName();
tf.close();
// Figure out the real save url, for symlinks we don't want to copy over the symlink but over the target file
const QUrl realSaveUrl = saveUrl.isLocalFile() ? QUrl::fromLocalFile( QFileInfo( saveUrl.toLocalFile() ).canonicalFilePath() )
: saveUrl;
QScopedPointer<QTemporaryFile> tempFile;
KIO::Job *copyJob = nullptr; // this will be filled with the job that writes to saveUrl
@ -2564,7 +2568,7 @@ bool Part::saveAs( const QUrl & saveUrl, SaveAsFlags flags )
return false;
}
copyJob = KIO::file_copy( QUrl::fromLocalFile( fileName ), saveUrl, -1, KIO::Overwrite );
copyJob = KIO::file_copy( QUrl::fromLocalFile( fileName ), realSaveUrl, -1, KIO::Overwrite );
}
else
{
@ -2638,7 +2642,7 @@ bool Part::saveAs( const QUrl & saveUrl, SaveAsFlags flags )
return false;
}
copyJob = KIO::file_copy( QUrl::fromLocalFile( fileName ), saveUrl, -1, KIO::Overwrite );
copyJob = KIO::file_copy( QUrl::fromLocalFile( fileName ), realSaveUrl, -1, KIO::Overwrite );
}
else
{
@ -2658,7 +2662,7 @@ bool Part::saveAs( const QUrl & saveUrl, SaveAsFlags flags )
return false;
}
copyJob = KIO::file_copy( QUrl::fromLocalFile( fileName ), saveUrl, -1, KIO::Overwrite );
copyJob = KIO::file_copy( QUrl::fromLocalFile( fileName ), realSaveUrl, -1, KIO::Overwrite );
}
else
{
@ -2692,12 +2696,12 @@ bool Part::saveAs( const QUrl & saveUrl, SaveAsFlags flags )
if ( srcUrl != saveUrl )
{
copyJob = KIO::file_copy( srcUrl, saveUrl, -1, KIO::Overwrite );
copyJob = KIO::file_copy( srcUrl, realSaveUrl, -1, KIO::Overwrite );
}
else
{
// Don't do a real copy in this case, just update the timestamps
copyJob = KIO::setModificationTime( saveUrl, QDateTime::currentDateTime() );
copyJob = KIO::setModificationTime( realSaveUrl, QDateTime::currentDateTime() );
}
}
}

Loading…
Cancel
Save