MCPcopy Create free account
hub / github.com/KDE/kdiff3 / writeFile

Method writeFile

src/fileaccess.cpp:839–892  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

837}
838
839bool FileAccess::writeFile(const void* pSrcBuffer, qint64 length)
840{
841 ProgressScope pp;
842
843 setStatusText("");
844 if(isLocal())
845 {
846 if(realFile->open(QIODevice::WriteOnly))
847 {
848 const qint64 maxChunkSize = 100000;
849 ProgressProxy::setMaxNofSteps(length / maxChunkSize + 1);
850 qint64 i = 0;
851 while(i < length)
852 {
853 qint64 nextLength = std::min(length - i, maxChunkSize);
854 qint64 reallyWritten = realFile->write((char*)pSrcBuffer + i, nextLength);
855 if(reallyWritten != nextLength)
856 {
857 realFile->close();
858 return false;
859 }
860 i += reallyWritten;
861
862 ProgressProxy::step();
863 if(ProgressProxy::wasCancelled())
864 {
865 realFile->close();
866 return false;
867 }
868 }
869
870 if(isExecutable()) // value is true if the old file was executable
871 {
872 // Preserve attributes
873 realFile->setPermissions(realFile->permissions() | QFile::ExeUser);
874 }
875
876 realFile->close();
877 assert((realFile == nullptr || !realFile->isOpen()) && !tmpFile->isOpen());
878 return true;
879 }
880 }
881 else
882 {
883 bool success = mJobHandler->put(pSrcBuffer, length, true /*overwrite*/);
884 close();
885
886 assert((realFile == nullptr || !realFile->isOpen()) && !tmpFile->isOpen());
887 return success;
888 }
889
890 assert((realFile == nullptr || !realFile->isOpen()) && !tmpFile->isOpen());
891 return false;
892}
893
894bool FileAccess::copyFile(const QString& dest)
895{

Callers 1

saveDocumentMethod · 0.45

Calls 4

openMethod · 0.80
closeMethod · 0.80
writeMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected