Commit c5592689 authored by Chinmoy Ranjan Pradhan's avatar Chinmoy Ranjan Pradhan Committed by Albert Astals Cid
Browse files

Obey umask rules when saving new file

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:
parent 3cea7c99
......@@ -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 );
return true;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment