|
Boost : |
Subject: Re: [boost] [filesystems]
From: Florian Lindner (mailinglists_at_[hidden])
Date: 2019-03-14 11:31:16
Am 14.03.19 um 11:19 schrieb Adam Majer via Boost:
> On 3/14/19 9:31 AM, Florian Lindner via Boost wrote:
>> However, I have no idea how that could happen. I use the rename, so
>> that a reading process never sees an empty file, but only no file or
>> filed with info. Is there any race involved between ofs.close() and
>> fs:rename()? The code was executed on a distributed network
>> filesystem (lustre).
>>
>> Any ideas anyone?
>
> `strace -e trace=%file,close program` and complain to file system for
> not working. This doesn't seem to have anything to do with
> boost::filesystem, more with the underlying filesystem.
>
> It's not close that matters, but open. Your program should work just fine without the explicit close.
Hey,
I was not trying to blame boost::filesystem, just trying to get ideas what can cause this.
I have modified the code to:
{
namespace fs = boost::filesystem;
auto path = getFilename();
auto tmp = fs::path(path + "~");
fs::create_directories(tmp.parent_path());
boost::iostreams::stream<boost::iostreams::file_descriptor_sink> ofs(tmp);
ofs << info;
::fdatasync(ofs->handle());
ofs.close();
fs::rename(tmp, path);
}
maybe the fdatasync helps. strace is complicated, as I haven't managend to reliable reproduce the bug.
Best,
Florian
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk