Changeset View
Changeset View
Standalone View
Standalone View
sftp/kio_sftp.cpp
Show First 20 Lines • Show All 243 Lines • ▼ Show 20 Line(s) | |||||
244 | 244 | | |||
245 | void sftpProtocol::virtual_hook(int id, void *data) | 245 | void sftpProtocol::virtual_hook(int id, void *data) | ||
246 | { | 246 | { | ||
247 | switch(id) { | 247 | switch(id) { | ||
248 | case SlaveBase::GetFileSystemFreeSpace: { | 248 | case SlaveBase::GetFileSystemFreeSpace: { | ||
249 | QUrl *url = static_cast<QUrl *>(data); | 249 | QUrl *url = static_cast<QUrl *>(data); | ||
250 | fileSystemFreeSpace(*url); | 250 | fileSystemFreeSpace(*url); | ||
251 | } break; | 251 | } break; | ||
252 | case SlaveBase::Truncate: { | ||||
253 | auto length = static_cast<KIO::filesize_t *>(data); | ||||
254 | truncate(*length); | ||||
255 | } break; | ||||
252 | default: | 256 | default: | ||
253 | SlaveBase::virtual_hook(id, data); | 257 | SlaveBase::virtual_hook(id, data); | ||
254 | } | 258 | } | ||
255 | } | 259 | } | ||
256 | 260 | | |||
257 | int sftpProtocol::authenticateKeyboardInteractive(AuthInfo &info) { | 261 | int sftpProtocol::authenticateKeyboardInteractive(AuthInfo &info) { | ||
258 | 262 | | |||
259 | int err = ssh_userauth_kbdint(mSession, nullptr, nullptr); | 263 | int err = ssh_userauth_kbdint(mSession, nullptr, nullptr); | ||
▲ Show 20 Lines • Show All 1205 Lines • ▼ Show 20 Line(s) | 1464 | void sftpProtocol::seek(KIO::filesize_t offset) { | |||
1465 | if (sftp_seek64(mOpenFile, static_cast<uint64_t>(offset)) < 0) { | 1469 | if (sftp_seek64(mOpenFile, static_cast<uint64_t>(offset)) < 0) { | ||
1466 | error(KIO::ERR_CANNOT_SEEK, mOpenUrl.path()); | 1470 | error(KIO::ERR_CANNOT_SEEK, mOpenUrl.path()); | ||
1467 | closeWithoutFinish(); | 1471 | closeWithoutFinish(); | ||
1468 | return; | 1472 | return; | ||
1469 | } | 1473 | } | ||
1470 | 1474 | | |||
1471 | position(sftp_tell64(mOpenFile)); | 1475 | position(sftp_tell64(mOpenFile)); | ||
1472 | } | 1476 | } | ||
1477 | void sftpProtocol::truncate(KIO::filesize_t length) { | ||||
1478 | qCDebug(KIO_SFTP_LOG) << "truncate, length =" << length; | ||||
dfaure: [minor: qDebug already appends spaces between arguments, so you get two here after the '='] | |||||
1479 | | ||||
1480 | Q_ASSERT(mOpenFile); | ||||
1481 | | ||||
1482 | int errorCode = 0; | ||||
1483 | sftp_attributes attr = sftp_fstat(mOpenFile); | ||||
1484 | if (attr) { | ||||
fvogt: This entire block is duplicated - can that be improved? | |||||
1485 | attr->size = length; | ||||
1486 | if (sftp_setstat(mSftp, mOpenUrl.path().toUtf8().constData(), attr) == 0) { | ||||
1487 | truncated(length); | ||||
1488 | } else { | ||||
1489 | errorCode = toKIOError(sftp_get_error(mSftp)); | ||||
1490 | } | ||||
1491 | sftp_attributes_free(attr); | ||||
1492 | } else { | ||||
1493 | errorCode = toKIOError(sftp_get_error(mSftp)); | ||||
1494 | } | ||||
1495 | | ||||
1496 | if (errorCode) { | ||||
fvogt: AFAICT, this has to be done in every case. | |||||
I wasn't too sure if attr was needed by libssh if the call succeeded. Looking at the source code it seems that you are probably right and can be freed in all circumstances. feverfew: I wasn't too sure if `attr` was needed by libssh if the call succeeded. Looking at the source… | |||||
1497 | error(errorCode == KIO::ERR_INTERNAL ? KIO::ERR_CANNOT_TRUNCATE : errorCode, mOpenUrl.path()); | ||||
self-assignment in some cases is a weird thing to do. dfaure: self-assignment in some cases is a weird thing to do.
Why not if (errorCode==..) { errorCode = . | |||||
I'd just get rid of the assignment TBH. The line below is the last place errorCode is used anyway, so the ternary could just move there. sitter: I'd just get rid of the assignment TBH. The line below is the last place errorCode is used… | |||||
1498 | closeWithoutFinish(); | ||||
1499 | } | ||||
1500 | } | ||||
1473 | 1501 | | |||
1474 | void sftpProtocol::close() { | 1502 | void sftpProtocol::close() { | ||
1475 | closeWithoutFinish(); | 1503 | closeWithoutFinish(); | ||
1476 | finished(); | 1504 | finished(); | ||
1477 | } | 1505 | } | ||
1478 | 1506 | | |||
1479 | void sftpProtocol::get(const QUrl& url) { | 1507 | void sftpProtocol::get(const QUrl& url) { | ||
1480 | qCDebug(KIO_SFTP_LOG) << url; | 1508 | qCDebug(KIO_SFTP_LOG) << url; | ||
▲ Show 20 Lines • Show All 1187 Lines • Show Last 20 Lines |
[minor: qDebug already appends spaces between arguments, so you get two here after the '=']