1
0
mirror of https://github.com/chylex/Nextcloud-Desktop.git synced 2025-04-09 19:15:43 +02:00

ChunkingNG: add '0' padding on the filename ()

The server sorts the chunk by name alphabetically. So if we want to keep
the chunk in order, we need to add a few '0' in front of the chunk name
This commit is contained in:
Olivier Goffart 2017-01-20 16:03:50 +01:00 committed by Markus Goetz
parent faedaa5e09
commit d6fdda8efa
3 changed files with 14 additions and 9 deletions

View File

@ -300,7 +300,8 @@ private:
// Map chunk number with its size from the PROPFIND on resume.
// (Only used from slotPropfindIterate/slotPropfindFinished because the LsColJob use signals to report data.)
QMap<int, quint64> _serverChunks;
struct ServerChunkInfo { quint64 size; QString originalName; };
QMap<int, ServerChunkInfo> _serverChunks;
quint64 chunkSize() const { return propagator()->chunkSize(); }
/**

View File

@ -41,7 +41,8 @@ QUrl PropagateUploadFileNG::chunkUrl(int chunk)
+ propagator()->account()->davUser()
+ QLatin1Char('/') + QString::number(_transferId);
if (chunk >= 0) {
path += QLatin1Char('/') + QString::number(chunk);
// We need to do add leading 0 because the server orders the chunk alphabetically
path += QLatin1Char('/') + QString::number(chunk).rightJustified(8, '0');
}
return Utility::concatUrlPath(propagator()->account()->url(), path);
}
@ -108,9 +109,11 @@ void PropagateUploadFileNG::slotPropfindIterate(const QString &name, const QMap<
return; // skip the info about the path itself
}
bool ok = false;
auto chunkId = name.mid(name.lastIndexOf('/')+1).toUInt(&ok);
QString chunkName = name.mid(name.lastIndexOf('/')+1);
auto chunkId = chunkName.toUInt(&ok);
if (ok) {
_serverChunks[chunkId] = properties["getcontentlength"].toULongLong();
ServerChunkInfo chunkinfo = { properties["getcontentlength"].toULongLong(), chunkName };
_serverChunks[chunkId] = chunkinfo;
}
}
@ -123,7 +126,7 @@ void PropagateUploadFileNG::slotPropfindFinished()
_currentChunk = 0;
_sent = 0;
while (_serverChunks.contains(_currentChunk)) {
_sent += _serverChunks[_currentChunk];
_sent += _serverChunks[_currentChunk].size;
_serverChunks.remove(_currentChunk);
++_currentChunk;
}
@ -141,7 +144,7 @@ void PropagateUploadFileNG::slotPropfindFinished()
qDebug() << "Resuming "<< _item->_file << " from chunk " << _currentChunk << "; sent ="<< _sent;
if (!_serverChunks.isEmpty()) {
qDebug() << "To Delete" << _serverChunks;
qDebug() << "To Delete" << _serverChunks.keys();
propagator()->_activeJobList.append(this);
_removeJobError = false;
@ -149,7 +152,7 @@ void PropagateUploadFileNG::slotPropfindFinished()
// we should remove the later chunks. Otherwise when we do dynamic chunk sizing, we may end up
// with corruptions if there are too many chunks, or if we abort and there are still stale chunks.
for (auto it = _serverChunks.begin(); it != _serverChunks.end(); ++it) {
auto job = new DeleteJob(propagator()->account(), Utility::concatUrlPath(chunkUrl(), QString::number(it.key())), this);
auto job = new DeleteJob(propagator()->account(), Utility::concatUrlPath(chunkUrl(), it->originalName), this);
QObject::connect(job, SIGNAL(finishedSignal()), this, SLOT(slotDeleteJobFinished()));
_jobs.append(job);
job->start();

View File

@ -589,9 +589,10 @@ public:
char payload = '*';
do {
if (!sourceFolder->children.contains(QString::number(count)))
QString chunkName = QString::number(count).rightJustified(8, '0');
if (!sourceFolder->children.contains(chunkName))
break;
auto &x = sourceFolder->children[QString::number(count)];
auto &x = sourceFolder->children[chunkName];
Q_ASSERT(!x.isDir);
Q_ASSERT(x.size > 0); // There should not be empty chunks
size += x.size;