file.setPermissions(permissions);
}
+
+void FileSystem::setFileReadOnlyWeak(const QString& filename, bool readonly)
+{
+ QFile file(filename);
+ QFile::Permissions permissions = file.permissions();
+
+ if (!readonly && (permissions & QFile::WriteOwner)) {
+ return; // already writable enough
+ }
+
+ setFileReadOnly(filename, readonly);
+}
+
time_t FileSystem::getModTime(const QString &filename)
{
csync_vio_file_stat_t* stat = csync_vio_file_stat_new();
*/
void OWNCLOUDSYNC_EXPORT setFileReadOnly(const QString& filename, bool readonly);
+/**
+ * @brief Marks the file as read-only.
+ *
+ * It's like setFileReadOnly(), but weaker: if readonly is false and the user
+ * already has write permissions, no change to the permissions is made.
+ *
+ * This means that it will preserve explicitly set rw-r--r-- permissions even
+ * when the umask is 0002. (setFileReadOnly() would adjust to rw-rw-r--)
+ */
+void OWNCLOUDSYNC_EXPORT setFileReadOnlyWeak(const QString& filename, bool readonly);
+
/** convert a "normal" windows path into a path that can be 32k chars long. */
QString OWNCLOUDSYNC_EXPORT longWinPath( const QString& inpath );
}
// Apply the remote permissions
- FileSystem::setFileReadOnly(_tmpFile.fileName(),
- !_item->_remotePerm.contains('W'));
+ FileSystem::setFileReadOnlyWeak(_tmpFile.fileName(),
+ !_item->_remotePerm.contains('W'));
QString error;
_propagator->addTouchedFile(fn);
SyncJournalFileRecord prev = _journal->getFileRecord(item->_file);
if (prev._remotePerm.contains('W') != item->_remotePerm.contains('W')) {
const bool isReadOnly = !item->_remotePerm.contains('W');
- FileSystem::setFileReadOnly(filePath, isReadOnly);
+ FileSystem::setFileReadOnlyWeak(filePath, isReadOnly);
}
_journal->setFileRecordMetadata(SyncJournalFileRecord(*item, filePath));