MCPcopy Create free account
hub / github.com/apache/arrow / TestCopyFile

Method TestCopyFile

cpp/src/arrow/filesystem/test_util.cc:534–589  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

532}
533
534void GenericFileSystemTest::TestCopyFile(FileSystem* fs) {
535 ASSERT_OK(fs->CreateDir("AB/CD"));
536 ASSERT_OK(fs->CreateDir("EF"));
537 CreateFile(fs, "AB/abc", "data");
538 std::vector<std::string> all_dirs{"AB", "AB/CD", "EF"};
539
540 // Copy into root dir
541 ASSERT_OK(fs->CopyFile("AB/abc", "def"));
542 AssertAllDirs(fs, all_dirs);
543 AssertAllFiles(fs, {"AB/abc", "def"});
544
545 // Copy out of root dir
546 ASSERT_OK(fs->CopyFile("def", "EF/ghi"));
547 AssertAllDirs(fs, all_dirs);
548 AssertAllFiles(fs, {"AB/abc", "EF/ghi", "def"});
549
550 // Overwrite contents for one file => other data shouldn't change
551 CreateFile(fs, "def", "other data");
552 AssertFileContents(fs, "AB/abc", "data");
553 AssertFileContents(fs, "def", "other data");
554 AssertFileContents(fs, "EF/ghi", "data");
555
556 // Destination is a file => clobber
557 ASSERT_OK(fs->CopyFile("def", "AB/abc"));
558 AssertAllDirs(fs, all_dirs);
559 AssertAllFiles(fs, {"AB/abc", "EF/ghi", "def"});
560 AssertFileContents(fs, "AB/abc", "other data");
561 AssertFileContents(fs, "def", "other data");
562 AssertFileContents(fs, "EF/ghi", "data");
563
564 // Identical source and destination: allowed to succeed or raise IOError,
565 // but should not lose data.
566 Status st = fs->CopyFile("def", "def");
567 if (!st.ok()) {
568 ASSERT_RAISES(IOError, st);
569 }
570 AssertAllFiles(fs, {"AB/abc", "EF/ghi", "def"});
571 AssertFileContents(fs, "def", "other data");
572
573 // Source doesn't exist
574 ASSERT_RAISES(IOError, fs->CopyFile("abc", "xxx"));
575 if (!allow_write_file_over_dir()) {
576 // Destination is a non-empty directory
577 ASSERT_RAISES(IOError, fs->CopyFile("def", "AB"));
578 }
579 if (!have_implicit_directories()) {
580 // Parent destination doesn't exist
581 ASSERT_RAISES(IOError, fs->CopyFile("AB/abc", "XX/mno"));
582 }
583 // Parent destination is not a directory ("def" is a file)
584 if (!allow_write_implicit_dir_over_file()) {
585 ASSERT_RAISES(IOError, fs->CopyFile("AB/abc", "def/mno"));
586 }
587 AssertAllDirs(fs, all_dirs);
588 AssertAllFiles(fs, {"AB/abc", "EF/ghi", "def"});
589}
590
591void GenericFileSystemTest::TestCopyFiles(FileSystem* fs) {

Callers

nothing calls this directly

Calls 10

CreateFileFunction · 0.85
AssertAllDirsFunction · 0.85
AssertAllFilesFunction · 0.85
AssertFileContentsFunction · 0.70
CreateDirMethod · 0.45
CopyFileMethod · 0.45
okMethod · 0.45

Tested by

no test coverage detected