diff --git a/starboard/loader_app/drain_file.cc b/starboard/loader_app/drain_file.cc index c84d7ace36bc3..dc0b9df709141 100644 --- a/starboard/loader_app/drain_file.cc +++ b/starboard/loader_app/drain_file.cc @@ -98,7 +98,8 @@ void Rank(const char* dir, char* app_key, size_t len) { std::vector filenames = FindAllWithPrefix(dir, kDrainFilePrefix); - std::remove_if(filenames.begin(), filenames.end(), IsExpired); + filenames.erase(std::remove_if(filenames.begin(), filenames.end(), IsExpired), + filenames.end()); if (filenames.empty()) return; diff --git a/starboard/loader_app/drain_file_test.cc b/starboard/loader_app/drain_file_test.cc index a1e0f07ca55bb..82658295e7b7c 100644 --- a/starboard/loader_app/drain_file_test.cc +++ b/starboard/loader_app/drain_file_test.cc @@ -174,6 +174,29 @@ TEST_F(DrainFileTest, SunnyDayRankCorrectlyRanksFiles) { EXPECT_TRUE(SbFileDelete(later_and_greatest.path().c_str())); } +// Ranking drain files should ignore expired files. +TEST_F(DrainFileTest, SunnyDayRankCorrectlyIgnoresExpired) { + const SbTime timestamp = SbTimeGetNow(); + + ScopedDrainFile early_and_expired(GetTempDir(), "a", + timestamp - kDrainFileMaximumAge); + ScopedDrainFile later_and_least(GetTempDir(), "c", timestamp); + ScopedDrainFile later_and_greatest(GetTempDir(), "b", + timestamp + kDrainFileAgeUnit); + + std::vector result(kSbFileMaxName); + + EXPECT_TRUE(DrainFileRankAndCheck(GetTempDir(), "c")); + EXPECT_TRUE(SbFileDelete(later_and_least.path().c_str())); + + EXPECT_TRUE(DrainFileRankAndCheck(GetTempDir(), "b")); + EXPECT_TRUE(SbFileDelete(later_and_greatest.path().c_str())); + + // Even though "a" is still there Rank should find nothing since it's expired. + EXPECT_TRUE(DrainFileRankAndCheck(GetTempDir(), "")); + EXPECT_TRUE(SbFileDelete(early_and_expired.path().c_str())); +} + // All files in the directory should be cleared except for drain files with an // app key matching the provided app key. TEST_F(DrainFileTest, SunnyDayPrepareDirectory) {