save for the weekend

This commit is contained in:
Gerhard Hoffmann 2024-03-22 13:46:54 +01:00
parent 73340cbb7a
commit f3680754ec
2 changed files with 15 additions and 15 deletions

View File

@ -607,20 +607,23 @@ int32_t GetFileMenuSize(char const *localGitRepo) {
}
char const *GetFileMenu(const char *localGitRepo) {
static char j[] = "{}";
char *json = j;
int const len = GetFileMenuSize(localGitRepo);
if (len > 0) {
json = new char [len+1];
// fprintf(stderr, "allocate pointer %p\n", json);
memset(json, 0x00, len+1);
if (localGitRepos.count(localGitRepo) == 0) {
localGitRepos.insert(localGitRepo,
new LocalGitRepository(localGitRepo));
}
QByteArray const &a = localGitRepos[localGitRepo]->GetFileMenu().constData();
if (a.isValidUtf8()) {
int const len = GetFileMenuSize(localGitRepo);
if (len > 0) {
char *json = new char [len+1];
// fprintf(stderr, "allocate pointer %p\n", json);
memset(json, 0x00, len+1);
memcpy(json, a.constData(), std::min(len, (int)a.size()));
}
}
return json;
}
}
return nullptr;
}
char const *GetFileName(char const *localGitRepo, char const *fileId) {

View File

@ -16,14 +16,11 @@ LocalGitRepository::LocalGitRepository(QString const &localRepository)
}
int32_t LocalGitRepository::GetFileMenuSize() const {
if (m_fileMenuSize == -1) {
GetFileMenu();
}
return m_fileMenuSize;
}
QByteArray const &LocalGitRepository::GetFileMenu() const {
if (m_fileMenu.toStdString() == "{}") {
if (m_fileMenuSize == -1) {
QFile f(QDir::cleanPath(QString(baseDir) + m_localRepository + QDir::separator()
+ "etc/psa_webinterface/menu_config.json"));
if (f.exists()) {
@ -98,7 +95,7 @@ bool LocalGitRepository::SetFile(QString const &fId, QByteArray const &json) {
QFile fn(a);
if (fn.exists()) {
if (fn.open(QIODevice::WriteOnly)) {
quint64 bytesWritten = 0;
qint64 bytesWritten = 0;
qint64 bytesToWrite = a.size();
while (bytesToWrite > 0 &&
(bytesWritten = fn.write(json.constData(), bytesToWrite)) != -1) {