Bug 183051

Summary: [Curl] Cookie Database files are wrongfully getting deleted when the database is opened
Product: WebKit Reporter: Christopher Reid <chris.reid>
Component: PlatformAssignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: achristensen, annulen, Basuke.Suzuki, bfulgham, commit-queue, don.olmstead, ews-watchlist, galpeter, pvollan, webkit-bug-importer, youennf
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch
none
Patch for landing none

Description Christopher Reid 2018-02-22 12:12:25 PST
The file stat logic in CookieJarDB::checkDatabaseCorruptionAndRemoveIfNeeded is backwards causing persistence issues. The database is wrongfully deleted when opened because it thinks it's corrupted.
Comment 1 Christopher Reid 2018-02-22 12:19:40 PST
Created attachment 334465 [details]
Patch
Comment 2 Don Olmstead 2018-02-23 12:51:10 PST
Comment on attachment 334465 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=334465&action=review

LGTM. I'm not sure how liberally we should be using auto or not.

> Source/WebCore/platform/network/curl/CookieJarDB.cpp:166
> +    FileSystem::PlatformFileHandle handle = FileSystem::openFile(getCorruptionMarkerPath(), FileSystem::FileOpenMode::Write);

Maybe auto here?
Comment 3 Christopher Reid 2018-02-23 14:01:36 PST
(In reply to Don Olmstead from comment #2)
> Comment on attachment 334465 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=334465&action=review
> 
> LGTM. I'm not sure how liberally we should be using auto or not.
> 
> > Source/WebCore/platform/network/curl/CookieJarDB.cpp:166
> > +    FileSystem::PlatformFileHandle handle = FileSystem::openFile(getCorruptionMarkerPath(), FileSystem::FileOpenMode::Write);
> 
> Maybe auto here?

It looks like auto is used quite a bit with openFile in the FileSystem implementation files so it makes sense to use it here too.
I'll update the patch.
Comment 4 Christopher Reid 2018-02-23 14:25:28 PST
Created attachment 334547 [details]
Patch
Comment 5 Per Arne Vollan 2018-02-23 15:15:10 PST
Comment on attachment 334547 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=334547&action=review

R=me.

> Source/WebCore/platform/network/curl/CookieJarDB.cpp:167
> +    FileSystem::closeFile(handle);

Should we check whether 'handle' is valid before closing?
Comment 6 Christopher Reid 2018-02-23 15:55:02 PST
Thanks for the review!

(In reply to Per Arne Vollan from comment #5)
> Comment on attachment 334547 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=334547&action=review
> 
> R=me.
> 
> > Source/WebCore/platform/network/curl/CookieJarDB.cpp:167
> > +    FileSystem::closeFile(handle);
> 
> Should we check whether 'handle' is valid before closing?

Ah, right now all the closeFile implementations have a check but it seems safer to have a check here too in case more functionality is added to that file.
Comment 7 Christopher Reid 2018-02-23 16:03:52 PST
Created attachment 334550 [details]
Patch for landing
Comment 8 WebKit Commit Bot 2018-02-23 18:01:41 PST
Comment on attachment 334550 [details]
Patch for landing

Clearing flags on attachment: 334550

Committed r228971: <https://trac.webkit.org/changeset/228971>
Comment 9 WebKit Commit Bot 2018-02-23 18:01:42 PST
All reviewed patches have been landed.  Closing bug.
Comment 10 Radar WebKit Bug Importer 2018-02-23 18:02:59 PST
<rdar://problem/37846254>