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

Unified Diff: base/files/file_util.h

Issue 2545283002: A robust base::DeleteFile.
Patch Set: test fixes Created 3 years, 11 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 | base/files/file_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/files/file_util.h
diff --git a/base/files/file_util.h b/base/files/file_util.h
index 77a87e7dade7df8db204dfd33aaafe7209c8a06b..8b56b78af4cc4c52eda638b8a619362807d392e1 100644
--- a/base/files/file_util.h
+++ b/base/files/file_util.h
@@ -55,21 +55,71 @@ BASE_EXPORT FilePath MakeAbsoluteFilePath(const FilePath& input);
// particularly speedy in any platform.
BASE_EXPORT int64_t ComputeDirectorySize(const FilePath& root_path);
-// Deletes the given path, whether it's a file or a directory.
-// If it's a directory, it's perfectly happy to delete all of the
-// directory's contents. Passing true to recursive deletes
-// subdirectories and their contents as well.
-// Returns true if successful, false otherwise. It is considered successful
-// to attempt to delete a file that does not exist.
+// Deletes the given path. If |path| names a directory and |recursive| is false,
+// the directory is only deleted if it is empty or is a symbolic link. If |path|
+// names a directory and |recursive| is true, this function will recursively
+// delete as much as possible within |path|, ideally ending in success when
+// |path| is deleted. In case of error, an unspecified amount of |path|'s
+// original contents may already have been deleted.
//
-// In posix environment and if |path| is a symbolic link, this deletes only
-// the symlink. (even if the symlink points to a non-existent file)
+// On Windows: as much as possible will always be deleted. Returns true if
+// |path| was deleted or did not exist. This function will not recurse into
+// symlinks or mount points (a.k.a. junction points), but rather will delete the
+// links/points themselves.
+//
+// In posix environment and if |path| is a symbolic link, this deletes only the
+// symlink. (even if the symlink points to a non-existent file)
//
// WARNING: USING THIS WITH recursive==true IS EQUIVALENT
// TO "rm -rf", SO USE WITH CAUTION.
BASE_EXPORT bool DeleteFile(const FilePath& path, bool recursive);
#if defined(OS_WIN)
+struct DeleteFileMetrics {
+ enum TemporaryDirectoryLocation {
+ UNDECIDED, // No attempt has yet been made to find a directory.
+ NONE, // Failed to find a writeable temporary directory.
+ TEMP, // Using %TEMP%.
+ VOLUME_TEMP, // Using X:\Temp or X:\Tmp.
+ PARENT, // Using the directory above the top-most item being deleted.
+ ITEM, // Using the directory containing the item being deleted.
+ };
+
+ TemporaryDirectoryLocation temporary_directory_location;
+
+ // The number of items deleted via the DELETE_ON_CLOSE path (note that
+ // non-existant items count as successes in this path).
+ int delete_on_close_success_count;
+
+ // The number of items in |delete_on_close_success_count| that were moved into
+ // the temp directory. Ideally, this equals |delete_on_close_success_count|,
+ // meaning that the operation was 100% successful.
+ int move_to_temp_count;
+
+ // The number of times opening an item to be deleted failed, resulting in a
+ // fallback to plain ::DeleteFile that succeded.
+ int delete_file_success_count;
+
+ // The number of times each of the above strategies failed to delete an item.
+ int fail_count;
+
+ // The total number of retries before giving up (0 if success on the first
+ // attempt). If the overall operation succeeds and this is not zero, the
+ // retries were a very good thing. If the overall operation fails and the two
+ // success counts above are non-zero, then perhaps more retries or some delays
+ // would have helped. If the overall operation fails and the two success
+ // counts above are zero, then it's likely that nothing would have helped.
+ int total_retry_count;
+
+ // The maximum recursion depth.
+ int max_depth;
+};
+
+// The same as DeleteFile, but with metrics about its performance.
+BASE_EXPORT bool DeleteFileWithMetrics(const FilePath& path,
+ bool recursive,
+ DeleteFileMetrics* metrics);
+
// Schedules to delete the given path, whether it's a file or a directory, until
// the operating system is restarted.
// Note:
« no previous file with comments | « no previous file | base/files/file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698