MCPcopy Create free account
hub / github.com/OpenFOAM/OpenFOAM-dev / cp

Function cp

src/OSspecific/POSIX/POSIX.C:739–869  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

737
738
739bool Foam::cp(const fileName& src, const fileName& dest, const bool followLink)
740{
741 if (POSIX::debug)
742 {
743 Pout<< FUNCTION_NAME << " : src:" << src << " dest:" << dest << endl;
744 if ((POSIX::debug & 2) && !Pstream::master())
745 {
746 error::printStack(Pout);
747 }
748 }
749 // Make sure source exists.
750 if (!exists(src))
751 {
752 return false;
753 }
754
755 const fileName::Type srcType = src.type(followLink);
756
757 fileName destFile(dest);
758
759 // Check type of source file.
760 if (srcType == fileName::FILE)
761 {
762 // If dest is a directory, create the destination file name.
763 if (destFile.type() == fileName::DIRECTORY)
764 {
765 destFile = destFile/src.name();
766 }
767
768 // Make sure the destination directory exists.
769 if (!isDir(destFile.path()) && !mkDir(destFile.path()))
770 {
771 return false;
772 }
773
774 // Open and check streams.
775 std::ifstream srcStream(src.c_str());
776 if (!srcStream)
777 {
778 return false;
779 }
780
781 std::ofstream destStream(destFile.c_str());
782 if (!destStream)
783 {
784 return false;
785 }
786
787 // Copy character data.
788 char ch;
789 while (srcStream.get(ch))
790 {
791 destStream.put(ch);
792 }
793
794 // Final check.
795 if (!srcStream.eof() || !destStream)
796 {

Callers 1

updateFileFunction · 0.50

Calls 13

getMethod · 0.80
eofMethod · 0.80
printStackFunction · 0.70
existsFunction · 0.70
isDirFunction · 0.70
mkDirFunction · 0.70
lnFunction · 0.70
forAllFunction · 0.50
typeMethod · 0.45
nameMethod · 0.45
pathMethod · 0.45
componentMethod · 0.45

Tested by

no test coverage detected