Bug 103793 - Error out on save if the file we had opened has been modified since we opened it
Summary: Error out on save if the file we had opened has been modified since we opened it
Status: RESOLVED FIXED
Alias: None
Product: poppler
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: Other All
: medium normal
Assignee: poppler-bugs
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-11-17 13:45 UTC by Albert Astals Cid
Modified: 2017-12-11 23:27 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:


Attachments
Error out on save if file has changed since we opened it (2.80 KB, patch)
2017-11-17 13:45 UTC, Albert Astals Cid
Details | Splinter Review
win version for Error out on save if file has changed since we opened it (1.40 KB, patch)
2017-11-27 11:09 UTC, Thomas Freitag
Details | Splinter Review

Description Albert Astals Cid 2017-11-17 13:45:48 UTC
Created attachment 135556 [details] [review]
Error out on save if file has changed since we opened it

In poppler we keep the fd of the file open so the XRef+FileStream can locate objects. This is good since we save lots of memory for not having everything on memory all the time, but that means that when we want to save we need the file to be exactly the same as it was when we created the XRef otherwise we're going to be reading from the wrong part of the "new" file.

The attached patch checks the modification time of the fd and errors out if it has changed since we opened the file.

It's a stub in windows since my understanding there is that you can't edit a file that is open by another program.
Comment 1 Thomas Freitag 2017-11-20 14:58:52 UTC
(In reply to Albert Astals Cid from comment #0)
> It's a stub in windows since my understanding there is that you can't edit a
> file that is open by another program.

You are not true, Albert. The files, at least with poppler, are opened with sharing enabled, i.e.

  HANDLE handle = CreateFileA(fileName->getCString(),
                              GENERIC_READ,
-->                           FILE_SHARE_READ | FILE_SHARE_WRITE,
                              NULL,
                              OPEN_EXISTING,
                              FILE_ATTRIBUTE_NORMAL, NULL);

That means that other processes are allowed to read and even write to the same file!
But we can probably do the same under windows with GetFileTime, using the lpLastWriteTime parameter.
Comment 2 Albert Astals Cid 2017-11-20 20:51:38 UTC
ok, then someone will have to provide the windows codepath i guess.
Comment 3 Thomas Freitag 2017-11-27 11:09:49 UTC
Created attachment 135735 [details] [review]
win version for Error out on save if file has changed since we opened it

Here the windows codepath.
Comment 4 Albert Astals Cid 2017-12-02 11:43:47 UTC
Cool, i'll push this in a week if noone disagrees :)
Comment 5 Albert Astals Cid 2017-12-11 23:27:00 UTC
Pushed


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.