Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-12-SP2:GA
kdump.2364
kdump-sftp-data-transfer.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File kdump-sftp-data-transfer.patch of Package kdump.2364
From: Petr Tesarik <ptesarik@suse.cz> Date: Wed, 15 Apr 2015 12:22:49 +0200 Subject: Implement file data transfer over SFTP References: FATE#318874, bsc#917747 Patch-mainline: v0.8.16 Git-commit: d9c2ad963e8a968076f002ef6745b706093ac7c3 This commit implements the actual write into the file. Signed-off-by: Petr Tesarik <ptesarik@suse.cz> --- kdumptool/sshtransfer.cc | 50 +++++++++++++++++++++++++++++++++++++++++++++++ kdumptool/sshtransfer.h | 3 ++ 2 files changed, 53 insertions(+) --- a/kdumptool/sshtransfer.cc +++ b/kdumptool/sshtransfer.cc @@ -424,6 +424,28 @@ void SFTPTransfer::perform(DataProvider string handle = createfile(fp); try { + dataprovider->prepare(); + ByteVector buffer(BUFSIZ); + off_t off = 0; + try { + while (true) { + char *bufp = (char*) buffer.data(); + size_t len = dataprovider->getData(bufp, buffer.size()); + + // finished? + if (len == 0) + break; + + buffer.resize(len); + writefile(handle, off, buffer); + off += buffer.size(); + buffer.resize(buffer.capacity()); + } + } catch (...) { + dataprovider->finish(); + throw; + } + dataprovider->finish(); } catch (...) { closefile(handle); throw; @@ -552,6 +574,34 @@ void SFTPTransfer::closefile(const std:: Stringutil::number2string(unsigned(type))); unsigned long errcode = pkt.getInt32(); + if (errcode != SSH_FX_OK) + throw KSFTPError("close failed on " + handle, errcode); +} + +/* -------------------------------------------------------------------------- */ +void SFTPTransfer::writefile(const std::string &handle, off_t off, + const ByteVector &data) +{ + SFTPPacket pkt; + pkt.addByte(SSH_FXP_WRITE); + pkt.addInt32(nextId()); + pkt.addString(handle); + pkt.addInt64(off); + pkt.addInt32(data.size()); + pkt.addByteVector(data); + sendPacket(pkt); + + recvPacket(pkt); + unsigned char type = pkt.getByte(); + unsigned long id = pkt.getInt32(); + if (id != m_lastid) + throw KError("SFTP request/reply id mismatch"); + + if (type != SSH_FXP_STATUS) + throw KError("Invalid response to SSH_FXP_WRITE: type " + + Stringutil::number2string(unsigned(type))); + + unsigned long errcode = pkt.getInt32(); if (errcode != SSH_FX_OK) throw KSFTPError("close failed on " + handle, errcode); } --- a/kdumptool/sshtransfer.h +++ b/kdumptool/sshtransfer.h @@ -124,6 +124,7 @@ enum { SSH_FXP_VERSION = 2, SSH_FXP_OPEN = 3, SSH_FXP_CLOSE = 4, + SSH_FXP_WRITE = 6, SSH_FXP_MKDIR = 14, SSH_FXP_STAT = 17, SSH_FXP_STATUS = 101, @@ -230,6 +231,8 @@ class SFTPTransfer : public URLTransfer void mkpath(const std::string &path); std::string createfile(const std::string &file); void closefile(const std::string &handle); + void writefile(const std::string &handle, off_t off, + const ByteVector &data); private: SubProcess m_process;
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor