View Issue Details

IDProjectCategoryView StatusLast Update
0003772OpenFOAMBugpublic2021-12-28 15:17
Reporterniklas.wikstromAssigned Tohenry 
Status resolvedResolutionfixed 
Platformx86_64OSfedoraOS Version35
Product Versiondev 
Fixed in Versiondev 
Summary0003772: Foam::cp() (POSIX) always returns false for file copy
DescriptionWhen 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 ReproduceBuild and run the attached application

# ./testFiles someFile copiedFile
Additional InformationAlso tested on the current docker image release.
TagsNo tags attached.



2021-12-28 12:09


testFiles.tgz (1,101 bytes)


2021-12-28 13:18

manager   ~0012351

What do you propose to resolve this issue?


2021-12-28 14:23

manager   ~0012352

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.


2021-12-28 14:31

reporter   ~0012353

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)


2021-12-28 15:17

manager   ~0012354

Resolved by commit 9f6e8e5effac9804af850bbb67bef660713d9c40

Issue History

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