Changeset View
Changeset View
Standalone View
Standalone View
src/ioslaves/file/file_unix.cpp
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | |||||
42 | #include <sys/xattr.h> | 42 | #include <sys/xattr.h> | ||
43 | #endif | 43 | #endif | ||
44 | #include <utime.h> | 44 | #include <utime.h> | ||
45 | 45 | | |||
46 | #include <KAuth> | 46 | #include <KAuth> | ||
47 | #include <KRandom> | 47 | #include <KRandom> | ||
48 | 48 | | |||
49 | #include "fdreceiver.h" | 49 | #include "fdreceiver.h" | ||
50 | #include "statjob.h" | ||||
50 | 51 | | |||
51 | //sendfile has different semantics in different platforms | 52 | //sendfile has different semantics in different platforms | ||
52 | #if HAVE_SENDFILE && defined Q_OS_LINUX | 53 | #if HAVE_SENDFILE && defined Q_OS_LINUX | ||
53 | #define USE_SENDFILE 1 | 54 | #define USE_SENDFILE 1 | ||
54 | #endif | 55 | #endif | ||
55 | 56 | | |||
56 | #ifdef USE_SENDFILE | 57 | #ifdef USE_SENDFILE | ||
57 | #include <sys/sendfile.h> | 58 | #include <sys/sendfile.h> | ||
▲ Show 20 Lines • Show All 476 Lines • ▼ Show 20 Line(s) | 520 | #endif | |||
534 | const QString pathBuffer(QDir::currentPath()); | 535 | const QString pathBuffer(QDir::currentPath()); | ||
535 | if (!QDir::setCurrent(path)) { | 536 | if (!QDir::setCurrent(path)) { | ||
536 | closedir(dp); | 537 | closedir(dp); | ||
537 | error(ERR_CANNOT_ENTER_DIRECTORY, path); | 538 | error(ERR_CANNOT_ENTER_DIRECTORY, path); | ||
538 | return; | 539 | return; | ||
539 | } | 540 | } | ||
540 | 541 | | |||
541 | const QString sDetails = metaData(QStringLiteral("details")); | 542 | const QString sDetails = metaData(QStringLiteral("details")); | ||
542 | const int details = sDetails.isEmpty() ? 2 : sDetails.toInt(); | 543 | const KIO::StatJob::StatDetails details = sDetails.isEmpty() ? KIO::StatJob::StatDefaultDetails : static_cast<KIO::StatJob::StatDetails>(sDetails.toInt()); | ||
dfaure: file_win.cpp needs to be ported the same way. | |||||
543 | //qDebug() << "========= LIST " << url << "details=" << details << " ========="; | 544 | //qDebug() << "========= LIST " << url << "details=" << details << " ========="; | ||
544 | UDSEntry entry; | 545 | UDSEntry entry; | ||
545 | 546 | | |||
546 | #ifndef HAVE_DIRENT_D_TYPE | 547 | #ifndef HAVE_DIRENT_D_TYPE | ||
547 | QT_STATBUF st; | 548 | QT_STATBUF st; | ||
548 | #endif | 549 | #endif | ||
549 | QT_DIRENT *ep; | 550 | QT_DIRENT *ep; | ||
550 | while ((ep = QT_READDIR(dp)) != nullptr) { | 551 | while ((ep = QT_READDIR(dp)) != nullptr) { | ||
551 | entry.clear(); | 552 | entry.clear(); | ||
552 | 553 | | |||
553 | const QString filename = QFile::decodeName(ep->d_name); | 554 | const QString filename = QFile::decodeName(ep->d_name); | ||
554 | 555 | | |||
555 | /* | 556 | /* | ||
556 | * details == 0 (if statement) is the fast code path. | 557 | * details == 0 (if statement) is the fast code path. | ||
557 | * We only get the file name and type. After that we emit | 558 | * We only get the file name and type. After that we emit | ||
558 | * the result. | 559 | * the result. | ||
559 | * | 560 | * | ||
560 | * The else statement is the slow path that requests all | 561 | * The else statement is the slow path that requests all | ||
561 | * file information in file.cpp. It executes a stat call | 562 | * file information in file.cpp. It executes a stat call | ||
562 | * for every entry thus becoming slower. | 563 | * for every entry thus becoming slower. | ||
563 | * | 564 | * | ||
564 | */ | 565 | */ | ||
565 | if (details == 0) { | 566 | if (details == KIO::StatJob::Basic) { | ||
566 | entry.fastInsert(KIO::UDSEntry::UDS_NAME, filename); | 567 | entry.fastInsert(KIO::UDSEntry::UDS_NAME, filename); | ||
567 | #ifdef HAVE_DIRENT_D_TYPE | 568 | #ifdef HAVE_DIRENT_D_TYPE | ||
568 | entry.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, | 569 | entry.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, | ||
569 | (ep->d_type == DT_DIR) ? S_IFDIR : S_IFREG); | 570 | (ep->d_type == DT_DIR) ? S_IFDIR : S_IFREG); | ||
570 | const bool isSymLink = (ep->d_type == DT_LNK); | 571 | const bool isSymLink = (ep->d_type == DT_LNK); | ||
571 | #else | 572 | #else | ||
572 | // oops, no fast way, we need to stat (e.g. on Solaris) | 573 | // oops, no fast way, we need to stat (e.g. on Solaris) | ||
573 | if (QT_LSTAT(ep->d_name, &st) == -1) { | 574 | if (QT_LSTAT(ep->d_name, &st) == -1) { | ||
▲ Show 20 Lines • Show All 248 Lines • ▼ Show 20 Line(s) | 812 | if (!err.wasCanceled()) { | |||
822 | } | 823 | } | ||
823 | } | 824 | } | ||
824 | } | 825 | } | ||
825 | } else { | 826 | } else { | ||
826 | finished(); | 827 | finished(); | ||
827 | } | 828 | } | ||
828 | } | 829 | } | ||
829 | 830 | | |||
830 | void FileProtocol::stat(const QUrl &url) | 831 | void FileProtocol::stat(const QUrl &url) | ||
This should go to file.cpp so that it's available on Windows too, it's not Unix specific. OK, right now it's not really implemented on Windows, but let's make it easy for the future developer who will implement it ;) dfaure: This should go to file.cpp so that it's available on Windows too, it's not Unix specific.
OK… | |||||
831 | { | 832 | { | ||
832 | if (!isLocalFileSameHost(url)) { | 833 | if (!isLocalFileSameHost(url)) { | ||
833 | redirect(url); | 834 | redirect(url); | ||
834 | return; | 835 | return; | ||
835 | } | 836 | } | ||
836 | 837 | | |||
837 | /* directories may not have a slash at the end if | 838 | /* directories may not have a slash at the end if | ||
838 | * we want to stat() them; it requires that we | 839 | * we want to stat() them; it requires that we | ||
839 | * change into it .. which may not be allowed | 840 | * change into it .. which may not be allowed | ||
840 | * stat("/is/unaccessible") -> rwx------ | 841 | * stat("/is/unaccessible") -> rwx------ | ||
841 | * stat("/is/unaccessible/") -> EPERM H.Z. | 842 | * stat("/is/unaccessible/") -> EPERM H.Z. | ||
842 | * This is the reason for the -1 | 843 | * This is the reason for the -1 | ||
843 | */ | 844 | */ | ||
844 | const QString path(url.adjusted(QUrl::StripTrailingSlash).toLocalFile()); | 845 | const QString path(url.adjusted(QUrl::StripTrailingSlash).toLocalFile()); | ||
845 | const QByteArray _path(QFile::encodeName(path)); | 846 | const QByteArray _path(QFile::encodeName(path)); | ||
846 | const QString sDetails = metaData(QStringLiteral("details")); | 847 | const QString sDetails = metaData(QStringLiteral("details")); | ||
847 | const int details = sDetails.isEmpty() ? 2 : sDetails.toInt(); | 848 | const KIO::StatJob::StatDetails details = sDetails.isEmpty() ? KIO::StatJob::StatDefaultDetails : static_cast<KIO::StatJob::StatDetails>(sDetails.toInt()); | ||
848 | 849 | | |||
849 | UDSEntry entry; | 850 | UDSEntry entry; | ||
850 | if (!createUDSEntry(url.fileName(), _path, entry, details)) { | 851 | if (!createUDSEntry(url.fileName(), _path, entry, details)) { | ||
851 | error(KIO::ERR_DOES_NOT_EXIST, path); | 852 | error(KIO::ERR_DOES_NOT_EXIST, path); | ||
852 | return; | 853 | return; | ||
853 | } | 854 | } | ||
854 | #if 0 | 855 | #if 0 | ||
855 | ///////// debug code | 856 | ///////// debug code | ||
▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines |
file_win.cpp needs to be ported the same way.