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