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

Unified Diff: net/disk_cache/simple/simple_synchronous_entry.cc

Issue 2862943002: SimpleCache: try to recover on CreateEntry on missing cache dir (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/disk_cache/simple/simple_synchronous_entry.cc
diff --git a/net/disk_cache/simple/simple_synchronous_entry.cc b/net/disk_cache/simple/simple_synchronous_entry.cc
index ea83472455e9170d7f0bb178fa6ee934bb09d6fd..c4f85c3dbe7dbd42c55559e9dc074a8a092e05fa 100644
--- a/net/disk_cache/simple/simple_synchronous_entry.cc
+++ b/net/disk_cache/simple/simple_synchronous_entry.cc
@@ -868,8 +868,18 @@ bool SimpleSynchronousEntry::MaybeCreateFile(
int flags = File::FLAG_CREATE | File::FLAG_READ | File::FLAG_WRITE |
File::FLAG_SHARE_DELETE;
files_[file_index].Initialize(filename, flags);
- *out_error = files_[file_index].error_details();
+ // It's possible that the creation failed because someone deleted the
+ // directory (e.g. because someone pressed "clear cache" on Android).
+ // If so, we would keep failing for a while until periodic index snapshot
+ // re-creates the cache dir, so try to recover from it quickly here.
+ if (!files_[file_index].IsValid() &&
+ files_[file_index].error_details() == File::FILE_ERROR_NOT_FOUND &&
+ !base::DirectoryExists(path_) && base::CreateDirectory(path_)) {
+ files_[file_index].Initialize(filename, flags);
jkarlin 2017/05/05 17:16:21 I worry a bit about the state of the cache being s
pasko 2017/05/05 17:24:15 Writing index here would probably fix the issue, b
jkarlin 2017/05/05 17:42:18 Okay, works with me.
+ }
+
+ *out_error = files_[file_index].error_details();
empty_file_omitted_[file_index] = false;
return files_[file_index].IsValid();
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698