PropagateRemoteRename is not a legacy job

move it back to propagatorjobs.cpp
This commit is contained in:
Olivier Goffart 2014-02-18 13:52:40 +01:00
parent 89b5ddec56
commit 58bda69f8b
2 changed files with 152 additions and 151 deletions

View file

@ -638,155 +638,4 @@ void PropagateDownloadFileLegacy::start()
}
void PropagateLocalRename::start()
{
if (_propagator->_abortRequested.fetchAndAddRelaxed(0))
return;
// if the file is a file underneath a moved dir, the _item.file is equal
// to _item.renameTarget and the file is not moved as a result.
if (_item._file != _item._renameTarget) {
emit progress(Progress::StartRename, _item, 0, _item._size);
qDebug() << "MOVE " << _propagator->_localDir + _item._file << " => " << _propagator->_localDir + _item._renameTarget;
QFile::rename(_propagator->_localDir + _item._file, _propagator->_localDir + _item._renameTarget);
emit progress(Progress::EndRename, _item, _item._size, _item._size);
}
_item._instruction = CSYNC_INSTRUCTION_DELETED;
_propagator->_journal->deleteFileRecord(_item._originalFile);
// store the rename file name in the item.
_item._file = _item._renameTarget;
SyncJournalFileRecord record(_item, _propagator->_localDir + _item._renameTarget);
record._path = _item._renameTarget;
if (!_item._isDirectory) { // Directory are saved at the end
_propagator->_journal->setFileRecord(record);
}
_propagator->_journal->commit("localRename");
done(SyncFileItem::Success);
}
void PropagateRemoteRename::start()
{
if (_propagator->_abortRequested.fetchAndAddRelaxed(0))
return;
if (_item._file == _item._renameTarget) {
if (!_item._isDirectory) {
// The parents has been renamed already so there is nothing more to do.
// But we still need to fetch the new ETAG
// FIXME maybe do a recusrsive propfind after having moved the parent.
// Note: we also update the mtime because the server do not keep the mtime when moving files
QScopedPointer<char, QScopedPointerPodDeleter> uri2(
ne_path_escape((_propagator->_remoteDir + _item._renameTarget).toUtf8()));
if (!updateMTimeAndETag(uri2.data(), _item._modtime))
return;
}
} else if (_item._file == QLatin1String("Shared") ) {
// Check if it is the toplevel Shared folder and do not propagate it.
if( QFile::rename( _propagator->_localDir + _item._renameTarget, _propagator->_localDir + QLatin1String("Shared")) ) {
done(SyncFileItem::NormalError, tr("This folder must not be renamed. It is renamed back to its original name."));
} else {
done(SyncFileItem::NormalError, tr("This folder must not be renamed. Please name it back to Shared."));
}
return;
} else {
emit progress(Progress::StartRename, _item, 0, _item._size);
QScopedPointer<char, QScopedPointerPodDeleter> uri1(ne_path_escape((_propagator->_remoteDir + _item._file).toUtf8()));
QScopedPointer<char, QScopedPointerPodDeleter> uri2(ne_path_escape((_propagator->_remoteDir + _item._renameTarget).toUtf8()));
qDebug() << "MOVE on Server: " << uri1.data() << "->" << uri2.data();
int rc = ne_move(_propagator->_session, 1, uri1.data(), uri2.data());
if( checkForProblemsWithShared()) {
return;
}
if (updateErrorFromSession(rc)) {
return;
}
if (!updateMTimeAndETag(uri2.data(), _item._modtime))
return;
emit progress(Progress::EndRename, _item, _item._size, _item._size);
}
_propagator->_journal->deleteFileRecord(_item._originalFile);
SyncJournalFileRecord record(_item, _propagator->_localDir + _item._renameTarget);
record._path = _item._renameTarget;
_propagator->_journal->setFileRecord(record);
_propagator->_journal->commit("Remote Rename");
done(SyncFileItem::Success);
}
bool PropagateNeonJob::updateErrorFromSession(int neon_code, ne_request* req, int ignoreHttpCode)
{
if( neon_code != NE_OK ) {
qDebug("Neon error code was %d", neon_code);
}
QString errorString;
int httpStatusCode = 0;
switch(neon_code) {
case NE_OK: /* Success, but still the possiblity of problems */
if( req ) {
const ne_status *status = ne_get_status(req);
if (status) {
if ( status->klass == 2 || status->code == ignoreHttpCode) {
// Everything is ok, no error.
return false;
}
errorString = QString::fromUtf8( status->reason_phrase );
httpStatusCode = status->code;
_item._httpErrorCode = httpStatusCode;
}
} else {
errorString = QString::fromUtf8(ne_get_error(_propagator->_session));
httpStatusCode = errorString.mid(0, errorString.indexOf(QChar(' '))).toInt();
_item._httpErrorCode = httpStatusCode;
if ((httpStatusCode >= 200 && httpStatusCode < 300)
|| (httpStatusCode != 0 && httpStatusCode == ignoreHttpCode)) {
// No error
return false;
}
}
// FIXME: classify the error
done (SyncFileItem::NormalError, errorString);
return true;
case NE_ERROR: /* Generic error; use ne_get_error(session) for message */
errorString = QString::fromUtf8(ne_get_error(_propagator->_session));
// Check if we don't need to ignore that error.
httpStatusCode = errorString.mid(0, errorString.indexOf(QChar(' '))).toInt();
_item._httpErrorCode = httpStatusCode;
qDebug() << Q_FUNC_INFO << "NE_ERROR" << errorString << httpStatusCode << ignoreHttpCode;
if (ignoreHttpCode && httpStatusCode == ignoreHttpCode)
return false;
done(SyncFileItem::NormalError, errorString);
return true;
case NE_LOOKUP: /* Server or proxy hostname lookup failed */
case NE_AUTH: /* User authentication failed on server */
case NE_PROXYAUTH: /* User authentication failed on proxy */
case NE_CONNECT: /* Could not connect to server */
case NE_TIMEOUT: /* Connection timed out */
done(SyncFileItem::FatalError, QString::fromUtf8(ne_get_error(_propagator->_session)));
return true;
case NE_FAILED: /* The precondition failed */
case NE_RETRY: /* Retry request (ne_end_request ONLY) */
case NE_REDIRECT: /* See ne_redirect.h */
default:
done(SyncFileItem::SoftError, QString::fromUtf8(ne_get_error(_propagator->_session)));
return true;
}
return false;
}
}

