Changeset View
Changeset View
Standalone View
Standalone View
smb/kio_smb_file.cpp
Show First 20 Lines • Show All 214 Lines • ▼ Show 20 Line(s) | 142 | { | |||
---|---|---|---|---|---|
215 | if (mode & QIODevice::ReadOnly){ | 215 | if (mode & QIODevice::ReadOnly){ | ||
216 | ssize_t bytesRequested = 1024; | 216 | ssize_t bytesRequested = 1024; | ||
217 | ssize_t bytesRead = 0; | 217 | ssize_t bytesRead = 0; | ||
218 | QVarLengthArray<char> buffer(bytesRequested); | 218 | QVarLengthArray<char> buffer(bytesRequested); | ||
219 | bytesRead = smbc_read(m_openFd, buffer.data(), bytesRequested); | 219 | bytesRead = smbc_read(m_openFd, buffer.data(), bytesRequested); | ||
220 | if(bytesRead < 0) | 220 | if(bytesRead < 0) | ||
221 | { | 221 | { | ||
222 | error( KIO::ERR_COULD_NOT_READ, m_openUrl.toDisplayString()); | 222 | error( KIO::ERR_COULD_NOT_READ, m_openUrl.toDisplayString()); | ||
223 | close(); | 223 | closeWithoutFinish(); | ||
224 | return; | 224 | return; | ||
225 | } | 225 | } | ||
226 | else | 226 | else | ||
227 | { | 227 | { | ||
228 | QByteArray fileData = QByteArray::fromRawData(buffer.data(),bytesRead); | 228 | QByteArray fileData = QByteArray::fromRawData(buffer.data(),bytesRead); | ||
229 | QMimeDatabase db; | 229 | QMimeDatabase db; | ||
230 | QMimeType type = db.mimeTypeForFileNameAndData(m_openUrl.fileName(), fileData); | 230 | QMimeType type = db.mimeTypeForFileNameAndData(m_openUrl.fileName(), fileData); | ||
231 | mimeType(type.name()); | 231 | mimeType(type.name()); | ||
232 | 232 | | |||
233 | off_t res = smbc_lseek(m_openFd, 0, SEEK_SET); | 233 | off_t res = smbc_lseek(m_openFd, 0, SEEK_SET); | ||
234 | if (res == (off_t)-1) { | 234 | if (res == (off_t)-1) { | ||
235 | error(KIO::ERR_COULD_NOT_SEEK, m_openUrl.path()); | 235 | error(KIO::ERR_COULD_NOT_SEEK, m_openUrl.path()); | ||
236 | close(); | 236 | closeWithoutFinish(); | ||
237 | return; | 237 | return; | ||
238 | } | 238 | } | ||
239 | } | 239 | } | ||
240 | } | 240 | } | ||
241 | 241 | | |||
242 | position( 0 ); | 242 | position( 0 ); | ||
243 | emit opened(); | 243 | emit opened(); | ||
244 | } | 244 | } | ||
245 | 245 | | |||
246 | 246 | | |||
247 | void SMBSlave::read( KIO::filesize_t bytesRequested ) | 247 | void SMBSlave::read( KIO::filesize_t bytesRequested ) | ||
248 | { | 248 | { | ||
249 | Q_ASSERT(m_openFd != -1); | 249 | Q_ASSERT(m_openFd != -1); | ||
250 | 250 | | |||
251 | QVarLengthArray<char> buffer(bytesRequested); | 251 | QVarLengthArray<char> buffer(bytesRequested); | ||
252 | ssize_t bytesRead = 0; | 252 | ssize_t bytesRead = 0; | ||
253 | 253 | | |||
254 | bytesRead = smbc_read(m_openFd, buffer.data(), bytesRequested); | 254 | bytesRead = smbc_read(m_openFd, buffer.data(), bytesRequested); | ||
255 | Q_ASSERT(bytesRead <= static_cast<ssize_t>(bytesRequested)); | 255 | Q_ASSERT(bytesRead <= static_cast<ssize_t>(bytesRequested)); | ||
256 | 256 | | |||
257 | if(bytesRead < 0) | 257 | if(bytesRead < 0) | ||
258 | { | 258 | { | ||
259 | qCDebug(KIO_SMB) << "Could not read " << m_openUrl; | 259 | qCDebug(KIO_SMB) << "Could not read " << m_openUrl; | ||
260 | error( KIO::ERR_COULD_NOT_READ, m_openUrl.toDisplayString()); | 260 | error( KIO::ERR_COULD_NOT_READ, m_openUrl.toDisplayString()); | ||
261 | close(); | 261 | closeWithoutFinish(); | ||
262 | return; | 262 | return; | ||
263 | } | 263 | } | ||
264 | 264 | | |||
265 | QByteArray fileData = QByteArray::fromRawData(buffer.data(), bytesRead); | 265 | QByteArray fileData = QByteArray::fromRawData(buffer.data(), bytesRead); | ||
266 | data( fileData ); | 266 | data( fileData ); | ||
267 | } | 267 | } | ||
268 | 268 | | |||
269 | 269 | | |||
270 | void SMBSlave::write(const QByteArray &fileData) | 270 | void SMBSlave::write(const QByteArray &fileData) | ||
271 | { | 271 | { | ||
272 | Q_ASSERT(m_openFd != -1); | 272 | Q_ASSERT(m_openFd != -1); | ||
273 | 273 | | |||
274 | QByteArray buf(fileData); | 274 | QByteArray buf(fileData); | ||
275 | 275 | | |||
276 | ssize_t size = smbc_write(m_openFd, buf.data(), buf.size()); | 276 | ssize_t size = smbc_write(m_openFd, buf.data(), buf.size()); | ||
277 | if (size < 0) | 277 | if (size < 0) | ||
278 | { | 278 | { | ||
279 | qCDebug(KIO_SMB) << "Could not write to " << m_openUrl; | 279 | qCDebug(KIO_SMB) << "Could not write to " << m_openUrl; | ||
280 | error( KIO::ERR_COULD_NOT_WRITE, m_openUrl.toDisplayString()); | 280 | error( KIO::ERR_COULD_NOT_WRITE, m_openUrl.toDisplayString()); | ||
281 | close(); | 281 | closeWithoutFinish(); | ||
282 | return; | 282 | return; | ||
283 | } | 283 | } | ||
284 | 284 | | |||
285 | written(size); | 285 | written(size); | ||
286 | } | 286 | } | ||
287 | 287 | | |||
288 | void SMBSlave::seek(KIO::filesize_t offset) | 288 | void SMBSlave::seek(KIO::filesize_t offset) | ||
289 | { | 289 | { | ||
290 | off_t res = smbc_lseek(m_openFd, static_cast<off_t>(offset), SEEK_SET); | 290 | off_t res = smbc_lseek(m_openFd, static_cast<off_t>(offset), SEEK_SET); | ||
291 | if (res == (off_t)-1) { | 291 | if (res == (off_t)-1) { | ||
292 | error(KIO::ERR_COULD_NOT_SEEK, m_openUrl.path()); | 292 | error(KIO::ERR_COULD_NOT_SEEK, m_openUrl.path()); | ||
293 | close(); | 293 | closeWithoutFinish(); | ||
294 | } else { | 294 | } else { | ||
295 | qCDebug( KIO_SMB ) << "res" << res; | 295 | qCDebug( KIO_SMB ) << "res" << res; | ||
296 | position( res ); | 296 | position( res ); | ||
297 | } | 297 | } | ||
298 | } | 298 | } | ||
299 | 299 | | |||
300 | void SMBSlave::close() | 300 | void SMBSlave::closeWithoutFinish() | ||
301 | { | 301 | { | ||
302 | smbc_close(m_openFd); | 302 | smbc_close(m_openFd); | ||
303 | } | ||||
304 | | ||||
305 | void SMBSlave::close() | ||||
306 | { | ||||
307 | closeWithoutFinish(); | ||||
303 | finished(); | 308 | finished(); | ||
304 | } | 309 | } | ||
305 | 310 | | |||
306 | //=========================================================================== | 311 | //=========================================================================== | ||
307 | void SMBSlave::put( const QUrl& kurl, | 312 | void SMBSlave::put( const QUrl& kurl, | ||
308 | int permissions, | 313 | int permissions, | ||
309 | KIO::JobFlags flags ) | 314 | KIO::JobFlags flags ) | ||
310 | { | 315 | { | ||
▲ Show 20 Lines • Show All 155 Lines • Show Last 20 Lines |