diff options
author | Tobias Markmann <tm@ayena.de> | 2016-02-10 19:25:21 (GMT) |
---|---|---|
committer | Kevin Smith <kevin.smith@isode.com> | 2016-02-15 12:31:10 (GMT) |
commit | ca226e7bb019308db4bfc818d7e04422d9d28106 (patch) | |
tree | 9f7ef065f20db3e04eb08560674eed16d10e95e5 /Swiften/FileTransfer/FileWriteBytestream.cpp | |
parent | 431eb62386101dc8fc1e7d346c49bd0d81fda70e (diff) | |
download | swift-ca226e7bb019308db4bfc818d7e04422d9d28106.zip swift-ca226e7bb019308db4bfc818d7e04422d9d28106.tar.bz2 |
Fix crash when saving a received file to non-writable location
WriteBytestream::write(…) now returns a boolean indicating
its success state (false in case of an error). Adjusted
FileWriteBytestream accordingly.
The QtWebKitChatView will test if the file path selected by
the user is writable before accepting it and starting the
transfer. If it is not writable a red warning message will be
added to the file-transfer element in the chat view.
Test-Information:
Added an integration test that tests the new behavior for
the FileWriteBytestream class.
Tested two file transfers on OS X 10.11.3, one to a write
protected location and another to /tmp. The first is not accepted
by the UI, and without the UI sanity check it results in a
file-transfer error. The second succeeds as expected.
Change-Id: I5aa0c617423073feb371365a23a294c149c88036
Diffstat (limited to 'Swiften/FileTransfer/FileWriteBytestream.cpp')
-rw-r--r-- | Swiften/FileTransfer/FileWriteBytestream.cpp | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/Swiften/FileTransfer/FileWriteBytestream.cpp b/Swiften/FileTransfer/FileWriteBytestream.cpp index bbf3d51..c39d63a 100644 --- a/Swiften/FileTransfer/FileWriteBytestream.cpp +++ b/Swiften/FileTransfer/FileWriteBytestream.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2015 Isode Limited. + * Copyright (c) 2010-2016 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -24,16 +24,21 @@ FileWriteBytestream::~FileWriteBytestream() { } } -void FileWriteBytestream::write(const std::vector<unsigned char>& data) { +bool FileWriteBytestream::write(const std::vector<unsigned char>& data) { if (data.empty()) { - return; + return true; } if (!stream) { stream = new boost::filesystem::ofstream(file, std::ios_base::out|std::ios_base::binary); } - assert(stream->good()); - stream->write(reinterpret_cast<const char*>(&data[0]), boost::numeric_cast<std::streamsize>(data.size())); - onWrite(data); + if (stream->good()) { + stream->write(reinterpret_cast<const char*>(&data[0]), boost::numeric_cast<std::streamsize>(data.size())); + if (stream->good()) { + onWrite(data); + return true; + } + } + return false; } void FileWriteBytestream::close() { |