Changeset View
Changeset View
Standalone View
Standalone View
sftp/kio_sftp.cpp
Show First 20 Lines • Show All 1412 Lines • ▼ Show 20 Line(s) | 1326 | void sftpProtocol::open(const QUrl &url, QIODevice::OpenMode mode) { | |||
---|---|---|---|---|---|
1413 | } | 1413 | } | ||
1414 | 1414 | | |||
1415 | mOpenUrl = url; | 1415 | mOpenUrl = url; | ||
1416 | 1416 | | |||
1417 | openOffset = 0; | 1417 | openOffset = 0; | ||
1418 | totalSize(fileSize); | 1418 | totalSize(fileSize); | ||
1419 | position(0); | 1419 | position(0); | ||
1420 | opened(); | 1420 | opened(); | ||
1421 | finished(); | | |||
1422 | } | 1421 | } | ||
1423 | 1422 | | |||
1424 | void sftpProtocol::read(KIO::filesize_t bytes) { | 1423 | void sftpProtocol::read(KIO::filesize_t bytes) { | ||
1425 | qCDebug(KIO_SFTP_LOG) << "read, offset = " << openOffset << ", bytes = " << bytes; | 1424 | qCDebug(KIO_SFTP_LOG) << "read, offset = " << openOffset << ", bytes = " << bytes; | ||
1426 | 1425 | | |||
1427 | Q_ASSERT(mOpenFile != nullptr); | 1426 | Q_ASSERT(mOpenFile != nullptr); | ||
1428 | 1427 | | |||
1429 | QVarLengthArray<char> buffer(bytes); | 1428 | QVarLengthArray<char> buffer(bytes); | ||
1430 | 1429 | | |||
1431 | ssize_t bytesRead = sftp_read(mOpenFile, buffer.data(), bytes); | 1430 | ssize_t bytesRead = sftp_read(mOpenFile, buffer.data(), bytes); | ||
1432 | Q_ASSERT(bytesRead <= static_cast<ssize_t>(bytes)); | 1431 | Q_ASSERT(bytesRead <= static_cast<ssize_t>(bytes)); | ||
1433 | 1432 | | |||
1434 | if (bytesRead < 0) { | 1433 | if (bytesRead < 0) { | ||
1435 | qCDebug(KIO_SFTP_LOG) << "Could not read " << mOpenUrl; | 1434 | qCDebug(KIO_SFTP_LOG) << "Could not read " << mOpenUrl; | ||
1436 | error(KIO::ERR_COULD_NOT_READ, mOpenUrl.toDisplayString()); | 1435 | error(KIO::ERR_COULD_NOT_READ, mOpenUrl.toDisplayString()); | ||
1437 | closeWithoutFinish(); | 1436 | closeWithoutFinish(); | ||
1438 | return; | 1437 | return; | ||
1439 | } | 1438 | } | ||
1440 | 1439 | | |||
1441 | const QByteArray fileData = QByteArray::fromRawData(buffer.data(), bytesRead); | 1440 | const QByteArray fileData = QByteArray::fromRawData(buffer.data(), bytesRead); | ||
1442 | data(fileData); | 1441 | data(fileData); | ||
1443 | finished(); | | |||
1444 | } | 1442 | } | ||
1445 | 1443 | | |||
1446 | void sftpProtocol::write(const QByteArray &data) { | 1444 | void sftpProtocol::write(const QByteArray &data) { | ||
1447 | qCDebug(KIO_SFTP_LOG) << "write, offset = " << openOffset << ", bytes = " << data.size(); | 1445 | qCDebug(KIO_SFTP_LOG) << "write, offset = " << openOffset << ", bytes = " << data.size(); | ||
1448 | 1446 | | |||
1449 | Q_ASSERT(mOpenFile != nullptr); | 1447 | Q_ASSERT(mOpenFile != nullptr); | ||
1450 | 1448 | | |||
1451 | ssize_t bytesWritten = sftp_write(mOpenFile, data.data(), data.size()); | 1449 | ssize_t bytesWritten = sftp_write(mOpenFile, data.data(), data.size()); | ||
1452 | if (bytesWritten < 0) { | 1450 | if (bytesWritten < 0) { | ||
1453 | qCDebug(KIO_SFTP_LOG) << "Could not write to " << mOpenUrl; | 1451 | qCDebug(KIO_SFTP_LOG) << "Could not write to " << mOpenUrl; | ||
1454 | error(KIO::ERR_COULD_NOT_WRITE, mOpenUrl.toDisplayString()); | 1452 | error(KIO::ERR_COULD_NOT_WRITE, mOpenUrl.toDisplayString()); | ||
1455 | closeWithoutFinish(); | 1453 | closeWithoutFinish(); | ||
1456 | return; | 1454 | return; | ||
1457 | } | 1455 | } | ||
1458 | 1456 | | |||
1459 | written(bytesWritten); | 1457 | written(bytesWritten); | ||
1460 | finished(); | | |||
1461 | } | 1458 | } | ||
1462 | 1459 | | |||
1463 | void sftpProtocol::seek(KIO::filesize_t offset) { | 1460 | void sftpProtocol::seek(KIO::filesize_t offset) { | ||
1464 | qCDebug(KIO_SFTP_LOG) << "seek, offset = " << offset; | 1461 | qCDebug(KIO_SFTP_LOG) << "seek, offset = " << offset; | ||
1465 | 1462 | | |||
1466 | Q_ASSERT(mOpenFile != nullptr); | 1463 | Q_ASSERT(mOpenFile != nullptr); | ||
1467 | 1464 | | |||
1468 | if (sftp_seek64(mOpenFile, static_cast<uint64_t>(offset)) < 0) { | 1465 | if (sftp_seek64(mOpenFile, static_cast<uint64_t>(offset)) < 0) { | ||
1469 | error(KIO::ERR_COULD_NOT_SEEK, mOpenUrl.path()); | 1466 | error(KIO::ERR_COULD_NOT_SEEK, mOpenUrl.path()); | ||
1470 | closeWithoutFinish(); | 1467 | closeWithoutFinish(); | ||
1471 | return; | 1468 | return; | ||
1472 | } | 1469 | } | ||
1473 | 1470 | | |||
1474 | position(sftp_tell64(mOpenFile)); | 1471 | position(sftp_tell64(mOpenFile)); | ||
1475 | finished(); | | |||
1476 | } | 1472 | } | ||
1477 | 1473 | | |||
1478 | void sftpProtocol::close() { | 1474 | void sftpProtocol::close() { | ||
1479 | closeWithoutFinish(); | 1475 | closeWithoutFinish(); | ||
1480 | finished(); | 1476 | finished(); | ||
1481 | } | 1477 | } | ||
1482 | 1478 | | |||
1483 | void sftpProtocol::get(const QUrl& url) { | 1479 | void sftpProtocol::get(const QUrl& url) { | ||
▲ Show 20 Lines • Show All 1188 Lines • Show Last 20 Lines |