[network/libktorrent] src/diskio: Use enum class for CacheFile::Mode

Jack Hill <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 602ee8d6217ed66362d5651c27a68a471dafd994 by Jack Hill.
Committed on 15/08/2026 at 10:19.
Pushed by jackh into branch 'master'.

Use enum class for CacheFile::Mode

M  +9    -9    src/diskio/cachefile.cpp
M  +1    -1    src/diskio/cachefile.h
M  +1    -1    src/diskio/multifilecache.cpp
M  +1    -1    src/diskio/singlefilecache.cpp

https://invent.kde.org/network/libktorrent/-/commit/602ee8d6217ed66362d5651c27a68a471dafd994

diff --git a/src/diskio/cachefile.cpp b/src/diskio/cachefile.cpp
index d8ab5fd8..73665950 100644
--- a/src/diskio/cachefile.cpp
+++ b/src/diskio/cachefile.cpp
@@ -74,7 +74,7 @@ void CacheFile::openFile(Mode mode)
     bool ok = false;
     if (!(ok = fptr.open(QIODevice::ReadWrite))) {
         // in case RDWR fails, try readonly if possible
-        if (mode == READ && (ok = fptr.open(QIODevice::ReadOnly))) {
+        if (mode == Mode::READ && (ok = fptr.open(QIODevice::ReadOnly))) {
             read_only = true;
         }
     }
@@ -109,7 +109,7 @@ void *CacheFile::map(MMappeable *thing, Uint64 off, Uint32 size, Mode mode)
         openFile(mode);
     }
 
-    if (read_only && mode != READ) {
+    if (read_only && mode != Mode::READ) {
         throw Error(i18n("Cannot open %1 for writing: readonly filesystem", path));
     }
 
@@ -133,13 +133,13 @@ void *CacheFile::map(MMappeable *thing, Uint64 off, Uint32 size, Mode mode)
 #ifndef Q_OS_WIN
     int mmap_flag = 0;
     switch (mode) {
-    case READ:
+    case Mode::READ:
         mmap_flag = PROT_READ;
         break;
-    case WRITE:
+    case Mode::WRITE:
         mmap_flag = PROT_WRITE;
         break;
-    case RW:
+    case Mode::RW:
         mmap_flag = PROT_READ | PROT_WRITE;
         break;
     }
@@ -195,7 +195,7 @@ void CacheFile::growFile(Uint64 to_write)
     // reopen the file if necessary
     if (!fptr.isOpen()) {
         //  Out(SYS_DIO|LOG_DEBUG) << "Reopening " << path << endl;
-        openFile(RW);
+        openFile(Mode::RW);
     }
 
     if (read_only) {
@@ -309,7 +309,7 @@ void CacheFile::read(Uint8 *buf, Uint32 size, Uint64 off)
     // reopen the file if necessary
     if (!fptr.isOpen()) {
         //  Out(SYS_DIO|LOG_DEBUG) << "Reopening " << path << endl;
-        openFile(READ);
+        openFile(Mode::READ);
         close_again = true;
     }
 
@@ -344,7 +344,7 @@ void CacheFile::write(const Uint8 *buf, Uint32 size, Uint64 off)
     // reopen the file if necessary
     if (!fptr.isOpen()) {
         //  Out(SYS_DIO|LOG_DEBUG) << "Reopening " << path << endl;
-        openFile(RW);
+        openFile(Mode::RW);
         close_again = true;
     }
 
@@ -402,7 +402,7 @@ void CacheFile::preallocate(PreallocationThread *prealloc)
     Out(SYS_GEN | LOG_NOTICE) << "Preallocating file " << path << " (" << max_size << " bytes)" << endl;
     bool close_again = false;
     if (!fptr.isOpen()) {
-        openFile(RW);
+        openFile(Mode::RW);
         close_again = true;
     }
 
diff --git a/src/diskio/cachefile.h b/src/diskio/cachefile.h
index 26d0968e..1d22f31b 100644
--- a/src/diskio/cachefile.h
+++ b/src/diskio/cachefile.h
@@ -62,7 +62,7 @@ public:
      * \var RW
      * Opened for read and write.
      */
-    enum Mode {
+    enum class Mode {
         READ,
         WRITE,
         RW,
diff --git a/src/diskio/multifilecache.cpp b/src/diskio/multifilecache.cpp
index a2954c91..a5dd20dd 100644
--- a/src/diskio/multifilecache.cpp
+++ b/src/diskio/multifilecache.cpp
@@ -389,7 +389,7 @@ PieceData::Ptr MultiFileCache::createPiece(Chunk *c, Uint32 off, Uint32 length,
         if (Cache::mappedModeAllowed() && mmap_failures < 3) {
             const Uint64 offset = FileOffset(c, f, tor.getChunkSize()) + off;
             PieceData::Ptr piece(new PieceData(c, off, length, nullptr, fd, read_only));
-            Uint8 *buf = (Uint8 *)fd->map(piece.data(), offset, length, read_only ? CacheFile::READ : CacheFile::RW);
+            Uint8 *buf = (Uint8 *)fd->map(piece.data(), offset, length, read_only ? CacheFile::Mode::READ : CacheFile::Mode::RW);
             if (buf) {
                 piece->setData(buf);
                 insertPiece(c, piece);
diff --git a/src/diskio/singlefilecache.cpp b/src/diskio/singlefilecache.cpp
index dfa9e9c0..3cedb4ef 100644
--- a/src/diskio/singlefilecache.cpp
+++ b/src/diskio/singlefilecache.cpp
@@ -135,7 +135,7 @@ PieceData::Ptr SingleFileCache::createPiece(Chunk *c, Uint64 off, Uint32 length,
         return cp;
     } else {
         PieceData::Ptr cp(new PieceData(c, off, length, nullptr, fd, read_only));
-        buf = (Uint8 *)fd->map(cp.data(), piece_off, length, read_only ? CacheFile::READ : CacheFile::RW);
+        buf = (Uint8 *)fd->map(cp.data(), piece_off, length, read_only ? CacheFile::Mode::READ : CacheFile::Mode::RW);
         if (buf) {
             cp->setData(buf);
         } else {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.