forked from qt-creator/qt-creator
Fix saving of hardlinked files
Our atomic write involves writing a temp file and renaming that (which is the only way to achieve something atomic). This creates a new inode, and disconnects any hardlinks. Note that the existing implementation for file paths with needsDevice already keeps hardlinks intact, because even though it first writes into a local temporary file it then writes the content directly into the target with dd. Check the number of hard links via system API and fallback to unsafe writing if there are any, for desktop paths. Fixes: QTCREATORBUG-19651 Change-Id: I3ce1ee81f339f241f0a2c9aa6f2259cb118ebef6 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "savefile.h"
|
||||
|
||||
#include "algorithm.h"
|
||||
#include "devicefileaccess.h"
|
||||
#include "qtcassert.h"
|
||||
#include "utilstr.h"
|
||||
|
||||
@@ -189,12 +190,13 @@ FileSaver::FileSaver(const FilePath &filePath, QIODevice::OpenMode mode)
|
||||
auto tf = new QTemporaryFile(QDir::tempPath() + "/remotefilesaver-XXXXXX");
|
||||
tf->setAutoRemove(false);
|
||||
m_file.reset(tf);
|
||||
} else if (mode & (QIODevice::ReadOnly | QIODevice::Append)) {
|
||||
m_file.reset(new QFile{filePath.path()});
|
||||
m_isSafe = false;
|
||||
} else {
|
||||
m_file.reset(new SaveFile(filePath));
|
||||
m_isSafe = true;
|
||||
const bool readOnlyOrAppend = mode & (QIODevice::ReadOnly | QIODevice::Append);
|
||||
m_isSafe = !readOnlyOrAppend && !filePath.hasHardLinks();
|
||||
if (m_isSafe)
|
||||
m_file.reset(new SaveFile(filePath));
|
||||
else
|
||||
m_file.reset(new QFile{filePath.path()});
|
||||
}
|
||||
if (!m_file->open(QIODevice::WriteOnly | mode)) {
|
||||
QString err = filePath.exists() ?
|
||||
|
||||
Reference in New Issue
Block a user