Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Issue 2545283002: A robust base::DeleteFile.

Created:
4 years ago by grt (UTC plus 2)
Modified:
3 years, 9 months ago
CC:
chromium-reviews, vmpstr+watch_chromium.org, Scott Hess - ex-Googler, jschuh
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

A robust base::DeleteFile. Win32's DeleteFile marks a file for deletion, but makes no guarantees that it disappears. This makes recursive deletes flaky as well as delete-create or delete-move pairs. This flakines leads to install and update failures, especially when scanners are active on the machine. This CL contains a robust file and directory deletion strategy that works as one would expect (delete means delete). Additionally, this CL removes wildcard support from the Windows implementation of base::DeleteFile, resolving a long-standing TODO. BUG=571906, 674135

Patch Set 1 #

Patch Set 2 : clang fix; simplification #

Total comments: 17

Patch Set 3 : shess and jschuh comments #

Patch Set 4 : search for temp #

Patch Set 5 : cl format and logging to find failure on bot #

Total comments: 24

Patch Set 6 : even better #

Patch Set 7 : with metrics and global retry #

Total comments: 4

Patch Set 8 : comment tweaks #

Patch Set 9 : sync to position 437832 #

Total comments: 15

Patch Set 10 : test fixes #

Unified diffs Side-by-side diffs Delta from patch set Stats (+672 lines, -194 lines) Patch
M base/files/file_util.h View 1 2 3 4 5 6 7 8 9 1 chunk +58 lines, -8 lines 0 comments Download
M base/files/file_util_unittest.cc View 1 2 3 4 5 6 7 8 9 42 chunks +133 lines, -140 lines 0 comments Download
M base/files/file_util_win.cc View 1 2 3 4 5 6 7 8 9 3 chunks +481 lines, -46 lines 0 comments Download

Depends on Patchset:

Messages

