summaryrefslogtreecommitdiff
path: root/src/libs/utils/savefile.cpp
diff options
context:
space:
mode:
authorKnut Petter Svendsen <knutpett@pvv.org>2013-01-28 21:15:04 +0100
committerOrgad Shaneh <orgads@gmail.com>2013-01-29 14:50:05 +0100
commitf556e8f5f2d99c9dc927db403e56e33d275f52e8 (patch)
tree5ff14ee9a36978638b93048a897e7c713e703606 /src/libs/utils/savefile.cpp
parent7fcc52bf47e11f34b18ef4aaea0b70e5a545f96e (diff)
downloadqt-creator-f556e8f5f2d99c9dc927db403e56e33d275f52e8.tar.gz
Fix: Make sure umask is used when creating new files
When a new file was created from the file menu, the permissions on *nix was always 0600 regardless of the proess' current umask. Fixed by letting CorePlugin::initialize() initialize the umask in Utils::SaveFile. Since getting the system's umask is not thread safe this can't be done directly in SaveFile::open. Task-number: QTCREATORBUG-6513 Change-Id: I10d8b2f4ab85574ed3004b5e646664c2255196b9 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'src/libs/utils/savefile.cpp')
-rw-r--r--src/libs/utils/savefile.cpp39
1 files changed, 38 insertions, 1 deletions
diff --git a/src/libs/utils/savefile.cpp b/src/libs/utils/savefile.cpp
index bd6278a587..55ba2925fb 100644
--- a/src/libs/utils/savefile.cpp
+++ b/src/libs/utils/savefile.cpp
@@ -34,10 +34,13 @@
# include <windows.h>
#else
# include <unistd.h>
+# include <sys/stat.h>
#endif
namespace Utils {
+QFile::Permissions SaveFile::m_umask = 0;
+
SaveFile::SaveFile(const QString &filename) :
m_finalFileName(filename), m_finalized(true), m_backup(false)
{
@@ -65,8 +68,19 @@ bool SaveFile::open(OpenMode flags)
return false;
m_finalized = false; // needs clean up in the end
- if (ofi.exists())
+ if (ofi.exists()) {
setPermissions(ofi.permissions()); // Ignore errors
+ } else {
+ Permissions permAll = QFile::ReadOwner
+ | QFile::ReadGroup
+ | QFile::ReadOther
+ | QFile::WriteOwner
+ | QFile::WriteGroup
+ | QFile::WriteOther;
+
+ // set permissions with respect to the current umask
+ setPermissions(permAll & ~m_umask);
+ }
return true;
}
@@ -114,4 +128,27 @@ bool SaveFile::commit()
return true;
}
+void SaveFile::initializeUmask()
+{
+#ifdef Q_OS_WIN
+ m_umask = QFile::WriteGroup | QFile::WriteOther;
+#else
+ // Get the current process' file creation mask (umask)
+ // umask() is not thread safe so this has to be done by single threaded
+ // application initialization
+ mode_t mask = umask(0); // get current umask
+ umask(mask); // set it back
+
+ m_umask = ((mask & S_IRUSR) ? QFile::ReadOwner : QFlags<QFile::Permission>(0))
+ | ((mask & S_IWUSR) ? QFile::WriteOwner : QFlags<QFile::Permission>(0))
+ | ((mask & S_IXUSR) ? QFile::ExeOwner : QFlags<QFile::Permission>(0))
+ | ((mask & S_IRGRP) ? QFile::ReadGroup : QFlags<QFile::Permission>(0))
+ | ((mask & S_IWGRP) ? QFile::WriteGroup : QFlags<QFile::Permission>(0))
+ | ((mask & S_IXGRP) ? QFile::ExeGroup : QFlags<QFile::Permission>(0))
+ | ((mask & S_IROTH) ? QFile::ReadOther : QFlags<QFile::Permission>(0))
+ | ((mask & S_IWOTH) ? QFile::WriteOther : QFlags<QFile::Permission>(0))
+ | ((mask & S_IXOTH) ? QFile::ExeOther : QFlags<QFile::Permission>(0));
+#endif
+}
+
} // namespace Utils