diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2023-07-23 10:53:10 +0000 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2023-07-25 07:57:52 +0000 |
commit | 59192dd1d07356497ea311b7f0d6a3b50f726f13 (patch) | |
tree | 5f9492d5ce9dd1e4b0125f7d6318127c30a964d6 /vespalib | |
parent | 78a211072a21ec5f368b99bce19c1b703d98152d (diff) |
Prefer std::filesystem::exists over FastOS_StatInfo
Diffstat (limited to 'vespalib')
-rw-r--r-- | vespalib/src/tests/fastlib/io/bufferedfiletest.cpp | 42 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/time.cpp | 5 | ||||
-rw-r--r-- | vespalib/src/vespa/vespalib/util/time.h | 4 |
3 files changed, 20 insertions, 31 deletions
diff --git a/vespalib/src/tests/fastlib/io/bufferedfiletest.cpp b/vespalib/src/tests/fastlib/io/bufferedfiletest.cpp index edf38122202..17f295c04d6 100644 --- a/vespalib/src/tests/fastlib/io/bufferedfiletest.cpp +++ b/vespalib/src/tests/fastlib/io/bufferedfiletest.cpp @@ -3,22 +3,22 @@ #include <vespa/vespalib/testkit/test_kit.h> #include <filesystem> +namespace fs = std::filesystem; namespace { void remove_testfiles() { - std::filesystem::remove(std::filesystem::path("testfile1")); - std::filesystem::remove(std::filesystem::path("testfile2")); - std::filesystem::remove(std::filesystem::path("testfile3")); - std::filesystem::remove(std::filesystem::path("testfile4")); - std::filesystem::remove(std::filesystem::path("testfile5")); + fs::remove(fs::path("testfile1")); + fs::remove(fs::path("testfile2")); + fs::remove(fs::path("testfile3")); + fs::remove(fs::path("testfile4")); + fs::remove(fs::path("testfile5")); } } TEST("main") { int value = 0; - FastOS_StatInfo statInfo; remove_testfiles(); @@ -30,11 +30,7 @@ TEST("main") { bufFile.addNum(1,10,' '); ASSERT_TRUE(bufFile.CheckedWrite("\n",1)); ASSERT_TRUE(bufFile.Close()); - FastOS_File::Stat("testfile1", &statInfo); - if (statInfo._size != 11) { - printf (" -- FAILURE\n\n"); - TEST_FATAL("exit 1"); - } + ASSERT_EQUAL(11u, fs::file_size(fs::path("testfile1"))); printf (" -- SUCCESS\n\n"); // test 2 @@ -44,11 +40,7 @@ TEST("main") { memset(buf,0xff,8192); ASSERT_TRUE(bufFile.CheckedWrite(buf,4095)); // write almost 4K ASSERT_TRUE(bufFile.Close()); - FastOS_File::Stat("testfile2", &statInfo); - if (statInfo._size != 4095) { - printf (" -- FAILURE\n\n"); - TEST_FATAL("exit 1"); - } + ASSERT_EQUAL(4095u, fs::file_size(fs::path("testfile2"))); printf (" -- SUCCESS\n\n"); // test 3 @@ -56,11 +48,7 @@ TEST("main") { bufFile.WriteOpen("testfile3"); ASSERT_TRUE(bufFile.CheckedWrite(buf,4096)); // write exactly 4K ASSERT_TRUE(bufFile.Close()); - FastOS_File::Stat("testfile3", &statInfo); - if (statInfo._size != 4096) { - printf (" -- FAILURE\n\n"); - TEST_FATAL("exit 1"); - } + ASSERT_EQUAL(4096u, fs::file_size(fs::path("testfile3"))); printf (" -- SUCCESS\n\n"); // test 4 @@ -68,11 +56,7 @@ TEST("main") { bufFile.WriteOpen("testfile4"); ASSERT_TRUE(bufFile.CheckedWrite(buf,4097)); // write a bit over 4K ASSERT_TRUE(bufFile.Close()); - FastOS_File::Stat("testfile4", &statInfo); - if (statInfo._size != 4097) { - printf (" -- FAILURE\n\n"); - TEST_FATAL("exit 1"); - } + ASSERT_EQUAL(4097u, fs::file_size(fs::path("testfile4"))); printf (" -- SUCCESS\n\n"); // test 5 @@ -86,11 +70,7 @@ TEST("main") { ASSERT_TRUE(bufFile.CheckedWrite("\n",1)); } ASSERT_TRUE(bufFile.Close()); - FastOS_File::Stat("testfile5", &statInfo); - if (statInfo._size != 610000) { - printf (" -- FAILURE\n\n"); - TEST_FATAL("exit 1"); - } + ASSERT_EQUAL(610000u, fs::file_size(fs::path("testfile5"))); printf (" -- SUCCESS\n\n"); remove_testfiles(); diff --git a/vespalib/src/vespa/vespalib/util/time.cpp b/vespalib/src/vespa/vespalib/util/time.cpp index dd4972b1c21..a6129d10bfa 100644 --- a/vespalib/src/vespa/vespalib/util/time.cpp +++ b/vespalib/src/vespa/vespalib/util/time.cpp @@ -62,6 +62,11 @@ to_string(system_time time) { return to_string(time.time_since_epoch()); } +string +to_string(file_time time) { + return to_string(time.time_since_epoch()); +} + steady_time saturated_add(steady_time time, duration diff) { auto td = time.time_since_epoch(); using dur_t = decltype(td); diff --git a/vespalib/src/vespa/vespalib/util/time.h b/vespalib/src/vespa/vespalib/util/time.h index 10077a0b49a..6df65554299 100644 --- a/vespalib/src/vespa/vespalib/util/time.h +++ b/vespalib/src/vespa/vespalib/util/time.h @@ -35,6 +35,9 @@ using steady_time = std::chrono::steady_clock::time_point; using system_clock = std::chrono::system_clock; using system_time = std::chrono::system_clock::time_point; +using file_clock = std::chrono::file_clock; +using file_time = std::chrono::file_clock::time_point; + using duration = std::chrono::nanoseconds; constexpr double to_s(duration d) { @@ -73,6 +76,7 @@ constexpr duration from_timespec(const timespec & ts) { } vespalib::string to_string(system_time time); +vespalib::string to_string(file_time time); steady_time saturated_add(steady_time time, duration diff); |