View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0003772 | OpenFOAM | Bug | public | 2021-12-28 12:09 | 2021-12-28 15:17 |
Reporter | niklas.wikstrom | Assigned To | henry | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | resolved | Resolution | fixed | ||
Platform | x86_64 | OS | fedora | OS Version | 35 |
Product Version | dev | ||||
Fixed in Version | dev | ||||
Summary | 0003772: Foam::cp() (POSIX) always returns false for file copy | ||||
Description | When using Foam::cp() to copy a file, the function always returns false. This appears to be a wrong behaviour, since it makes it more difficult to assert success. The error might(!) be that std::ifstream::rdbuf() does not set the eof() flag: srcStream.eof() returns 0 both before and after the << srcStream.rdbuf() | ||||
Steps To Reproduce | Build and run the attached application # ./testFiles someFile copiedFile | ||||
Additional Information | Also tested on the current docker image release. | ||||
Tags | No tags attached. | ||||
|
|
|
What do you propose to resolve this issue? |
|
I looked into the options for error handling and there is nothing obvious with is system independent. When we move to C++17 we will replace the current implementation of cp with filesystem::copy_file which provides error handling but in the meantime I think the best we can do is remove the EOF test. |
|
The attached variant is probably naive, but it is at least faster (and it can be "eof checked"). I suppose one can remove the check altoghether, since it is not used in recursive cp (same function) anyway. This is ofcourse a tiny issue, but I wanted to report it, since I stumbled on it for a while. Happy new year! testFiles.C (2,237 bytes)
/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2019 EQUA Simulation AB \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>. Application testFiles Description \*---------------------------------------------------------------------------*/ #include "argList.H" #include "OSspecific.H" #include "clockTime.H" #include <fstream> using namespace Foam; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // Main program: int main(int argc, char *argv[]) { argList::validArgs.insert("file1"); argList::validArgs.insert("file2"); argList args(argc, argv, false, true); const fileName file1 = args[1]; const fileName file2("out1"); const fileName file3("out2"); clockTime T; T.timeIncrement(); Foam::cp(file1,file2); Info << "Foam::cp elapsed time = " << T.timeIncrement() << endl; std::ifstream f1(file1); std::ofstream f3(file3); const size_t L = 256; char* buffer = new char[L]; while (!f1.eof()) { f1.read(buffer, L); f3.write(buffer, f1.gcount()); } Info << "Buffered rd/wt elapsed time = " << T.timeIncrement() << endl; Info << "after rdbuf eof = " << f1.eof() << endl; return 0; } // ************************************************************************* // |
|
Resolved by commit 9f6e8e5effac9804af850bbb67bef660713d9c40 |
Date Modified | Username | Field | Change |
---|---|---|---|
2021-12-28 12:09 | niklas.wikstrom | New Issue | |
2021-12-28 12:09 | niklas.wikstrom | File Added: testFiles.tgz | |
2021-12-28 13:18 | henry | Note Added: 0012351 | |
2021-12-28 14:23 | henry | Note Added: 0012352 | |
2021-12-28 14:31 | niklas.wikstrom | File Added: testFiles.C | |
2021-12-28 14:31 | niklas.wikstrom | Note Added: 0012353 | |
2021-12-28 15:17 | henry | Assigned To | => henry |
2021-12-28 15:17 | henry | Status | new => resolved |
2021-12-28 15:17 | henry | Resolution | open => fixed |
2021-12-28 15:17 | henry | Fixed in Version | => dev |
2021-12-28 15:17 | henry | Note Added: 0012354 |