| 290 | } |
| 291 | |
| 292 | void GenericFileSystemTest::TestDeleteDirContents(FileSystem* fs) { |
| 293 | if (have_flaky_directory_tree_deletion()) GTEST_SKIP() << "Flaky directory deletion"; |
| 294 | |
| 295 | ASSERT_OK(fs->CreateDir("AB/CD/EF")); |
| 296 | ASSERT_OK(fs->CreateDir("AB/GH/IJ")); |
| 297 | CreateFile(fs, "AB/abc", ""); |
| 298 | CreateFile(fs, "AB/CD/def", ""); |
| 299 | CreateFile(fs, "AB/CD/EF/ghi", ""); |
| 300 | ASSERT_OK(fs->DeleteDirContents("AB/CD")); |
| 301 | ASSERT_OK(fs->DeleteDirContents("AB/GH/IJ")); |
| 302 | |
| 303 | AssertAllDirs(fs, {"AB", "AB/CD", "AB/GH", "AB/GH/IJ"}); |
| 304 | AssertAllFiles(fs, {"AB/abc"}); |
| 305 | |
| 306 | // Calling DeleteDirContents on root directory is disallowed |
| 307 | ASSERT_RAISES(Invalid, fs->DeleteDirContents("")); |
| 308 | ASSERT_RAISES(Invalid, fs->DeleteDirContents("/")); |
| 309 | AssertAllDirs(fs, {"AB", "AB/CD", "AB/GH", "AB/GH/IJ"}); |
| 310 | AssertAllFiles(fs, {"AB/abc"}); |
| 311 | |
| 312 | // Not a directory |
| 313 | CreateFile(fs, "abc", ""); |
| 314 | ASSERT_RAISES(IOError, fs->DeleteDirContents("abc")); |
| 315 | ASSERT_RAISES(IOError, fs->DeleteDirContents("abc", /*missing_dir_ok=*/true)); |
| 316 | AssertAllFiles(fs, {"AB/abc", "abc"}); |
| 317 | |
| 318 | // Missing directory |
| 319 | ASSERT_RAISES(IOError, fs->DeleteDirContents("missing")); |
| 320 | ASSERT_OK(fs->DeleteDirContents("missing", /*missing_dir_ok=*/true)); |
| 321 | } |
| 322 | |
| 323 | void GenericFileSystemTest::TestDeleteRootDirContents(FileSystem* fs) { |
| 324 | if (have_flaky_directory_tree_deletion()) GTEST_SKIP() << "Flaky directory deletion"; |
nothing calls this directly
no test coverage detected