aboutsummaryrefslogtreecommitdiff
path: root/zenstore/basicfile.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-03-25 12:04:59 +0100
committerDan Engelbrecht <[email protected]>2022-03-31 11:29:27 +0200
commit6a166635b5c1d12aae5e58a04fbe423cf9995f6f (patch)
treed8ae7df19316397dd2e22a939c003a0b1da589d9 /zenstore/basicfile.cpp
parentMigration now works in larger disk IO chunks (diff)
downloadzen-6a166635b5c1d12aae5e58a04fbe423cf9995f6f.tar.xz
zen-6a166635b5c1d12aae5e58a04fbe423cf9995f6f.zip
incremental migration with optional clean of source
add more fine-grained access modes for BasicFile
Diffstat (limited to 'zenstore/basicfile.cpp')
-rw-r--r--zenstore/basicfile.cpp46
1 files changed, 39 insertions, 7 deletions
diff --git a/zenstore/basicfile.cpp b/zenstore/basicfile.cpp
index fc7282941..44a7fc77f 100644
--- a/zenstore/basicfile.cpp
+++ b/zenstore/basicfile.cpp
@@ -44,13 +44,33 @@ void
BasicFile::Open(const std::filesystem::path& FileName, EMode Mode, std::error_code& Ec)
{
Ec.clear();
- uint32_t ModeFlags = static_cast<uint32_t>(Mode);
#if ZEN_PLATFORM_WINDOWS
- const DWORD dwCreationDisposition = (ModeFlags & static_cast<uint32_t>(kAccessTruncate)) ? CREATE_ALWAYS : OPEN_EXISTING;
- DWORD dwDesiredAccess = GENERIC_READ;
- dwDesiredAccess |= (ModeFlags & static_cast<uint32_t>(kAccessWrite)) ? GENERIC_WRITE : 0;
- dwDesiredAccess |= (ModeFlags & static_cast<uint32_t>(kAccessDelete)) ? DELETE : 0;
+ DWORD dwCreationDisposition = 0;
+ DWORD dwDesiredAccess = 0;
+ switch (Mode)
+ {
+ case EMode::kRead:
+ dwCreationDisposition |= OPEN_EXISTING;
+ dwDesiredAccess |= GENERIC_READ;
+ break;
+ case EMode::kWrite:
+ dwCreationDisposition |= OPEN_ALWAYS;
+ dwDesiredAccess |= (GENERIC_READ | GENERIC_WRITE);
+ break;
+ case EMode::kDelete:
+ dwCreationDisposition |= OPEN_ALWAYS;
+ dwDesiredAccess |= (GENERIC_READ | GENERIC_WRITE | DELETE);
+ break;
+ case EMode::kTruncate:
+ dwCreationDisposition |= CREATE_ALWAYS;
+ dwDesiredAccess |= (GENERIC_READ | GENERIC_WRITE);
+ break;
+ case EMode::kTruncateDelete:
+ dwCreationDisposition |= CREATE_ALWAYS;
+ dwDesiredAccess |= (GENERIC_READ | GENERIC_WRITE | DELETE);
+ break;
+ }
const DWORD dwShareMode = FILE_SHARE_READ;
const DWORD dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
@@ -72,8 +92,20 @@ BasicFile::Open(const std::filesystem::path& FileName, EMode Mode, std::error_co
}
#else
int OpenFlags = O_CLOEXEC;
- OpenFlags |= (ModeFlags & static_cast<uint32_t>(kAccessWrite)) ? O_RDWR : 0;
- OpenFlags |= (ModeFlags & static_cast<uint32_t>(kAccessTruncate)) ? (O_CREAT | O_TRUNC) : 0;
+ switch (Mode)
+ {
+ case EMode::kRead:
+ OpenFlags |= O_RDONLY;
+ break;
+ case EMode::kWrite:
+ case EMode::kDelete:
+ OpenFlags |= (O_RDWR | O_CREAT);
+ break;
+ case EMode::kTruncate:
+ case EMode::kTruncateDelete:
+ OpenFlags |= (O_RDWR | O_CREAT | O_TRUNC);
+ break;
+ }
int Fd = open(FileName.c_str(), OpenFlags, 0666);
if (Fd < 0)