Skip to content

Commit

Permalink
IO: print the filemode as string
Browse files Browse the repository at this point in the history
  • Loading branch information
mgerhardy committed Jan 10, 2025
1 parent 600434e commit 076bcac
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/modules/io/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,16 @@ void trackOpenedFile(const core::String &path, FileMode mode) {
return;
}
const bool alreadyOpened = _openedFiles.hasKey(absPath);
core_assert_msg(!alreadyOpened, "File %s is already opened in mode %i - this will produce problems on windows", path.c_str(), (int)mode);
if (alreadyOpened) {
Log::error("File %s is already opened in mode %i", path.c_str(), (int)mode);
FileMode openedMode;
core_assert_always(_openedFiles.get(absPath, openedMode));
core_assert_msg(
!alreadyOpened,
"File %s is already opened (opened mode %s, new mode %s) - this will produce problems on windows",
path.c_str(), FileModeStr[(int)openedMode], FileModeStr[(int)mode]);

Log::error("File %s is already opened (opened mode %s, new mode %s)", path.c_str(),
FileModeStr[(int)openedMode], FileModeStr[(int)mode]);
return;
}
Log::debug("open file: %s", absPath.c_str());
Expand Down
14 changes: 13 additions & 1 deletion src/modules/io/File.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#pragma once

#include "core/ArrayLength.h"
#include "core/String.h"
#include "core/SharedPtr.h"
#include "IOResource.h"
Expand All @@ -22,9 +23,20 @@ enum class FileMode {
Append, /**< appending to an existing file or create a new one */
SysRead, /**< reading from the given path - using virtual paths as fallback */
SysWrite, /**< writing into the given path */
ReadNoHome /**< reading from the virtual file system but skip user setting files in the home directories */
ReadNoHome, /**< reading from the virtual file system but skip user setting files in the home directories */
Max
};

static const char * FileModeStr[] = {
"Read",
"Write",
"Append",
"SysRead",
"SysWrite",
"ReadNoHome",
};
static_assert(lengthof(FileModeStr) == (size_t)FileMode::Max, "FileModeStr is incomplete");

/**
* @sa core::string::sanitizeDirPath()
*/
Expand Down

0 comments on commit 076bcac

Please sign in to comment.