| 469 | } |
| 470 | |
| 471 | void GenericFileSystemTest::TestMoveDir(FileSystem* fs) { |
| 472 | if (!allow_move_dir()) { |
| 473 | GTEST_SKIP() << "Filesystem doesn't allow moving directories"; |
| 474 | } |
| 475 | |
| 476 | ASSERT_OK(fs->CreateDir("AB/CD")); |
| 477 | ASSERT_OK(fs->CreateDir("EF")); |
| 478 | CreateFile(fs, "AB/abc", "abc data"); |
| 479 | CreateFile(fs, "AB/CD/def", "def data"); |
| 480 | CreateFile(fs, "EF/ghi", "ghi data"); |
| 481 | AssertAllDirs(fs, {"AB", "AB/CD", "EF"}); |
| 482 | AssertAllFiles(fs, {"AB/CD/def", "AB/abc", "EF/ghi"}); |
| 483 | |
| 484 | // Move inside root dir |
| 485 | ASSERT_OK(fs->Move("AB", "GH")); |
| 486 | AssertAllDirs(fs, {"EF", "GH", "GH/CD"}); |
| 487 | AssertAllFiles(fs, {"EF/ghi", "GH/CD/def", "GH/abc"}); |
| 488 | |
| 489 | // Move out of root dir |
| 490 | ASSERT_OK(fs->Move("GH", "EF/IJ")); |
| 491 | AssertAllDirs(fs, {"EF", "EF/IJ", "EF/IJ/CD"}); |
| 492 | AssertAllFiles(fs, {"EF/IJ/CD/def", "EF/IJ/abc", "EF/ghi"}); |
| 493 | |
| 494 | // Move back into root dir |
| 495 | ASSERT_OK(fs->Move("EF/IJ", "KL")); |
| 496 | AssertAllDirs(fs, {"EF", "KL", "KL/CD"}); |
| 497 | AssertAllFiles(fs, {"EF/ghi", "KL/CD/def", "KL/abc"}); |
| 498 | |
| 499 | // Overwrite file with directory => untested (implementation-dependent) |
| 500 | |
| 501 | // Identical source and destination: allowed to succeed or raise IOError, |
| 502 | // but should not lose data. |
| 503 | Status st = fs->Move("KL", "KL"); |
| 504 | if (!st.ok()) { |
| 505 | ASSERT_RAISES(IOError, st); |
| 506 | } |
| 507 | AssertAllDirs(fs, {"EF", "KL", "KL/CD"}); |
| 508 | AssertAllFiles(fs, {"EF/ghi", "KL/CD/def", "KL/abc"}); |
| 509 | |
| 510 | // Cannot move directory inside itself |
| 511 | ASSERT_RAISES(IOError, fs->Move("KL", "KL/ZZ")); |
| 512 | |
| 513 | // Contents didn't change |
| 514 | AssertAllDirs(fs, {"EF", "KL", "KL/CD"}); |
| 515 | AssertFileContents(fs, "KL/abc", "abc data"); |
| 516 | AssertFileContents(fs, "KL/CD/def", "def data"); |
| 517 | |
| 518 | // Destination is a non-empty directory |
| 519 | if (!allow_move_dir_over_non_empty_dir()) { |
| 520 | ASSERT_RAISES(IOError, fs->Move("KL", "EF")); |
| 521 | AssertAllDirs(fs, {"EF", "KL", "KL/CD"}); |
| 522 | AssertAllFiles(fs, {"EF/ghi", "KL/CD/def", "KL/abc"}); |
| 523 | } else { |
| 524 | // In some filesystems such as HDFS, this operation is interpreted |
| 525 | // as with the Unix `mv` command, i.e. move KL *inside* EF. |
| 526 | ASSERT_OK(fs->Move("KL", "EF")); |
| 527 | AssertAllDirs(fs, {"EF", "EF/KL", "EF/KL/CD"}); |
| 528 | AssertAllFiles(fs, {"EF/KL/CD/def", "EF/KL/abc", "EF/ghi"}); |
nothing calls this directly
no test coverage detected