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

Unified Diff: base/file_util.cc

Issue 9316004: Move common file path related methods between chrome & content to file_util. I reduced the 4 meth... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: remove includes Created 8 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 | « base/file_util.h ('k') | chrome/browser/DEPS » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_util.cc
===================================================================
--- base/file_util.cc (revision 119906)
+++ base/file_util.cc (working copy)
@@ -13,6 +13,7 @@
#include "base/file_path.h"
#include "base/logging.h"
+#include "base/stringprintf.h"
#include "base/string_piece.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
@@ -21,6 +22,13 @@
const FilePath::CharType kExtensionSeparator = FILE_PATH_LITERAL('.');
+// The maximum number of 'uniquified' files we will try to create.
+// This is used when the filename we're trying to download is already in use,
+// so we create a new unique filename by appending " (nnn)" before the
+// extension, where 1 <= nnn <= kMaxUniqueFiles.
+// Also used by code that cleans up said files.
+static const int kMaxUniqueFiles = 100;
+
} // namespace
namespace file_util {
@@ -237,6 +245,27 @@
return true;
}
+int GetUniquePathNumber(
+ const FilePath& path,
+ const FilePath::StringType& suffix) {
+ bool have_suffix = !suffix.empty();
+ if (!PathExists(path) &&
+ (!have_suffix || !PathExists(FilePath(path.value() + suffix)))) {
+ return 0;
+ }
+
+ FilePath new_path;
+ for (int count = 1; count <= kMaxUniqueFiles; ++count) {
+ new_path = path.InsertBeforeExtensionASCII(StringPrintf(" (%d)", count));
+ if (!PathExists(new_path) &&
+ (!have_suffix || !PathExists(FilePath(new_path.value() + suffix)))) {
+ return count;
+ }
+ }
+
+ return -1;
+}
+
bool ContainsPath(const FilePath &parent, const FilePath& child) {
FilePath abs_parent = FilePath(parent);
FilePath abs_child = FilePath(child);
« no previous file with comments | « base/file_util.h ('k') | chrome/browser/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698