diff --git a/autotests/jobtest.h b/autotests/jobtest.h --- a/autotests/jobtest.h +++ b/autotests/jobtest.h @@ -85,6 +85,7 @@ void stat(); void statDetailsBasic(); void statDetailsBasicSetDetails(); + void statWithInode(); #ifndef Q_OS_WIN void statSymlink(); #endif diff --git a/autotests/jobtest.cpp b/autotests/jobtest.cpp --- a/autotests/jobtest.cpp +++ b/autotests/jobtest.cpp @@ -1505,6 +1505,46 @@ QCOMPARE(kioItem.time(KFileItem::AccessTime), QDateTime()); } +void JobTest::statWithInode() +{ + const QString filePath = homeTmpDir() + "fileFromHome"; + createTestFile(filePath); + const QUrl url(QUrl::fromLocalFile(filePath)); + KIO::StatJob *job = KIO::statDetails(url, KIO::StatJob::SourceSide, KIO::StatInode); + QVERIFY(job); + QVERIFY2(job->exec(), qPrintable(job->errorString())); + + const KIO::UDSEntry &entry = job->statResult(); + QVERIFY(entry.contains(KIO::UDSEntry::UDS_DEVICE_ID)); + QVERIFY(entry.contains(KIO::UDSEntry::UDS_INODE)); + QCOMPARE(entry.count(), 2); + + const QString path = otherTmpDir() + "otherFile"; + createTestFile(path); + const QUrl otherUrl(QUrl::fromLocalFile(path)); + KIO::StatJob *otherJob = KIO::statDetails(otherUrl, KIO::StatJob::SourceSide, KIO::StatInode); + QVERIFY(otherJob); + QVERIFY2(otherJob->exec(), qPrintable(otherJob->errorString())); + + const KIO::UDSEntry otherEntry = otherJob->statResult(); + QVERIFY(otherEntry.contains(KIO::UDSEntry::UDS_DEVICE_ID)); + QVERIFY(otherEntry.contains(KIO::UDSEntry::UDS_INODE)); + QCOMPARE(otherEntry.count(), 2); + + const int device = entry.numberValue(KIO::UDSEntry::UDS_DEVICE_ID); + const int otherDevice = otherEntry.numberValue(KIO::UDSEntry::UDS_DEVICE_ID); + + // this test doesn't make sense on the CI as it's an LXC container with one partition + if (otherTmpDirIsOnSamePartition()) { + // On the CI where the two tmp dirs are on the only parition available + // in the LXC container, the device ID's would be identical + QCOMPARE(device, otherDevice); + } + else { + QVERIFY(device != otherDevice); + } +} + #ifndef Q_OS_WIN void JobTest::statSymlink() { diff --git a/src/ioslaves/file/file_unix.cpp b/src/ioslaves/file/file_unix.cpp --- a/src/ioslaves/file/file_unix.cpp +++ b/src/ioslaves/file/file_unix.cpp @@ -53,6 +53,7 @@ #if HAVE_STATX #include +#include // for makedev() #endif //sendfile has different semantics in different platforms @@ -281,7 +282,7 @@ return statx(AT_FDCWD, path, AT_STATX_SYNC_AS_STAT, mask, buff); } inline static uint16_t stat_mode(struct statx &buf) { return buf.stx_mode; } -inline static uint32_t stat_dev(struct statx &buf) { return buf.stx_dev_major; } +inline static dev_t stat_dev(struct statx &buf) { return makedev(buf.stx_dev_major, buf.stx_dev_minor); } inline static uint64_t stat_ino(struct statx &buf) { return buf.stx_ino; } inline static uint64_t stat_size(struct statx &buf) { return buf.stx_size; } inline static uint32_t stat_uid(struct statx &buf) { return buf.stx_uid; }