From c5592689874f41df393b44f3ba572acc751c5645 Mon Sep 17 00:00:00 2001 From: Chinmoy Ranjan Pradhan Date: Mon, 23 Apr 2018 22:52:28 +0200 Subject: [PATCH 1/2] Obey umask rules when saving new file Summary: Okular saves a new file with permissions 0600 completely ignoring the umask value. This is because it makes use of QTemporaryFile which creates file with the said permissions and which then Okular copies to the new location. So to overcome this generate new file permissions using old mask value and change permissions of the new file. BUG: 392682 Test Plan: Set umask to 0040 Open a pdf file from the same shell and save it under a new name. Before patch: file permisions -> 0600 After patch: file permisions -> 0606 Reviewers: #okular, aacid Tags: #okular Differential Revision: https://phabricator.kde.org/D12049 --- part.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/part.cpp b/part.cpp index 42485f0b8..92b5db5f4 100644 --- a/part.cpp +++ b/part.cpp @@ -2758,6 +2758,18 @@ bool Part::saveAs( const QUrl & saveUrl, SaveAsFlags flags ) if ( url().isLocalFile() ) setFileToWatch( localFilePath() ); + //Set correct permission taking into account the umask value +#ifndef Q_OS_WIN + const QString saveFilePath = saveUrl.toLocalFile(); + if ( QFile::exists( saveFilePath ) ) + { + const mode_t mask = umask( 0 ); + umask( mask ); + const mode_t fileMode = 0666 & ~mask; + chmod( saveFilePath.toUtf8().constData(), fileMode ); + } +#endif + return true; } From 991eb0ed31251429d566e882401eb4bf2ad57ba2 Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Mon, 23 Apr 2018 23:08:06 +0200 Subject: [PATCH 2/2] Use toLocal8Bit instead of toUtf8 It's the most "proper" way to do it, i guess in real world scenarios it doesn't really matter though --- part.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/part.cpp b/part.cpp index 92b5db5f4..344b19699 100644 --- a/part.cpp +++ b/part.cpp @@ -2766,7 +2766,7 @@ bool Part::saveAs( const QUrl & saveUrl, SaveAsFlags flags ) const mode_t mask = umask( 0 ); umask( mask ); const mode_t fileMode = 0666 & ~mask; - chmod( saveFilePath.toUtf8().constData(), fileMode ); + chmod( saveFilePath.toLocal8Bit().constData(), fileMode ); } #endif