mirror of
https://github.com/ioquake/launch.git
synced 2025-02-19 18:30:42 +00:00
Fixed file transaction handling when the destination file doesn't exist.
This commit is contained in:
parent
5897c21ddc
commit
f39872b24e
1 changed files with 23 additions and 7 deletions
30
filecopy.cpp
30
filecopy.cpp
|
@ -59,19 +59,35 @@ void FileCopyWorker::copy()
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
const QString tempDestFilename = FileUtils::uniqueFilename(files.at(i).dest);
|
||||
QFile destinationFile(tempDestFilename);
|
||||
// Write to the destination file if it doesn't exist, otherwise write to a uniquely named file.
|
||||
const bool destExists = QFile::exists(files.at(i).dest);
|
||||
QString destFilename;
|
||||
|
||||
if (destExists)
|
||||
{
|
||||
destFilename = FileUtils::uniqueFilename(files.at(i).dest);
|
||||
}
|
||||
else
|
||||
{
|
||||
destFilename = files.at(i).dest;
|
||||
}
|
||||
|
||||
QFile destinationFile(destFilename);
|
||||
|
||||
if (!destinationFile.open(QIODevice::WriteOnly))
|
||||
{
|
||||
emit errorMessage(QString("'%1': %2").arg(tempDestFilename).arg(destinationFile.errorString()));
|
||||
emit errorMessage(QString("'%1': %2").arg(destFilename).arg(destinationFile.errorString()));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
FileOperation fo;
|
||||
fo.source = tempDestFilename;
|
||||
fo.dest = files.at(i).dest;
|
||||
renameOperations.append(fo);
|
||||
// Don't add a rename operation if the destination file doesn't exist - not trying to overwrite, don't need to rename anything to complete the transaction.
|
||||
if (destExists)
|
||||
{
|
||||
FileOperation fo;
|
||||
fo.source = destFilename;
|
||||
fo.dest = files.at(i).dest;
|
||||
renameOperations.append(fo);
|
||||
}
|
||||
|
||||
emit fileChanged(QFileInfo(sourceFile.fileName()).fileName());
|
||||
const qint64 totalBytes = sourceFile.size();
|
||||
|
|
Loading…
Reference in a new issue