View file

@ -205,4 +205,156 @@ void PropagateRemoteMkdir::start()
}
void PropagateLocalRename::start()
{
if (_propagator->_abortRequested.fetchAndAddRelaxed(0))
return;
// if the file is a file underneath a moved dir, the _item.file is equal
// to _item.renameTarget and the file is not moved as a result.
if (_item._file != _item._renameTarget) {
emit progress(Progress::StartRename, _item, 0, _item._size);
qDebug() << "MOVE " << _propagator->_localDir + _item._file << " => " << _propagator->_localDir + _item._renameTarget;
QFile::rename(_propagator->_localDir + _item._file, _propagator->_localDir + _item._renameTarget);
emit progress(Progress::EndRename, _item, _item._size, _item._size);
}
_item._instruction = CSYNC_INSTRUCTION_DELETED;
_propagator->_journal->deleteFileRecord(_item._originalFile);
// store the rename file name in the item.
_item._file = _item._renameTarget;
SyncJournalFileRecord record(_item, _propagator->_localDir + _item._renameTarget);
record._path = _item._renameTarget;
if (!_item._isDirectory) { // Directory are saved at the end
_propagator->_journal->setFileRecord(record);
}
_propagator->_journal->commit("localRename");
done(SyncFileItem::Success);
}
void PropagateRemoteRename::start()
{
if (_propagator->_abortRequested.fetchAndAddRelaxed(0))
return;
if (_item._file == _item._renameTarget) {
if (!_item._isDirectory) {
// The parents has been renamed already so there is nothing more to do.
// But we still need to fetch the new ETAG
// FIXME maybe do a recusrsive propfind after having moved the parent.
// Note: we also update the mtime because the server do not keep the mtime when moving files
QScopedPointer<char, QScopedPointerPodDeleter> uri2(
ne_path_escape((_propagator->_remoteDir + _item._renameTarget).toUtf8()));
if (!updateMTimeAndETag(uri2.data(), _item._modtime))
return;
}
} else if (_item._file == QLatin1String("Shared") ) {
// Check if it is the toplevel Shared folder and do not propagate it.
if( QFile::rename( _propagator->_localDir + _item._renameTarget, _propagator->_localDir + QLatin1String("Shared")) ) {
done(SyncFileItem::NormalError, tr("This folder must not be renamed. It is renamed back to its original name."));
} else {
done(SyncFileItem::NormalError, tr("This folder must not be renamed. Please name it back to Shared."));
}
return;
} else {
emit progress(Progress::StartRename, _item, 0, _item._size);
QScopedPointer<char, QScopedPointerPodDeleter> uri1(ne_path_escape((_propagator->_remoteDir + _item._file).toUtf8()));
QScopedPointer<char, QScopedPointerPodDeleter> uri2(ne_path_escape((_propagator->_remoteDir + _item._renameTarget).toUtf8()));
qDebug() << "MOVE on Server: " << uri1.data() << "->" << uri2.data();
int rc = ne_move(_propagator->_session, 1, uri1.data(), uri2.data());
if( checkForProblemsWithShared()) {
return;
}
if (updateErrorFromSession(rc)) {
return;
}
if (!updateMTimeAndETag(uri2.data(), _item._modtime))
return;
emit progress(Progress::EndRename, _item, _item._size, _item._size);
}
_propagator->_journal->deleteFileRecord(_item._originalFile);
SyncJournalFileRecord record(_item, _propagator->_localDir + _item._renameTarget);
record._path = _item._renameTarget;
_propagator->_journal->setFileRecord(record);
_propagator->_journal->commit("Remote Rename");
done(SyncFileItem::Success);
}
bool PropagateNeonJob::updateErrorFromSession(int neon_code, ne_request* req, int ignoreHttpCode)
{
if( neon_code != NE_OK ) {
qDebug("Neon error code was %d", neon_code);
}
QString errorString;
int httpStatusCode = 0;
switch(neon_code) {
case NE_OK: /* Success, but still the possiblity of problems */
if( req ) {
const ne_status *status = ne_get_status(req);
if (status) {
if ( status->klass == 2 || status->code == ignoreHttpCode) {
// Everything is ok, no error.
return false;
}
errorString = QString::fromUtf8( status->reason_phrase );
httpStatusCode = status->code;
_item._httpErrorCode = httpStatusCode;
}
} else {
errorString = QString::fromUtf8(ne_get_error(_propagator->_session));
httpStatusCode = errorString.mid(0, errorString.indexOf(QChar(' '))).toInt();
_item._httpErrorCode = httpStatusCode;
if ((httpStatusCode >= 200 && httpStatusCode < 300)
|| (httpStatusCode != 0 && httpStatusCode == ignoreHttpCode)) {
// No error
return false;
}
}
// FIXME: classify the error
done (SyncFileItem::NormalError, errorString);
return true;
case NE_ERROR: /* Generic error; use ne_get_error(session) for message */
errorString = QString::fromUtf8(ne_get_error(_propagator->_session));
// Check if we don't need to ignore that error.
httpStatusCode = errorString.mid(0, errorString.indexOf(QChar(' '))).toInt();
_item._httpErrorCode = httpStatusCode;
qDebug() << Q_FUNC_INFO << "NE_ERROR" << errorString << httpStatusCode << ignoreHttpCode;
if (ignoreHttpCode && httpStatusCode == ignoreHttpCode)
return false;
done(SyncFileItem::NormalError, errorString);
return true;
case NE_LOOKUP: /* Server or proxy hostname lookup failed */
case NE_AUTH: /* User authentication failed on server */
case NE_PROXYAUTH: /* User authentication failed on proxy */
case NE_CONNECT: /* Could not connect to server */
case NE_TIMEOUT: /* Connection timed out */
done(SyncFileItem::FatalError, QString::fromUtf8(ne_get_error(_propagator->_session)));
return true;
case NE_FAILED: /* The precondition failed */
case NE_RETRY: /* Retry request (ne_end_request ONLY) */
case NE_REDIRECT: /* See ne_redirect.h */
default:
done(SyncFileItem::SoftError, QString::fromUtf8(ne_get_error(_propagator->_session)));
return true;
}
return false;
}
}