Total messages: 77 (46 generated)
grt (UTC plus 2)
Hi Will. Do you have time to put some eyes on this? I was motivated ...
4 years ago (2016-12-03 21:44:31 UTC) #4
grt (UTC plus 2)
+cc shess and jschuh https://codereview.chromium.org/2545283002/diff/20001/base/files/file_util_win.cc File base/files/file_util_win.cc (right): https://codereview.chromium.org/2545283002/diff/20001/base/files/file_util_win.cc#newcode212 base/files/file_util_win.cc:212: !IsMountPointOrSymlink(to_delete, basic_info) && !DeleteContents(path)) { ...
4 years ago (2016-12-04 08:52:06 UTC) #10
jschuh
Sadly, I'm not entirely surprised it's this complicated. https://codereview.chromium.org/2545283002/diff/20001/base/files/file_util_win.cc File base/files/file_util_win.cc (right): https://codereview.chromium.org/2545283002/diff/20001/base/files/file_util_win.cc#newcode212 base/files/file_util_win.cc:212: !IsMountPointOrSymlink(to_delete, ...
4 years ago (2016-12-04 14:10:46 UTC) #14
grt (UTC plus 2)
https://codereview.chromium.org/2545283002/diff/20001/base/files/file_util_win.cc File base/files/file_util_win.cc (right): https://codereview.chromium.org/2545283002/diff/20001/base/files/file_util_win.cc#newcode212 base/files/file_util_win.cc:212: !IsMountPointOrSymlink(to_delete, basic_info) && !DeleteContents(path)) { On 2016/12/04 14:10:46, jschuh ...
4 years ago (2016-12-04 21:31:48 UTC) #15
grt (UTC plus 2)
https://codereview.chromium.org/2545283002/diff/20001/base/files/file_util_win.cc File base/files/file_util_win.cc (right): https://codereview.chromium.org/2545283002/diff/20001/base/files/file_util_win.cc#newcode304 base/files/file_util_win.cc:304: bool TreeDeleter::MoveToParent(const FilePath& path, On 2016/12/04 14:10:46, jschuh (very ...
4 years ago (2016-12-04 21:35:46 UTC) #16
grt (UTC plus 2)
+wfh again
4 years ago (2016-12-06 07:28:40 UTC) #19
Scott Hess - ex-Googler
Something I didn't get from the talk was whether the dance of moving the file ...
4 years ago (2016-12-06 08:15:56 UTC) #21
grt (UTC plus 2)
On 2016/12/06 08:15:56, Scott Hess wrote: > Something I didn't get from the talk was ...
4 years ago (2016-12-06 12:20:46 UTC) #22
Will Harris
I feel like I'm entering the scary door with this CL.
4 years ago (2016-12-06 19:49:38 UTC) #23
jschuh
https://codereview.chromium.org/2545283002/diff/20001/base/files/file_util_win.cc File base/files/file_util_win.cc (right): https://codereview.chromium.org/2545283002/diff/20001/base/files/file_util_win.cc#newcode212 base/files/file_util_win.cc:212: !IsMountPointOrSymlink(to_delete, basic_info) && !DeleteContents(path)) { On 2016/12/04 21:31:48, grt ...
4 years ago (2016-12-06 22:16:34 UTC) #24
grt (UTC plus 2)
Some comments addressed and some questions raised. https://codereview.chromium.org/2545283002/diff/20001/base/files/file_util_win.cc File base/files/file_util_win.cc (right): https://codereview.chromium.org/2545283002/diff/20001/base/files/file_util_win.cc#newcode212 base/files/file_util_win.cc:212: !IsMountPointOrSymlink(to_delete, basic_info) ...
4 years ago (2016-12-07 08:34:39 UTC) #25
forshaw
> James: do you have any thoughts on this? It's likely that even when the ...
4 years ago (2016-12-07 10:46:10 UTC) #26
grt (UTC plus 2)
On 2016/12/07 10:46:10, forshaw wrote: > > James: do you have any thoughts on this? ...
4 years ago (2016-12-07 10:51:06 UTC) #27
grt (UTC plus 2)
https://codereview.chromium.org/2545283002/diff/20001/base/files/file_util_win.cc File base/files/file_util_win.cc (right): https://codereview.chromium.org/2545283002/diff/20001/base/files/file_util_win.cc#newcode304 base/files/file_util_win.cc:304: bool TreeDeleter::MoveToParent(const FilePath& path, On 2016/12/07 08:34:39, grt (UTC ...
4 years ago (2016-12-07 15:03:10 UTC) #30
Sigurður Ásgeirsson
Didn't review in great detail, but looks sane to me. https://codereview.chromium.org/2545283002/diff/80001/base/files/file_util_win.cc File base/files/file_util_win.cc (right): https://codereview.chromium.org/2545283002/diff/80001/base/files/file_util_win.cc#newcode46 ...
4 years ago (2016-12-07 16:29:19 UTC) #36
Sigurður Ásgeirsson
Didn't review in great detail, but looks sane to me.
4 years ago (2016-12-07 16:29:21 UTC) #37
Will Harris
few questions https://codereview.chromium.org/2545283002/diff/80001/base/files/file_util_win.cc File base/files/file_util_win.cc (right): https://codereview.chromium.org/2545283002/diff/80001/base/files/file_util_win.cc#newcode45 base/files/file_util_win.cc:45: // The workhorse of base::DeleteFile. This class ...
4 years ago (2016-12-07 19:47:44 UTC) #40
grt (UTC plus 2)
PTAL https://codereview.chromium.org/2545283002/diff/80001/base/files/file_util_win.cc File base/files/file_util_win.cc (right): https://codereview.chromium.org/2545283002/diff/80001/base/files/file_util_win.cc#newcode45 base/files/file_util_win.cc:45: // The workhorse of base::DeleteFile. This class implements ...
4 years ago (2016-12-07 20:56:06 UTC) #46
Will Harris
On 2016/12/07 20:56:06, grt (UTC plus 1) wrote: > PTAL > > https://codereview.chromium.org/2545283002/diff/80001/base/files/file_util_win.cc > File ...
4 years ago (2016-12-07 21:04:04 UTC) #47
grt (UTC plus 2)
PTAL. I've added a way for callers to get metrics, and have rejiggered the retry ...
4 years ago (2016-12-08 14:08:44 UTC) #53
Sigurður Ásgeirsson
Sadly I don't have time to moar review till Monday, so don't hold this up ...
4 years ago (2016-12-08 14:29:26 UTC) #54
Sigurður Ásgeirsson
/exit stage left to do my chores. https://codereview.chromium.org/2545283002/diff/160001/base/files/file_util.h File base/files/file_util.h (right): https://codereview.chromium.org/2545283002/diff/160001/base/files/file_util.h#newcode64 base/files/file_util.h:64: // possible ...
4 years ago (2016-12-08 14:36:46 UTC) #55
Sigurður Ásgeirsson
/exit stage left to do my chores.
4 years ago (2016-12-08 14:36:56 UTC) #56
grt (UTC plus 2)
On 2016/12/08 14:29:26, Sigurður Ásgeirsson wrote: > Sadly I don't have time to moar review ...
4 years ago (2016-12-08 20:17:42 UTC) #59
grt (UTC plus 2)
https://codereview.chromium.org/2545283002/diff/160001/base/files/file_util.h File base/files/file_util.h (right): https://codereview.chromium.org/2545283002/diff/160001/base/files/file_util.h#newcode64 base/files/file_util.h:64: // possible will always be deleted. Returns true if ...
4 years ago (2016-12-08 20:35:17 UTC) #62
grt (UTC plus 2)
+thakis for base/OWNERS review. please review the CL this depends on, too (base32 in base). ...
4 years ago (2016-12-12 08:15:54 UTC) #66
grt (UTC plus 2)
I just stumbled upon DatabaseTracker::DeleteOrigin, which can be simplified once this lands -- it has ...
4 years ago (2016-12-15 21:05:22 UTC) #71
Nico
The main code for this is very readable, thanks! It's pretty scary that this much ...
3 years, 11 months ago (2017-01-10 18:31:56 UTC) #72
Nico
https://codereview.chromium.org/2545283002/diff/200001/base/files/file_util_win.cc File base/files/file_util_win.cc (right): https://codereview.chromium.org/2545283002/diff/200001/base/files/file_util_win.cc#newcode265 base/files/file_util_win.cc:265: // Try the parent dir of |path|. On 2017/01/10 ...
3 years, 11 months ago (2017-01-10 18:39:51 UTC) #73
grt (UTC plus 2)
Thanks. I was hoping to get sign-off on this approach before doing some investing more ...
3 years, 11 months ago (2017-01-12 15:07:03 UTC) #75
Nico
3 years, 11 months ago (2017-01-17 13:19:58 UTC) #76
Yes, overall approach looks good to me. I think having some way (e.g. the psycho
test suite you mention) to evaluate future changes ("adding another attempt at
deletion here increases test success rate by 5%") to this code is important
though.

https://codereview.chromium.org/2545283002/diff/200001/base/files/file_util_w...
File base/files/file_util_win.cc (right):

https://codereview.chromium.org/2545283002/diff/200001/base/files/file_util_w...
base/files/file_util_win.cc:179: return Base32Encode(StringPiece(&random[0],
sizeof(random))).append(".tmp");
On 2017/01/12 15:07:03, grt (UTC plus 1) wrote:
> On 2017/01/10 18:31:56, Nico wrote:
> > what's wrong with win32's GetTempFileName()?
> 
> I think it's undesirable here for a few reasons:
> - If you want it to guarantee a unique filename, the documentation says it's
> inefficient in directories containing lots of files. Temp dirs often have lots
> of files, so this seems bad.
> - If you want it to guarantee a unique filename, it creates a file with that
> name and leaves it there for you. This file is then in the way of the file we
> want to move, so we'd have to delete it or rename it, which kinda puts us back
> to where we started. :-)

(This is to protect against time of check to time of use attacks – see mktemp
references on https://en.wikipedia.org/wiki/Time_of_check_to_time_of_use . For
file deletion, I believe you're right that this gets in the way instead of
helping, but I'm also not very creative in coming up with exploits for this type
of problem :-) )

> - If you don't want it to guarantee a unique filename, you have to call it
> repeatedly in case of collision, which is no better than the roll-your-own
I've
> created here.

Well, it's roughly the same code except that we don't need the base64 code in
base, right? (Maybe I'm missing something.)

Powered by Google App Engine
This is Rietveld 408576698