2

We see a strange issue sometimes when we call boost::filesystem::copy() to copy a file from a normal local partition to one hosted on Lustre. Normally if we do cp of files we notice that the destination file exists correctly and is available immediately after cp returns, however with the boost operation, when it returns, the file may be all there or not (at the destination.)

Looking through the boost code, I see:

    if ( ::close( infile) < 0 ) sz_read = -1;
    if ( ::close( outfile) < 0 ) sz_read = -1;

I'm wondering if this is correct, will this correctly flush the file to the destination, or should this call ::fclose() to explicitly flush and then close the file? I don't see any explicit ::fflush() calls preceding the close, so not sure if the file really is flushed to the destination correctly...

4

1 回答 1

2

这取决于文件的打开方式。如果它是使用特定操作系统打开的::open,那么它必须使用特定操作系统关闭::close。如果它是用 来打开的fopen,那么它必须用 来关闭fclose。如果它是用 std::fstream::open(或 an 的构造函数fstream)打开的,那么它必须通过调用close对象来关闭。

Boost 显然正在使用低级系统调用。在这种情况下,没有需要刷新的缓冲区。对于fcloseor fstream::close,关闭将自动刷新缓冲区。不需要显式刷新。

于 2013-09-19T10:50:31.073 回答