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

Unified Diff: base/file_util_win.cc

Issue 12212010: Truncate the download file name if it exceeds the filesystem limit. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move to file_util, care about MAX_PATH, uniquification Created 7 years, 10 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_posix.cc ('k') | chrome/browser/download/download_path_reservation_tracker.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/file_util_win.cc
diff --git a/base/file_util_win.cc b/base/file_util_win.cc
index 65fd6ebb43c3ff09bd82790678cfe2ac06ad50c7..42d8b5bbecbdd7c7735a2624ad1b700e5031b40f 100644
--- a/base/file_util_win.cc
+++ b/base/file_util_win.cc
@@ -8,8 +8,10 @@
#include <psapi.h>
#include <shellapi.h>
#include <shlobj.h>
+#include <shlwapi.h>
#include <time.h>
+#include <algorithm>
#include <limits>
#include <string>
@@ -948,4 +950,29 @@ bool NormalizeToNativeFilePath(const FilePath& path, FilePath* nt_path) {
return success;
}
+int GetMaximumPathComponentLength(const FilePath& path) {
+ base::ThreadRestrictions::AssertIOAllowed();
+ FilePath full_path(path);
+ if (!full_path.IsAbsolute() && !file_util::AbsolutePath(&full_path))
+ return -1;
+
+ // GetVolumeInformationW takes a root path ended with a backslash.
+ std::vector<FilePath::CharType> root(full_path.value().begin(),
+ full_path.value().end());
+ root.resize(root.size() + 2); // +2 for trailing \0 and backslash.
+ PathStripToRootW(&root[0]);
Mark Mentovai 2013/02/14 13:40:58 Looking at http://msdn.microsoft.com/en-us/library
asanka 2013/02/14 16:06:53 Unfortunately PathCchStripToRoot() appears to be o
+ PathAddBackslashW(&root[0]);
Mark Mentovai 2013/02/14 13:40:58 Same with PathCchAddBackslash. See http://msdn.mic
+
+ DWORD max_length = 0;
+ if (!GetVolumeInformationW(&root[0], NULL, 0, NULL, &max_length, NULL, NULL,
+ 0)) {
+ return -1;
+ }
+
+ // path.Append(name) cannot exceed MAX_PATH.
+ int whole_path_limit =
+ std::max(0, MAX_PATH - static_cast<int>(path.value().size()) - 1);
+ return std::min(whole_path_limit, static_cast<int>(max_length));
+}
+
} // namespace file_util
« no previous file with comments | « base/file_util_posix.cc ('k') | chrome/browser/download/download_path_reservation_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698