mirror of
https://github.com/ioquake/launch.git
synced 2025-02-21 11:10:50 +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;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString tempDestFilename = FileUtils::uniqueFilename(files.at(i).dest);
|
// Write to the destination file if it doesn't exist, otherwise write to a uniquely named file.
|
||||||
QFile destinationFile(tempDestFilename);
|
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))
|
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;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileOperation 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.
|
||||||
fo.source = tempDestFilename;
|
if (destExists)
|
||||||
fo.dest = files.at(i).dest;
|
{
|
||||||
renameOperations.append(fo);
|
FileOperation fo;
|
||||||
|
fo.source = destFilename;
|
||||||
|
fo.dest = files.at(i).dest;
|
||||||
|
renameOperations.append(fo);
|
||||||
|
}
|
||||||
|
|
||||||
emit fileChanged(QFileInfo(sourceFile.fileName()).fileName());
|
emit fileChanged(QFileInfo(sourceFile.fileName()).fileName());
|
||||||
const qint64 totalBytes = sourceFile.size();
|
const qint64 totalBytes = sourceFile.size();
|
||||||
|
|
Loading…
Reference in a new issue