Keep permissions of the saved files intact.

Previously the permission were destroyed by the newly created
temporary file -- which is later used as new saved file.
Tested on symlinks as well but only on Linux.
This commit is contained in:
Pavel Sanda 2018-12-07 23:10:46 +01:00
parent 32c6724fd6
commit 04fe818b22
3 changed files with 12 additions and 0 deletions

View File

@ -1443,6 +1443,9 @@ bool Buffer::save() const
FileName savefile(tempfile->name());
LYXERR(Debug::FILES, "Saving to " << savefile.absFileName());
if (!savefile.clonePermissions(fileName()))
LYXERR0("Failed to clone the permission from " << fileName().absFileName() << " to " << savefile.absFileName());
if (!writeFile(savefile))
return false;

View File

@ -288,6 +288,13 @@ bool FileName::changePermission(unsigned long int mode) const
return true;
}
bool FileName::clonePermissions(FileName const & source)
{
QFile fin(toqstr(source.absFileName()));
QFile f(toqstr(absFileName()));
return f.setPermissions(fin.permissions());
}
string FileName::toFilesystemEncoding() const
{

View File

@ -150,6 +150,8 @@ public:
/// support this.
/// \return true on success.
bool changePermission(unsigned long int mode) const;
// sets permission based on the file given as an argument
bool clonePermissions(FileName const & target);
/// remove pointed directory and all contents.
/// \return true on success.