Changeset View
Changeset View
Standalone View
Standalone View
src/ioslaves/file/file_unix.cpp
Show All 25 Lines | |||||
26 | #include "file.h" | 26 | #include "file.h" | ||
27 | 27 | | |||
28 | #include <config-kioslave-file.h> | 28 | #include <config-kioslave-file.h> | ||
29 | 29 | | |||
30 | #include <QFile> | 30 | #include <QFile> | ||
31 | #include <QDir> | 31 | #include <QDir> | ||
32 | #include <qplatformdefs.h> | 32 | #include <qplatformdefs.h> | ||
33 | #include <QStandardPaths> | 33 | #include <QStandardPaths> | ||
34 | #include <QThread> | ||||
34 | 35 | | |||
35 | #include <QDebug> | 36 | #include <QDebug> | ||
36 | #include <kconfiggroup.h> | 37 | #include <kconfiggroup.h> | ||
37 | #include <klocalizedstring.h> | 38 | #include <klocalizedstring.h> | ||
38 | #include <kmountpoint.h> | 39 | #include <kmountpoint.h> | ||
39 | 40 | | |||
40 | #include <errno.h> | 41 | #include <errno.h> | ||
41 | #if HAVE_SYS_XATTR_H | 42 | #if HAVE_SYS_XATTR_H | ||
▲ Show 20 Lines • Show All 264 Lines • ▼ Show 20 Line(s) | 305 | #endif | |||
306 | 307 | | |||
307 | KIO::filesize_t processed_size = 0; | 308 | KIO::filesize_t processed_size = 0; | ||
308 | char buffer[ MAX_IPC_SIZE ]; | 309 | char buffer[ MAX_IPC_SIZE ]; | ||
309 | ssize_t n = 0; | 310 | ssize_t n = 0; | ||
310 | #ifdef USE_SENDFILE | 311 | #ifdef USE_SENDFILE | ||
311 | bool use_sendfile = buff_src.st_size < 0x7FFFFFFF; | 312 | bool use_sendfile = buff_src.st_size < 0x7FFFFFFF; | ||
312 | #endif | 313 | #endif | ||
313 | bool existing_dest_delete_attempted = false; | 314 | bool existing_dest_delete_attempted = false; | ||
314 | while (1) { | 315 | while (!wasKilled()) { | ||
316 | | ||||
317 | if (testMode && dest_file.fileName().contains(QLatin1String("slow"))) { | ||||
dfaure: Maybe in testMode, the slave can become particularly slow for one given filename.
E.g. if… | |||||
318 | QThread::usleep(500); | ||||
319 | } | ||||
320 | | ||||
315 | #ifdef USE_SENDFILE | 321 | #ifdef USE_SENDFILE | ||
316 | if (use_sendfile) { | 322 | if (use_sendfile) { | ||
317 | off_t sf = processed_size; | 323 | off_t sf = processed_size; | ||
318 | n = ::sendfile(dest_file.handle(), src_file.handle(), &sf, MAX_IPC_SIZE); | 324 | n = ::sendfile(dest_file.handle(), src_file.handle(), &sf, MAX_IPC_SIZE); | ||
319 | processed_size = sf; | 325 | processed_size = sf; | ||
320 | if (n == -1 && (errno == EINVAL || errno == ENOSYS)) { //not all filesystems support sendfile() | 326 | if (n == -1 && (errno == EINVAL || errno == ENOSYS)) { //not all filesystems support sendfile() | ||
321 | // qDebug() << "sendfile() not supported, falling back "; | 327 | // qDebug() << "sendfile() not supported, falling back "; | ||
322 | use_sendfile = false; | 328 | use_sendfile = false; | ||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Line(s) | 398 | #ifdef USE_SENDFILE | |||
393 | } | 399 | } | ||
394 | #endif | 400 | #endif | ||
395 | processedSize(processed_size); | 401 | processedSize(processed_size); | ||
396 | } | 402 | } | ||
397 | 403 | | |||
398 | src_file.close(); | 404 | src_file.close(); | ||
399 | dest_file.close(); | 405 | dest_file.close(); | ||
400 | 406 | | |||
407 | if (wasKilled()) { | ||||
408 | qCDebug(KIO_FILE) << "Clean dest file after ioslave was killed:" << dest; | ||||
409 | if (!QFile::remove(dest)) { // don't keep partly copied file | ||||
410 | execWithElevatedPrivilege(DEL, {_dest}, errno); | ||||
411 | } | ||||
412 | error(KIO::ERR_USER_CANCELED, dest); | ||||
shouldn't this be error(KIO::ERR_USER_CANCELED) instead? It's not like the copy actually succeeded... dfaure: shouldn't this be error(KIO::ERR_USER_CANCELED) instead? It's not like the copy actually… | |||||
413 | return; | ||||
414 | } | ||||
415 | | ||||
401 | if (dest_file.error() != QFile::NoError) { | 416 | if (dest_file.error() != QFile::NoError) { | ||
402 | qCWarning(KIO_FILE) << "Error when closing file descriptor[2]:" << dest_file.errorString(); | 417 | qCWarning(KIO_FILE) << "Error when closing file descriptor[2]:" << dest_file.errorString(); | ||
403 | error(KIO::ERR_CANNOT_WRITE, dest); | 418 | error(KIO::ERR_CANNOT_WRITE, dest); | ||
404 | #if HAVE_POSIX_ACL | 419 | #if HAVE_POSIX_ACL | ||
405 | if (acl) { | 420 | if (acl) { | ||
406 | acl_free(acl); | 421 | acl_free(acl); | ||
407 | } | 422 | } | ||
408 | #endif | 423 | #endif | ||
▲ Show 20 Lines • Show All 569 Lines • Show Last 20 Lines |
Maybe in testMode, the slave can become particularly slow for one given filename.
E.g. if (testMode && fileName.contains("slow"))
This way, for other files, it remains fast, and for that one file it can be really reliably slow (possibly sleeping for a whole second, or something like that).
It also makes the more generically named "KIOSLAVE_FILE_ENABLE_TESTMODE" available for enabling other kinds of "test mode" in the ioslave (the filename acting as an additional switch).