summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRoland Reichwein <mail@reichwein.it>2023-01-01 21:16:19 +0100
committerRoland Reichwein <mail@reichwein.it>2023-01-01 21:16:19 +0100
commita72cd70af957a06ae870d93314b4ed0f3625f6ee (patch)
tree9da93fc597d26ac3cec93a4518649871453a7f94
parent6c339d8aab380a191fe3fce7ca7dc7c09e252ebd (diff)
Adjust to Debian 11 build
-rw-r--r--common.mk22
-rw-r--r--config.cpp2
-rw-r--r--debian/control2
-rw-r--r--storage.cpp23
-rw-r--r--tests/Makefile10
-rw-r--r--tests/test-storage.cpp20
6 files changed, 65 insertions, 14 deletions
diff --git a/common.mk b/common.mk
index 118310f..cffe297 100644
--- a/common.mk
+++ b/common.mk
@@ -1,11 +1,23 @@
CXX=clang++-14
#CXX=g++-12
+ifeq ($(CXX),clang++-14)
+CXXTYPE=clang++
+else ifeq ($(CXX),clang++)
+CXXTYPE=clang++
+else
+CXXTYPE=g++
+endif
+
ifeq ($(shell which $(CXX)),)
CXX=clang++-13
endif
ifeq ($(shell which $(CXX)),)
+CXX=clang++-11
+endif
+
+ifeq ($(shell which $(CXX)),)
CXX=clang++-10
endif
@@ -36,13 +48,19 @@ endif
ifeq ($(CXX),clang++-10)
LIBS+=-fuse-ld=lld-10 -lstdc++
+else ifeq ($(CXX),clang++-11)
+#LIBS+=-fuse-ld=lld-11 -lc++ -lc++abi
+LLVMPROFDATA=llvm-profdata-11
+LLVMCOV=llvm-cov-11
else ifeq ($(CXX),clang++-14)
-LIBS+=-fuse-ld=lld-14 -lc++ -lc++abi
+#LIBS+=-fuse-ld=lld-14 -lc++ -lc++abi
+LLVMPROFDATA=llvm-profdata-14
+LLVMCOV=llvm-cov-14
else
LIBS+=-lstdc++ -lstdc++fs
endif
CXXFLAGS+=$(shell pkg-config --cflags qrcodegencpp Magick++ fmt sqlite3)
-LIBS+=-lfcgi -lboost_filesystem
+LIBS+=-lfcgi -lboost_filesystem -lpthread
LIBS+=-lSQLiteCpp $(shell pkg-config --libs qrcodegencpp Magick++ fmt sqlite3)
diff --git a/config.cpp b/config.cpp
index 7474a1d..4488e84 100644
--- a/config.cpp
+++ b/config.cpp
@@ -23,7 +23,7 @@ Config::Config(const std::string& config_filename): m_dataPath{default_datapath}
m_dataPath = tree.get<std::string>("config.datapath", default_datapath);
m_maxage = tree.get<uint64_t>("config.maxage", default_maxage);
} catch (const std::exception& ex) {
- std::cerr << "Error reading config file " << config_filename << ". Using " << default_datapath << "." << std::endl;
+ std::cerr << "Error reading config file " << config_filename << ". Using defaults." << std::endl;
}
}
diff --git a/debian/control b/debian/control
index ed6ee77..a958cca 100644
--- a/debian/control
+++ b/debian/control
@@ -2,7 +2,7 @@ Source: whiteboard
Section: web
Priority: optional
Maintainer: Roland Reichwein <mail@reichwein.it>
-Build-Depends: debhelper (>= 12), libboost-all-dev | libboost1.71-all-dev, clang | g++-9, uglifyjs, python3-pkg-resources, htmlmin, cleancss, libfcgi-dev, libqrcodegencpp-dev, libmagick++-dev, pkg-config, libfmt-dev, libsqlitecpp-dev, googletest, gcovr
+Build-Depends: debhelper (>= 12), libboost-all-dev | libboost1.71-all-dev, clang | g++-9, llvm | g++-9, lld | g++-9, uglifyjs, python3-pkg-resources, htmlmin, cleancss, libfcgi-dev, libqrcodegencpp-dev, libmagick++-dev, pkg-config, libfmt-dev, libsqlitecpp-dev, googletest, gcovr
Standards-Version: 4.5.0
Homepage: http://www.reichwein.it/whiteboard/
diff --git a/storage.cpp b/storage.cpp
index ffdb2f4..6fb5b64 100644
--- a/storage.cpp
+++ b/storage.cpp
@@ -43,12 +43,22 @@ uint64_t Storage::getNumberOfDocuments()
return m_stmt_getNumberOfDocuments.getColumn<int64_t>(0);
}
+namespace {
+ uint64_t unixepoch()
+ {
+ const auto p1 = std::chrono::system_clock::now();
+ return std::chrono::duration_cast<std::chrono::seconds>(p1.time_since_epoch()).count();
+ }
+} // namespace
+
void Storage::cleanup()
{
if (m_maxage == 0)
return;
- m_stmt_cleanup.init("DELETE FROM documents WHERE timestamp + "s + std::to_string(static_cast<int64_t>(m_maxage)) + " < unixepoch()"s);
+ m_stmt_cleanup.init("DELETE FROM documents WHERE timestamp + ? < ?");
+ m_stmt_cleanup.bind(1, static_cast<int64_t>(m_maxage));
+ m_stmt_cleanup.bind(2, static_cast<int64_t>(unixepoch()));
m_stmt_cleanup.execute();
}
@@ -106,16 +116,18 @@ std::tuple<std::string, int, int> Storage::getRow(const std::string& id)
void Storage::setDocument(const std::string& id, const std::string& document)
{
- m_stmt_setDocument.init("UPDATE documents SET value = ? WHERE id = ?");
+ m_stmt_setDocument.init("UPDATE documents SET value = ?, timestamp = ?, rev = rev + 1 WHERE id = ?");
m_stmt_setDocument.bind(1, document);
- m_stmt_setDocument.bind(2, id);
+ m_stmt_setDocument.bind(2, static_cast<int64_t>(unixepoch()));
+ m_stmt_setDocument.bind(3, id);
if (!m_stmt_setDocument.execute()) {
- m_stmt_setDocument_new.init("INSERT INTO documents (id, value, rev, cursorpos, timestamp) values (?, ?, ?, ?, unixepoch())");
+ m_stmt_setDocument_new.init("INSERT INTO documents (id, value, rev, cursorpos, timestamp) values (?, ?, ?, ?, ?)");
m_stmt_setDocument_new.bind(1, id);
m_stmt_setDocument_new.bind(2, document);
m_stmt_setDocument_new.bind(3, 0);
m_stmt_setDocument_new.bind(4, 0);
+ m_stmt_setDocument_new.bind(5, static_cast<int64_t>(unixepoch()));
m_stmt_setDocument_new.execute();
}
}
@@ -142,11 +154,12 @@ void Storage::setCursorPos(const std::string& id, int cursorPos)
void Storage::setRow(const std::string& id, const std::string& document, int rev, int cursorPos)
{
- m_stmt_setRow.init("INSERT OR REPLACE INTO documents (id, value, rev, cursorpos, timestamp) values (?, ?, ?, ?, unixepoch())");
+ m_stmt_setRow.init("INSERT OR REPLACE INTO documents (id, value, rev, cursorpos, timestamp) values (?, ?, ?, ?, ?)");
m_stmt_setRow.bind(1, id);
m_stmt_setRow.bind(2, document);
m_stmt_setRow.bind(3, rev);
m_stmt_setRow.bind(4, cursorPos);
+ m_stmt_setRow.bind(5, static_cast<int64_t>(unixepoch()));
if (!m_stmt_setRow.execute())
throw std::runtime_error("Unable to insert row with id "s + id);
}
diff --git a/tests/Makefile b/tests/Makefile
index 94789f9..4ade005 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -2,7 +2,7 @@ CXXFLAGS=-g -O0
include ../common.mk
-ifeq ($(CXX),clang++-14)
+ifeq ($(CXXTYPE),clang++)
CXXFLAGS+=-fprofile-instr-generate -fcoverage-mapping
LDFLAGS+=-fprofile-instr-generate -fcoverage-mapping
else
@@ -25,10 +25,10 @@ CXXFLAGS+=\
test: unittests
# https://clang.llvm.org/docs/SourceBasedCodeCoverage.html
-ifeq ($(CXX),clang++-14)
+ifeq ($(CXXTYPE),clang++)
LLVM_PROFILE_FILE="unittests.profraw" ./unittests
- llvm-profdata-14 merge -sparse unittests.profraw -o unittests.profdata
- llvm-cov-14 report --ignore-filename-regex='google' --ignore-filename-regex='test-' --show-region-summary=0 -instr-profile unittests.profdata unittests
+ $(LLVMPROFDATA) merge -sparse unittests.profraw -o unittests.profdata
+ $(LLVMCOV) report --ignore-filename-regex='google' --ignore-filename-regex='test-' --show-region-summary=0 -instr-profile unittests.profdata unittests
else
./unittests
#gcov-12 storage.o
@@ -36,7 +36,7 @@ else
endif
coverage:
- llvm-cov-14 show -instr-profile unittests.profdata $(UNITS:.cpp=.o)
+ $(LLVMCOV) show -instr-profile unittests.profdata $(UNITS:.cpp=.o)
unittests: libgmock.a $(UNITTESTS:.cpp=.o) $(UNITS:.cpp=.o)
$(CXX) $(LDFLAGS) $^ $(LDLIBS) $(LIBS) -o $@
diff --git a/tests/test-storage.cpp b/tests/test-storage.cpp
index 87168fc..158a9bd 100644
--- a/tests/test-storage.cpp
+++ b/tests/test-storage.cpp
@@ -184,3 +184,23 @@ TEST_F(StorageTest, getRow)
EXPECT_EQ(std::get<2>(row), 456);
}
+TEST_F(StorageTest, revision_increment)
+{
+ Storage storage(m_config);
+ storage.setDocument("0", "xyz");
+ storage.setDocument("0bc", "xyz2");
+ storage.setDocument("iabc", "xyz3");
+
+ EXPECT_EQ(storage.getRevision("0"), 0);
+ EXPECT_EQ(storage.getRevision("0bc"), 0);
+ EXPECT_EQ(storage.getRevision("iabc"), 0);
+
+ storage.setDocument("0bc", "xyz234");
+ EXPECT_EQ(storage.getRevision("0bc"), 1);
+
+ storage.setDocument("0bc", "xyz2345");
+ EXPECT_EQ(storage.getRevision("0"), 0);
+ EXPECT_EQ(storage.getRevision("0bc"), 2);
+ EXPECT_EQ(storage.getRevision("iabc"), 0);
+}
+