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

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: GetVolumePathName(). 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..b7154051f6b8107336fb18f32bfd9c66cbb5a64f 100644
--- a/base/file_util_win.cc
+++ b/base/file_util_win.cc
@@ -10,6 +10,7 @@
#include <shlobj.h>
#include <time.h>
+#include <algorithm>
#include <limits>
#include <string>
@@ -948,4 +949,26 @@ bool NormalizeToNativeFilePath(const FilePath& path, FilePath* nt_path) {
return success;
}
+int GetMaximumPathComponentLength(const FilePath& path) {
+ base::ThreadRestrictions::AssertIOAllowed();
+
+ wchar_t volume_path[MAX_PATH];
+ if (!GetVolumePathNameW(path.NormalizePathSeparators().value().c_str(),
+ volume_path,
+ MAX_PATH)) {
Mark Mentovai 2013/02/15 13:49:42 arraysize(volume_path)
kinaba 2013/02/18 03:30:21 Done.
+ return -1;
+ }
+
+ DWORD max_length = 0;
+ if (!GetVolumeInformationW(volume_path, NULL, 0, NULL, &max_length, NULL,
+ NULL, 0)) {
+ return -1;
+ }
+
+ // path.Append(name).value().size() must be less than MAX_PATH.
+ size_t prefix = path.StripTrailingSeparators().value().size() + 1;
+ int whole_path_limit = std::max(0, MAX_PATH - 1 - static_cast<int>(prefix));
Mark Mentovai 2013/02/15 13:49:42 So one +1 is for the separator and one -1 is to ke
Mark Mentovai 2013/02/15 13:49:42 You might not be able to get rid of all of the sta
kinaba 2013/02/18 03:30:21 Added some comments for clarification.
kinaba 2013/02/18 03:30:21 The expression assigned to |prefix| has type size_
+ 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