diff options
23 files changed, 164 insertions, 242 deletions
diff --git a/config/src/tests/misc/configsystem.cpp b/config/src/tests/misc/configsystem.cpp index c02e27ca989..db3d0a80706 100644 --- a/config/src/tests/misc/configsystem.cpp +++ b/config/src/tests/misc/configsystem.cpp @@ -44,7 +44,7 @@ TEST("require that correct pid file succeeds") { FastOS_File::MakeDirIfNotPresentOrExit("var/run"); FastOS_File pid_file("var/run/configproxy.pid"); pid_file.OpenWriteOnlyTruncate(); - pid_file.Close(); + ASSERT_TRUE(pid_file.Close()); ASSERT_EQUAL(0, setenv(VESPA_HOME, cwd, 1)); vespa::Defaults::bootstrap(cwd); diff --git a/fastlib/src/vespa/fastlib/io/bufferedfile.cpp b/fastlib/src/vespa/fastlib/io/bufferedfile.cpp index e6972c501f5..cbe95e286b7 100644 --- a/fastlib/src/vespa/fastlib/io/bufferedfile.cpp +++ b/fastlib/src/vespa/fastlib/io/bufferedfile.cpp @@ -204,9 +204,7 @@ Fast_BufferedFile::SetPosition(const int64_t s) const char * Fast_BufferedFile::GetFileName(void) const { - return (_file.get() == NULL) - ? "" - : _file->GetFileName(); + return _file ? _file->GetFileName() : ""; } char * @@ -228,7 +226,7 @@ Fast_BufferedFile::ReadLine(char *line, size_t buflen) fillReadBuf(); if (_bufi >= _bufe) { if (p == line) - return NULL; + return nullptr; *p = 0; return line; } @@ -394,8 +392,8 @@ Fast_BufferedFile::Fast_BufferedFile(FastOS_FileInterface *file, size_t bufferSi FastOS_FileInterface(), _fileleft(static_cast<uint64_t>(-1)), _buf(vespalib::alloc::Alloc::allocMMap(computeBufLen(bufferSize))), - _bufi(NULL), - _bufe(NULL), + _bufi(nullptr), + _bufe(nullptr), _filepos(0), _directIOEnabled(false), _file(file) @@ -405,7 +403,8 @@ Fast_BufferedFile::Fast_BufferedFile(FastOS_FileInterface *file, size_t bufferSi Fast_BufferedFile::~Fast_BufferedFile(void) { - Close(); + bool close_ok = Close(); + assert(close_ok); } void diff --git a/fastlib/src/vespa/fastlib/io/tests/bufferedfiletest.cpp b/fastlib/src/vespa/fastlib/io/tests/bufferedfiletest.cpp index 4cc386b2d17..0e27cb525af 100644 --- a/fastlib/src/vespa/fastlib/io/tests/bufferedfiletest.cpp +++ b/fastlib/src/vespa/fastlib/io/tests/bufferedfiletest.cpp @@ -4,8 +4,6 @@ TEST("main") { - int i = 0; - int j = 0; int value = 0; FastOS_StatInfo statInfo; @@ -22,7 +20,7 @@ TEST("main") { bufFile.WriteOpen("testfile1"); bufFile.addNum(1,10,' '); bufFile.CheckedWrite("\n",1); - bufFile.Close(); + ASSERT_TRUE(bufFile.Close()); FastOS_File::Stat("testfile1", &statInfo); if (statInfo._size != 11) { printf (" -- FAILURE\n\n"); @@ -36,7 +34,7 @@ TEST("main") { char buf[8192]; // allocate 8K buffer memset(buf,0xff,8192); bufFile.CheckedWrite(buf,4095); // write almost 4K - bufFile.Close(); + ASSERT_TRUE(bufFile.Close()); FastOS_File::Stat("testfile2", &statInfo); if (statInfo._size != 4095) { printf (" -- FAILURE\n\n"); @@ -48,7 +46,7 @@ TEST("main") { printf ("testing 4096 byte long file\n"); bufFile.WriteOpen("testfile3"); bufFile.CheckedWrite(buf,4096); // write exactly 4K - bufFile.Close(); + ASSERT_TRUE(bufFile.Close()); FastOS_File::Stat("testfile3", &statInfo); if (statInfo._size != 4096) { printf (" -- FAILURE\n\n"); @@ -60,7 +58,7 @@ TEST("main") { printf ("testing 4097 byte long file\n"); bufFile.WriteOpen("testfile4"); bufFile.CheckedWrite(buf,4097); // write a bit over 4K - bufFile.Close(); + ASSERT_TRUE(bufFile.Close()); FastOS_File::Stat("testfile4", &statInfo); if (statInfo._size != 4097) { printf (" -- FAILURE\n\n"); @@ -71,14 +69,14 @@ TEST("main") { // test 5 printf ("testing 610000 byte long file with repeated addNum\n"); bufFile.WriteOpen("testfile5"); - for (i = 0; i < 10000; i++) { - for (j = 0; j < 10; j++) { + for (int i = 0; i < 10000; i++) { + for (int j = 0; j < 10; j++) { bufFile.addNum(value,6,' '); value++; } bufFile.CheckedWrite("\n",1); } - bufFile.Close(); + ASSERT_TRUE(bufFile.Close()); FastOS_File::Stat("testfile5", &statInfo); if (statInfo._size != 610000) { printf (" -- FAILURE\n\n"); diff --git a/fastos/src/tests/filetest.cpp b/fastos/src/tests/filetest.cpp index 09ed1ea33ae..d95580897d0 100644 --- a/fastos/src/tests/filetest.cpp +++ b/fastos/src/tests/filetest.cpp @@ -32,7 +32,6 @@ bool createFile(const char* fileName, success = true; } } - cf.Close(); } return success; } @@ -269,8 +268,8 @@ public: ssize_t wroteB = file.Write2(buffer, bufSize); Progress(wroteB == bufSize, "Writing %d bytes to file", bufSize); - file.Close(); - + bool close_ok = file.Close(); + assert(close_ok); file.enableMemoryMap(mmap_flags); rc = file.OpenReadOnly(); @@ -323,7 +322,8 @@ public: ssize_t wroteB = file.Write2(buffer, bufSize); Progress(wroteB == bufSize, "Writing %d bytes to file", bufSize); - file.Close(); + bool close_ok = file.Close(); + assert(close_ok); if (rc) { file.EnableDirectIO(); @@ -556,7 +556,8 @@ public: if (myFile->OpenExisting()) { Progress(false, "OpenExisting() should not work when '%s' does not exist.", rwFilename.c_str()); - myFile->Close(); + bool close_ok = myFile->Close(); + assert(close_ok); } else { Progress(true, "OpenExisting() should fail when '%s' does not exist, and it did.", rwFilename.c_str()); } @@ -684,8 +685,6 @@ public: position = file.GetPosition(); Progress(position == 4, "File pointer should still be 4 after ReadBuf"); Progress(strcmp(buffer, "a test") == 0, "[a test]=[%s]", buffer); - - file.Close(); } PrintSeparator(); diff --git a/fastos/src/vespa/fastos/file.cpp b/fastos/src/vespa/fastos/file.cpp index 15a817c0bff..fc7074d7815 100644 --- a/fastos/src/vespa/fastos/file.cpp +++ b/fastos/src/vespa/fastos/file.cpp @@ -11,6 +11,7 @@ #include <cstring> #include <fcntl.h> #include <cstdlib> +#include <cassert> DirectIOException::DirectIOException(const char * fileName, const void * buffer, size_t length, int64_t offset) : std::exception(), @@ -258,8 +259,10 @@ FastOS_FileInterface::CopyFile( const char *src, const char *dst ) delete [] tmpBuf; } // else out of memory ? - s.Close(); - d.Close(); + bool close_ok = s.Close(); + assert(close_ok); + close_ok = d.Close(); + assert(close_ok); } // else Could not open source or destination file. } // else Source file does not exist, or input args are invalid. diff --git a/fastos/src/vespa/fastos/linux_file.cpp b/fastos/src/vespa/fastos/linux_file.cpp index 6cbd320d426..1074c02b4ac 100644 --- a/fastos/src/vespa/fastos/linux_file.cpp +++ b/fastos/src/vespa/fastos/linux_file.cpp @@ -9,13 +9,14 @@ #ifdef __linux__ #include "file.h" +#include "file_rw_ops.h" #include <sstream> #include <unistd.h> #include <fcntl.h> -#include "file_rw_ops.h" #include <cstdio> #include <cstring> #include <system_error> +#include <cassert> using fastos::File_RW_Ops; @@ -29,6 +30,11 @@ FastOS_Linux_File::FastOS_Linux_File(const char *filename) { } +FastOS_Linux_File::~FastOS_Linux_File () { + bool ok = Close(); + assert(ok); +} + #define DIRECTIOPOSSIBLE(buf, len, off) \ ((off & (_directIOFileAlign - 1)) == 0 && \ (len & (_directIOFileAlign - 1)) == 0 && \ @@ -383,12 +389,14 @@ FastOS_Linux_File::Open(unsigned int openFlags, const char *filename) if (POSIX_FADV_NORMAL != fadviseOptions) { rc = (posix_fadvise(_filedes, 0, 0, fadviseOptions) == 0); if (!rc) { - Close(); + bool close_ok = Close(); + assert(close_ok); } } } if (rc) { - Sync(); + bool sync_ok = Sync(); + assert(sync_ok); _cachedSize = GetSize(); _filePointer = 0; } @@ -397,7 +405,8 @@ FastOS_Linux_File::Open(unsigned int openFlags, const char *filename) if (rc && (POSIX_FADV_NORMAL != getFAdviseOptions())) { rc = (posix_fadvise(_filedes, 0, 0, getFAdviseOptions()) == 0); if (!rc) { - Close(); + bool close_ok = Close(); + assert(close_ok); } } } diff --git a/fastos/src/vespa/fastos/linux_file.h b/fastos/src/vespa/fastos/linux_file.h index 92f0d0b923a..ababf51d26d 100644 --- a/fastos/src/vespa/fastos/linux_file.h +++ b/fastos/src/vespa/fastos/linux_file.h @@ -25,9 +25,7 @@ protected: public: FastOS_Linux_File (const char *filename = nullptr); - ~FastOS_Linux_File () { - Close(); - } + ~FastOS_Linux_File (); bool GetDirectIORestrictions(size_t &memoryAlignment, size_t &transferGranularity, size_t &transferMaximum) override; bool DirectIOPadding(int64_t offset, size_t length, size_t &padBefore, size_t &padAfter) override; void EnableDirectIO() override; diff --git a/fastos/src/vespa/fastos/unix_file.cpp b/fastos/src/vespa/fastos/unix_file.cpp index 8dd589d5144..39e31c87702 100644 --- a/fastos/src/vespa/fastos/unix_file.cpp +++ b/fastos/src/vespa/fastos/unix_file.cpp @@ -407,7 +407,7 @@ bool FastOS_UNIX_File::Rename (const char *currentFileName, const char *newFileN } bool -FastOS_UNIX_File::Sync(void) +FastOS_UNIX_File::Sync() { assert(IsOpened()); diff --git a/juniper/src/test/auxTest.cpp b/juniper/src/test/auxTest.cpp index 069a114bfd3..15f5ad1749e 100644 --- a/juniper/src/test/auxTest.cpp +++ b/juniper/src/test/auxTest.cpp @@ -135,12 +135,12 @@ AuxTest::TestDoubleWidth() juniper::Config myConfig("best", juniper); juniper::QueryParser q("\xef\xbd\x93\xef\xbd\x8f\xef\xbd\x8e\xef\xbd\x99"); - juniper::QueryHandle qh(q, NULL, juniper.getModifier()); + juniper::QueryHandle qh(q, nullptr, juniper.getModifier()); juniper::Result* res = juniper::Analyse(&myConfig, &qh, input, 17, 0, 0, 0); - _test(res != NULL); + _test(res != nullptr); - juniper::Summary* sum = juniper::GetTeaser(res, NULL); + juniper::Summary* sum = juniper::GetTeaser(res, nullptr); (void) sum; // this should work // _test(sum->Length() != 0); @@ -154,12 +154,13 @@ AuxTest::TestPartialUTF8() { const int inputSize = 5769; // NB: update this if input is changed char input[inputSize]; - FastOS_File file((GetSourceDirectory() + "partialutf8.input.utf8").c_str()); - _test(file.OpenReadOnly()); - _test(file.GetSize() == inputSize); - _test(file.Read(input, inputSize)); - _test(countBrokenUTF8(input, inputSize) == 0); - file.Close(); + { + FastOS_File file((GetSourceDirectory() + "partialutf8.input.utf8").c_str()); + _test(file.OpenReadOnly()); + _test(file.GetSize() == inputSize); + _test(file.Read(input, inputSize)); + _test(countBrokenUTF8(input, inputSize) == 0); + } juniper::PropertyMap myprops; myprops // config taken from vespa test case @@ -173,12 +174,12 @@ AuxTest::TestPartialUTF8() juniper::Config myConfig("best", juniper); juniper::QueryParser q("ipod"); - juniper::QueryHandle qh(q, NULL, juniper.getModifier()); + juniper::QueryHandle qh(q, nullptr, juniper.getModifier()); juniper::Result* res = juniper::Analyse(&myConfig, &qh, input, inputSize, 0, 0, 0); - _test(res != NULL); + _test(res != nullptr); - juniper::Summary* sum = juniper::GetTeaser(res, NULL); + juniper::Summary* sum = juniper::GetTeaser(res, nullptr); _test(sum->Length() != 0); // check for partial/broken utf-8 @@ -191,12 +192,13 @@ void AuxTest::TestLargeBlockChinese() { const int inputSize = 10410; // NB: update this if input is changed char input[inputSize]; - FastOS_File file((GetSourceDirectory() + "largeblockchinese.input.utf8").c_str()); - _test(file.OpenReadOnly()); - _test(file.GetSize() == inputSize); - _test(file.Read(input, inputSize)); - _test(countBrokenUTF8(input, inputSize) == 0); - file.Close(); + { + FastOS_File file((GetSourceDirectory() + "largeblockchinese.input.utf8").c_str()); + _test(file.OpenReadOnly()); + _test(file.GetSize() == inputSize); + _test(file.Read(input, inputSize)); + _test(countBrokenUTF8(input, inputSize) == 0); + } juniper::PropertyMap myprops; myprops // config taken from reported bug @@ -212,12 +214,12 @@ void AuxTest::TestLargeBlockChinese() juniper::Config myConfig("best", juniper); juniper::QueryParser q("希望"); - juniper::QueryHandle qh(q, NULL, juniper.getModifier()); + juniper::QueryHandle qh(q, nullptr, juniper.getModifier()); juniper::Result* res = juniper::Analyse(&myConfig, &qh, input, inputSize, 0, 0, 0); - _test(res != NULL); + _test(res != nullptr); - juniper::Summary* sum = juniper::GetTeaser(res, NULL); + juniper::Summary* sum = juniper::GetTeaser(res, nullptr); _test(sum->Length() != 0); // check that the entire block of chinese data is not returned in the summary @@ -232,7 +234,7 @@ void AuxTest::TestLargeBlockChinese() void AuxTest::TestExample() { juniper::QueryParser q("AND(consume,sleep,tree)"); - juniper::QueryHandle qh(q, NULL, juniper::_Juniper->getModifier()); + juniper::QueryHandle qh(q, nullptr, juniper::_Juniper->getModifier()); // some content const char* content = "the monkey consumes bananas and sleeps afterwards." @@ -244,7 +246,7 @@ void AuxTest::TestExample() &qh, content, content_len, 0, 0, 0); - _test(res != NULL); + _test(res != nullptr); res->Scan(); Matcher& m = *res->_matcher; @@ -259,7 +261,7 @@ AuxTest::TestPropertyMap() juniper::PropertyMap map; IJuniperProperties *props = ↦ map.set("foo", "bar").set("one", "two"); - _test(props->GetProperty("bogus") == NULL); + _test(props->GetProperty("bogus") == nullptr); _test(strcmp(props->GetProperty("bogus", "default"), "default") == 0); _test(strcmp(props->GetProperty("foo"), "bar") == 0); _test(strcmp(props->GetProperty("one", "default"), "two") == 0); @@ -395,7 +397,7 @@ void AuxTest::TestUTF8context() { const char* iso_cont = char_from_u8(u8"AND(m\u00b5ss,fast,s\u00f8kemotor,\u00e5relang)"); juniper::QueryParser q(iso_cont); - juniper::QueryHandle qh(q, NULL, juniper::_Juniper->getModifier()); + juniper::QueryHandle qh(q, nullptr, juniper::_Juniper->getModifier()); // some content std::string s(char_from_u8(u8"Fast leverer s\u00d8kemotorer og andre nyttige ting for \u00e5 finne frem p\u00e5 ")); @@ -409,7 +411,7 @@ void AuxTest::TestUTF8context() s.append(char_from_u8(u8"Hvis bare UTF8-kodingen virker som den skal for tegn som tar mer enn \u00e9n byte.")); juniper::Result* res = juniper::Analyse(juniper::TestConfig, &qh, s.c_str(), s.size(), 0, 0, 0); - _test(res != NULL); + _test(res != nullptr); size_t charsize; Matcher& m = *res->_matcher; @@ -456,8 +458,6 @@ void AuxTest::TestUTF8context() } -const char* japanese_sep_ex = "。"; - struct TermTextPair { const char* term; @@ -477,24 +477,24 @@ static TermTextPair testjap[] = { "hit", " -. hit at start" }, { "hit", "hit at end .,: " }, { "hit", "---------------------------------------------------------------------------------------------------------------------this is a text that is long enough to generate a hit that does have dots on both sides ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; " }, - { NULL, NULL } + { nullptr, nullptr } }; void AuxTest::TestJapanese() { - for (int i = 0; testjap[i].term != NULL; i++) + for (int i = 0; testjap[i].term != nullptr; i++) { const char* qstr = testjap[i].term; juniper::QueryParser q(qstr); - juniper::QueryHandle qh(q, NULL, juniper::_Juniper->getModifier()); + juniper::QueryHandle qh(q, nullptr, juniper::_Juniper->getModifier()); const char* content = testjap[i].text; int content_len = strlen(content); juniper::Result* res = juniper::Analyse(juniper::TestConfig, &qh, content, content_len, 0, 0, 0); - _test(res != NULL); + _test(res != nullptr); size_t charsize; Matcher& m = *res->_matcher; @@ -506,7 +506,7 @@ void AuxTest::TestJapanese() _sumconf = CreateSummaryConfig("<hit>", "</hit>", "...", "", connectors); SummaryDesc* sumdesc = m.CreateSummaryDesc(256, 256, 4, 80); - _test(sumdesc != NULL); + _test(sumdesc != nullptr); if (!sumdesc) return; std::string sum = BuildSummary(content, content_len, sumdesc, _sumconf, charsize); @@ -556,7 +556,7 @@ void AuxTest::test_summary(Matcher& m, const char* content, size_t content_len, int size, int matches, int surround, size_t& charsize) { SummaryDesc* sum = m.CreateSummaryDesc(size, size, matches, surround); - _test(sum != NULL); + _test(sum != nullptr); if (!sum) { // No summary generated! @@ -571,16 +571,6 @@ void AuxTest::test_summary(Matcher& m, const char* content, size_t content_len, DeleteSummaryDesc(sum); } - -class DefProps : public IJuniperProperties -{ -public: - const char* GetProperty(const char*, const char* def) override { - return def; - } -}; - - void AuxTest::TestStartHits() { juniper::QueryParser q("elvis"); @@ -595,9 +585,9 @@ void AuxTest::TestStartHits() juniper::Result* res = juniper::Analyse(juniper::TestConfig, &qh, content, content_len, 0, 0, 0); - _test(res != NULL); + _test(res != nullptr); - juniper::Summary* sum = juniper::GetTeaser(res, NULL); + juniper::Summary* sum = juniper::GetTeaser(res, nullptr); (void) sum; // TODO: ReEnable _test(sum->Length() != 0); juniper::ReleaseResult(res); @@ -620,36 +610,13 @@ void AuxTest::TestEndHit() juniper::Result* res = juniper::Analyse(juniper::TestConfig, &qh, content, content_len, 0, 0, 0); - _test(res != NULL); + _test(res != nullptr); - juniper::Summary* sum = juniper::GetTeaser(res, NULL); + juniper::Summary* sum = juniper::GetTeaser(res, nullptr); _test(sum->Length() != 0); juniper::ReleaseResult(res); } - - -class TokenChecker : public ITokenProcessor -{ -private: - TokenChecker(const TokenChecker&); - TokenChecker& operator= (const TokenChecker&); - - Token* _out; - int i; -public: - TokenChecker(Token* output) : _out(output), i(0) - { } - - void handle_token(Token& token) override { - _out[i] = token; - i++; - } - - void handle_end(Token&) override {} -}; - - void AuxTest::TestJuniperStack() { // Stack simplification tests @@ -673,7 +640,7 @@ void AuxTest::TestJuniperStack() q->_arity = 0; SimplifyStack(q); std::string s1; - _test(q == NULL); + _test(q == nullptr); if (GetNumFailed() > 0) fprintf(stderr, "TestJuniperStack: %s\n", s.c_str()); @@ -697,7 +664,6 @@ public: //_tokens.back().c_str(), //(int)t.bytepos, (int)t.wordpos, t.bytelen, t.curlen); } - void clearTokens() { _tokens.clear(); } const std::vector<std::string> & getTokens() const { return _tokens; } }; @@ -913,11 +879,11 @@ AuxTest::TestWhiteSpacePreserved() juniper::Config myConfig("myconfig", juniper); juniper::QueryParser q("best"); - juniper::QueryHandle qh(q, NULL, juniper.getModifier()); + juniper::QueryHandle qh(q, nullptr, juniper.getModifier()); juniper::Result* res = juniper::Analyse(&myConfig, &qh, input.c_str(), input.size(), 0, 0, 0); - _test(res != NULL); + _test(res != nullptr); - juniper::Summary* sum = juniper::GetTeaser(res, NULL); + juniper::Summary* sum = juniper::GetTeaser(res, nullptr); vespalib::string expected = "<hi>best</hi> of \nmetallica"; vespalib::string actual(sum->Text(), sum->Length()); _test(actual == expected); diff --git a/searchcommon/src/vespa/searchcommon/common/schema.cpp b/searchcommon/src/vespa/searchcommon/common/schema.cpp index af730f38018..0127f727069 100644 --- a/searchcommon/src/vespa/searchcommon/common/schema.cpp +++ b/searchcommon/src/vespa/searchcommon/common/schema.cpp @@ -290,18 +290,13 @@ Schema::saveToFile(const vespalib::string & fileName) const FastOS_File s; s.OpenReadWrite(fileName.c_str()); if (!s.IsOpened()) { - LOG(warning, - "Could not open schema file '%s' for fsync", - fileName.c_str()); + LOG(warning, "Could not open schema file '%s' for fsync", fileName.c_str()); return false; } else { if (!s.Sync()) { - LOG(warning, - "Could not fsync schema file '%s'", - fileName.c_str()); + LOG(warning, "Could not fsync schema file '%s'", fileName.c_str()); return false; } - s.Close(); } return true; } diff --git a/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp b/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp index 6e8223399e6..1d1fda70f8f 100644 --- a/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp +++ b/searchcore/src/apps/vespa-gen-testdocs/vespa-gen-testdocs.cpp @@ -18,7 +18,6 @@ LOG_SETUP("vespa-gen-testdocs"); typedef vespalib::hash_set<vespalib::string> StringSet; typedef std::vector<vespalib::string> StringArray; -typedef std::shared_ptr<StringArray> StringArraySP; using namespace vespalib::alloc; using vespalib::string; @@ -38,10 +37,7 @@ void usageHeader() { using std::cerr; - cerr << - "vespa-gen-testdocs version 0.0\n" - "\n" - "USAGE:\n"; + cerr << "vespa-gen-testdocs version 0.0\n\nUSAGE:\n"; } string @@ -71,8 +67,7 @@ splitArg(const string &arg) } void -shafile(const string &baseDir, - const string &file) +shafile(const string &baseDir, const string &file) { unsigned char digest[EVP_MAX_MD_SIZE]; unsigned int digest_len = 0; @@ -98,7 +93,6 @@ shafile(const string &baseDir, EVP_DigestUpdate(md_ctx.get(), buf.get(), thistime); remainder -= thistime; } - f.Close(); EVP_DigestFinal_ex(md_ctx.get(), &digest[0], &digest_len); assert(digest_len > 0u && digest_len <= EVP_MAX_MD_SIZE); for (unsigned int i = 0; i < digest_len; ++i) { @@ -106,10 +100,7 @@ shafile(const string &baseDir, os.fill('0'); os << std::hex << static_cast<unsigned int>(digest[i]); } - LOG(info, - "SHA256(%s)= %s", - file.c_str(), - os.str().c_str()); + LOG(info, "SHA256(%s)= %s", file.c_str(), os.str().c_str()); } class StringGenerator @@ -119,14 +110,9 @@ class StringGenerator public: StringGenerator(vespalib::Rand48 &rnd); - void - rand_string(string &res, uint32_t minLen, uint32_t maxLen); + void rand_string(string &res, uint32_t minLen, uint32_t maxLen); - void - rand_unique_array(StringArray &res, - uint32_t minLen, - uint32_t maxLen, - uint32_t size); + void rand_unique_array(StringArray &res, uint32_t minLen, uint32_t maxLen, uint32_t size); }; @@ -590,7 +576,8 @@ DocumentGenerator::generate(uint32_t docMin, uint32_t docIdLimit, } } f.Flush(); - f.Close(); + bool close_ok = f.Close(); + assert(close_ok); LOG(info, "Calculating sha256 for %s", feedFileName.c_str()); shafile(baseDir, feedFileName); } diff --git a/searchcore/src/vespa/searchcore/proton/common/hw_info_sampler.cpp b/searchcore/src/vespa/searchcore/proton/common/hw_info_sampler.cpp index 2f0db6083c7..c21bb0866cf 100644 --- a/searchcore/src/vespa/searchcore/proton/common/hw_info_sampler.cpp +++ b/searchcore/src/vespa/searchcore/proton/common/hw_info_sampler.cpp @@ -79,29 +79,31 @@ void writeConfig(const vespalib::string &path, double measureDiskWriteSpeed(const vespalib::string &path, size_t diskWriteLen) { - FastOS_File testFile; vespalib::string fileName = path + "/hwinfo-writespeed"; size_t bufferLen = 1_Mi; Alloc buffer(Alloc::allocMMap(bufferLen)); memset(buffer.get(), 0, buffer.size()); - testFile.EnableDirectIO(); - testFile.OpenWriteOnlyTruncate(fileName.c_str()); - sync(); - sleep(1); - sync(); - sleep(1); - Clock::time_point before = Clock::now(); - size_t residue = diskWriteLen; - while (residue > 0) { - size_t writeNow = std::min(residue, bufferLen); - testFile.WriteBuf(buffer.get(), writeNow); - residue -= writeNow; + double diskWriteSpeed; + { + FastOS_File testFile; + testFile.EnableDirectIO(); + testFile.OpenWriteOnlyTruncate(fileName.c_str()); + sync(); + sleep(1); + sync(); + sleep(1); + Clock::time_point before = Clock::now(); + size_t residue = diskWriteLen; + while (residue > 0) { + size_t writeNow = std::min(residue, bufferLen); + testFile.WriteBuf(buffer.get(), writeNow); + residue -= writeNow; + } + Clock::time_point after = Clock::now(); + double elapsed = vespalib::to_s(after - before); + diskWriteSpeed = diskWriteLen / elapsed / 1_Mi; } - Clock::time_point after = Clock::now(); - testFile.Close(); vespalib::unlink(fileName); - double elapsed = vespalib::to_s(after - before); - double diskWriteSpeed = diskWriteLen / elapsed / 1_Mi; return diskWriteSpeed; } diff --git a/searchcore/src/vespa/searchcore/proton/server/fileconfigmanager.cpp b/searchcore/src/vespa/searchcore/proton/server/fileconfigmanager.cpp index 9a525731d0d..34369a0803e 100644 --- a/searchcore/src/vespa/searchcore/proton/server/fileconfigmanager.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/fileconfigmanager.cpp @@ -68,7 +68,6 @@ fsyncFile(const vespalib::string &fileName) if (!f.Sync()) { LOG(error, "Could not fsync file '%s'", fileName.c_str()); } - f.Close(); } template <class Config> @@ -131,7 +130,6 @@ ConfigFile::ConfigFile(const vespalib::string &name, const vespalib::string &ful _content.resize(fileSize); file.ReadBuf(&_content[0], fileSize); _modTime = file.GetModificationTime(); - file.Close(); } nbostream & diff --git a/searchcorespi/src/vespa/searchcorespi/index/indexwriteutilities.cpp b/searchcorespi/src/vespa/searchcorespi/index/indexwriteutilities.cpp index 058a21e15c7..cc2575f74d2 100644 --- a/searchcorespi/src/vespa/searchcorespi/index/indexwriteutilities.cpp +++ b/searchcorespi/src/vespa/searchcorespi/index/indexwriteutilities.cpp @@ -24,8 +24,7 @@ using search::SerialNum; using vespalib::IllegalStateException; using vespalib::FileHeader; -namespace searchcorespi { -namespace index { +namespace searchcorespi::index { namespace { @@ -42,22 +41,24 @@ IndexWriteUtilities::writeSerialNum(SerialNum serialNum, IndexDiskLayout::getSerialNumFileName(dir); const vespalib::string tmpFileName = fileName + ".tmp"; - SerialNumFileHeaderContext snFileHeaderContext(fileHeaderContext, - serialNum); + SerialNumFileHeaderContext snFileHeaderContext(fileHeaderContext, serialNum); Fast_BufferedFile file; file.WriteOpen(tmpFileName.c_str()); FileHeader fileHeader; snFileHeaderContext.addTags(fileHeader, fileName); - fileHeader.putTag(FileHeader::Tag(IndexDiskLayout::SerialNumTag, - serialNum)); + fileHeader.putTag(FileHeader::Tag(IndexDiskLayout::SerialNumTag, serialNum)); bool ok = (fileHeader.writeFile(file) >= fileHeader.getSize()); - if (!file.Sync()) { + if ( ! ok) { + LOG(error, "Unable to write file header '%s'", tmpFileName.c_str()); + } + if ( ! file.Sync()) { + ok = false; + LOG(error, "Unable to fsync '%s'", tmpFileName.c_str()); + } + if ( ! file.Close()) { ok = false; - LOG(error, - "Unable to fsync '%s'", - tmpFileName.c_str()); + LOG(error, "Unable to close '%s'", tmpFileName.c_str()); } - file.Close(); vespalib::File::sync(dir); if (ok) { @@ -85,23 +86,20 @@ IndexWriteUtilities::copySerialNumFile(const vespalib::string &sourceDir, } FastOS_File file(tmpDest.c_str()); if (!file.OpenReadWrite()) { - LOG(error, - "Unable to open '%s' for fsync", - tmpDest.c_str()); + LOG(error, "Unable to open '%s' for fsync", tmpDest.c_str()); return false; } if (!file.Sync()) { - LOG(error, - "Unable to fsync '%s'", - tmpDest.c_str()); + LOG(error, "Unable to fsync '%s'", tmpDest.c_str()); + return false; + } + if (!file.Close()) { + LOG(error, "Unable to close '%s'", tmpDest.c_str()); return false; } - file.Close(); vespalib::File::sync(destDir); if (!file.Rename(dest.c_str())) { - LOG(error, - "Unable to rename file '%s' to '%s'", - tmpDest.c_str(), dest.c_str()); + LOG(error, "Unable to rename file '%s' to '%s'", tmpDest.c_str(), dest.c_str()); return false; } vespalib::File::sync(destDir); @@ -193,6 +191,4 @@ IndexWriteUtilities::updateDiskIndexSchema(const vespalib::string &indexDir, vespalib::File::sync(indexDir); } -} // namespace index -} // namespace searchcorespi - +} diff --git a/searchcorespi/src/vespa/searchcorespi/index/indexwriteutilities.h b/searchcorespi/src/vespa/searchcorespi/index/indexwriteutilities.h index 37193cce4d5..313ab3cc1c7 100644 --- a/searchcorespi/src/vespa/searchcorespi/index/indexwriteutilities.h +++ b/searchcorespi/src/vespa/searchcorespi/index/indexwriteutilities.h @@ -8,8 +8,7 @@ #include <vespa/searchlib/common/serialnum.h> #include <vespa/vespalib/stllike/string.h> -namespace searchcorespi { -namespace index { +namespace searchcorespi::index { /** * Utility class with functions to write aspects of an index to disk. @@ -40,7 +39,6 @@ struct IndexWriteUtilities search::SerialNum serialNum); }; -} // namespace index -} // namespace searchcorespi +} diff --git a/searchlib/src/apps/vespa-fileheader-inspect/vespa-fileheader-inspect.cpp b/searchlib/src/apps/vespa-fileheader-inspect/vespa-fileheader-inspect.cpp index 29c0a533fec..bdc841ab235 100644 --- a/searchlib/src/apps/vespa-fileheader-inspect/vespa-fileheader-inspect.cpp +++ b/searchlib/src/apps/vespa-fileheader-inspect/vespa-fileheader-inspect.cpp @@ -110,7 +110,6 @@ Application::Main() std::cerr << e.getMessage() << std::endl; return EXIT_FAILURE; } - file.Close(); if (_quiet) { printQuiet(header); diff --git a/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp b/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp index 8a6f1e08fa6..c77dfb2c2d2 100644 --- a/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp +++ b/searchlib/src/tests/attribute/tensorattribute/tensorattribute_test.cpp @@ -681,7 +681,6 @@ Fixture::get_file_header() vespalib::string file_name = attr_name + ".dat"; EXPECT_TRUE(file.OpenReadOnly(file_name.c_str())); (void) header.readFile(file); - file.Close(); return header; } diff --git a/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp b/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp index 6c78d185cfb..0fc42ae3fad 100644 --- a/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp +++ b/searchlib/src/tests/diskindex/fieldwriter/fieldwriter_test.cpp @@ -330,7 +330,6 @@ FileChecksum::FileChecksum(const vespalib::string &file_name) EVP_DigestUpdate(md_ctx.get(), buf.get(), thistime); remainder -= thistime; } - f.Close(); EVP_DigestFinal_ex(md_ctx.get(), &_digest[0], &_digest_len); assert(_digest_len > 0u && _digest_len <= EVP_MAX_MD_SIZE); } diff --git a/searchlib/src/tests/fileheadertk/fileheadertk_test.cpp b/searchlib/src/tests/fileheadertk/fileheadertk_test.cpp index 3662e371839..089650573e2 100644 --- a/searchlib/src/tests/fileheadertk/fileheadertk_test.cpp +++ b/searchlib/src/tests/fileheadertk/fileheadertk_test.cpp @@ -9,24 +9,7 @@ LOG_SETUP("fileheadertk_test"); using namespace search; -class Test : public vespalib::TestApp { -private: - void testVersionTags(); - -public: - int Main() override { - TEST_INIT("fileheadertk_test"); - - testVersionTags(); TEST_FLUSH(); - - TEST_DONE(); - } -}; - -TEST_APPHOOK(Test); - -void -Test::testVersionTags() +TEST("testVersionTags") { vespalib::FileHeader header; FileHeaderTk::addVersionTags(header); @@ -34,7 +17,6 @@ Test::testVersionTags() FastOS_File file; ASSERT_TRUE(file.OpenWriteOnlyTruncate("versiontags.dat")); EXPECT_EQUAL(header.getSize(), header.writeFile(file)); - file.Close(); EXPECT_EQUAL(8u, header.getNumTags()); EXPECT_TRUE(header.hasTag("version-arch")); @@ -46,3 +28,5 @@ Test::testVersionTags() EXPECT_TRUE(header.hasTag("version-tag")); EXPECT_TRUE(header.hasTag("version-pkg")); } + +TEST_MAIN() { TEST_RUN_ALL(); }
\ No newline at end of file diff --git a/searchlib/src/tests/transactionlog/translogclient_test.cpp b/searchlib/src/tests/transactionlog/translogclient_test.cpp index d3c3af3a9ca..fa0753373bf 100644 --- a/searchlib/src/tests/transactionlog/translogclient_test.cpp +++ b/searchlib/src/tests/transactionlog/translogclient_test.cpp @@ -967,7 +967,6 @@ TEST("test truncation after short read") { FastOS_File trfile(filename.c_str()); EXPECT_TRUE(trfile.OpenReadWrite(nullptr)); trfile.SetSize(trfile.getSize() - 1); - trfile.Close(); } { TransLogServer tlss(topdir.getDir(), 18377, ".", fileHeaderContext, domainConfig); diff --git a/searchlib/src/tests/util/rawbuf_test.cpp b/searchlib/src/tests/util/rawbuf_test.cpp index e24314336af..1963833947f 100644 --- a/searchlib/src/tests/util/rawbuf_test.cpp +++ b/searchlib/src/tests/util/rawbuf_test.cpp @@ -129,7 +129,7 @@ TEST("require that rawbuf can read from file") { buf.readFile(file, 100); EXPECT_EQUAL("foobarbaz", getString(buf)); - file.Close(); + ASSERT_TRUE(file.Close()); file.Delete(); } diff --git a/searchlib/src/tests/vespa-fileheader-inspect/vespa-fileheader-inspect_test.cpp b/searchlib/src/tests/vespa-fileheader-inspect/vespa-fileheader-inspect_test.cpp index 15c7e114761..7ea480bf542 100644 --- a/searchlib/src/tests/vespa-fileheader-inspect/vespa-fileheader-inspect_test.cpp +++ b/searchlib/src/tests/vespa-fileheader-inspect/vespa-fileheader-inspect_test.cpp @@ -17,7 +17,6 @@ bool writeHeader(const FileHeader &header, const vespalib::string &fileName) { if (!EXPECT_EQUAL(header.getSize(), header.writeFile(file))) { return false; } - file.Close(); return true; } @@ -30,7 +29,6 @@ vespalib::string readFile(const vespalib::string &fileName) { EXPECT_LESS(len, sizeof(buf)); // make sure we got everything vespalib::string str(buf, len); - file.Close(); return str; } diff --git a/staging_vespalib/src/tests/fileheader/fileheader_test.cpp b/staging_vespalib/src/tests/fileheader/fileheader_test.cpp index a174ba3ecb6..21e374e4f62 100644 --- a/staging_vespalib/src/tests/fileheader/fileheader_test.cpp +++ b/staging_vespalib/src/tests/fileheader/fileheader_test.cpp @@ -4,7 +4,6 @@ #include <vespa/vespalib/data/fileheader.h> #include <vespa/vespalib/data/databuffer.h> #include <vespa/fastos/file.h> -#include <iostream> using namespace vespalib; @@ -302,7 +301,7 @@ void Test::testBufferAccess() { DataBuffer buf; - uint32_t len = 0; + uint32_t len; { GenericHeader header; header.putTag(GenericHeader::Tag("foo", 6.9)); @@ -345,8 +344,6 @@ Test::testFileReader() buf[i] = (uint8_t)i; } EXPECT_EQUAL(256, file.Write2(buf, 256)); - - file.Close(); } { FastOS_File file; @@ -364,7 +361,7 @@ Test::testFileReader() } EXPECT_EQUAL(256u, sum); - file.Close(); + ASSERT_TRUE(file.Close()); file.Delete(); } } @@ -399,7 +396,7 @@ Test::testFileWriter() EXPECT_EQUAL(i, (uint32_t)buf[i]); } - file.Close(); + ASSERT_TRUE(file.Close()); file.Delete(); } } @@ -418,7 +415,6 @@ Test::testFileHeader() ASSERT_TRUE(file.OpenWriteOnlyTruncate("fileheader.tmp")); len = header.writeFile(file); EXPECT_EQUAL(len, header.getSize()); - file.Close(); } { FastOS_File file; @@ -440,8 +436,6 @@ Test::testFileHeader() header.putTag(FileHeader::Tag("baz", "999666")); EXPECT_EQUAL(len, header.getSize()); EXPECT_EQUAL(len, header.rewriteFile(file)); - - file.Close(); } { FileHeader header; @@ -450,7 +444,7 @@ Test::testFileHeader() ASSERT_TRUE(file.OpenReadOnly("fileheader.tmp")); EXPECT_EQUAL(len, header.readFile(file)); EXPECT_EQUAL(len, header.getSize()); - file.Close(); + ASSERT_TRUE(file.Close()); file.Delete(); EXPECT_TRUE(header.hasTag("foo")); @@ -575,34 +569,36 @@ Test::testRewriteErrors() header.putTag(FileHeader::Tag("foo", "bar")); uint32_t len = header.getSize(); - FastOS_File file; - ASSERT_TRUE(file.OpenWriteOnlyTruncate("fileheader.tmp")); - EXPECT_EQUAL(len, header.writeFile(file)); - file.Close(); - - ASSERT_TRUE(file.OpenReadWrite("fileheader.tmp")); - header.putTag(FileHeader::Tag("baz", "cox")); - EXPECT_TRUE(len != header.getSize()); - try { - header.rewriteFile(file); - EXPECT_TRUE(false); - } catch (IllegalHeaderException &e) { - EXPECT_EQUAL("Failed to rewrite resized header.", e.getMessage()); + { + FastOS_File file; + ASSERT_TRUE(file.OpenWriteOnlyTruncate("fileheader.tmp")); + EXPECT_EQUAL(len, header.writeFile(file)); + } + { + FastOS_File file; + ASSERT_TRUE(file.OpenReadWrite("fileheader.tmp")); + header.putTag(FileHeader::Tag("baz", "cox")); + EXPECT_TRUE(len != header.getSize()); + try { + header.rewriteFile(file); + EXPECT_TRUE(false); + } catch (IllegalHeaderException &e) { + EXPECT_EQUAL("Failed to rewrite resized header.", e.getMessage()); + } } - file.Close(); } void Test::testLayout() { - FastOS_File file; - const std::string fileName = TEST_PATH("fileheader.dat"); - ASSERT_TRUE(file.OpenReadOnly(fileName.c_str())); - FileHeader header; - uint32_t len = header.readFile(file); - EXPECT_EQUAL(len, header.getSize()); - file.Close(); + { + FastOS_File file; + const std::string fileName = TEST_PATH("fileheader.dat"); + ASSERT_TRUE(file.OpenReadOnly(fileName.c_str())); + uint32_t len = header.readFile(file); + EXPECT_EQUAL(len, header.getSize()); + } EXPECT_TRUE(header.hasTag("foo")); EXPECT_EQUAL(6.9, header.getTag("foo").asFloat()); @@ -621,7 +617,7 @@ Test::testReadSize(bool mapped) buf.writeInt32(21); buf.writeInt32(GenericHeader::VERSION); buf.writeInt32(1); - uint32_t headerLen = 0u; + uint32_t headerLen; if (mapped) { GenericHeader::MMapReader reader(buf.getData(), buf.getDataLen()); headerLen = FileHeader::readSize(reader); |