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

Unified Diff: base/file_path.cc

Issue 5754002: Moving away from shell api to support long path names on windows for filesystem. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years 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
Index: base/file_path.cc
===================================================================
--- base/file_path.cc (revision 69859)
+++ base/file_path.cc (working copy)
@@ -34,6 +34,19 @@
const FilePath::CharType FilePath::kCurrentDirectory[] = FILE_PATH_LITERAL(".");
const FilePath::CharType FilePath::kParentDirectory[] = FILE_PATH_LITERAL("..");
+#if defined(OS_WIN)
+const FilePath::CharType FilePath::kExtendedPathPrefix[] =
+ FILE_PATH_LITERAL("\\\\?\\");
+
+const FilePath::CharType FilePath::kUNCExtendedPathPrefix[] =
+ FILE_PATH_LITERAL("\\\\?\\UNC\\");
+
+const FilePath::CharType FilePath::kSharePrefix[] =
+ FILE_PATH_LITERAL("\\\\");
+
+const int kSharePrefixLength = 2;
kinuko 2010/12/22 23:20:49 arraysize(kSharePrefix) would also work.
Kavita Kanetkar 2010/12/23 03:14:28 Done.
+#endif
+
const FilePath::CharType FilePath::kExtensionSeparator = FILE_PATH_LITERAL('.');
typedef FilePath::StringType StringType;
@@ -1190,3 +1203,51 @@
return FilePath(copy);
}
#endif
+
+#if defined(OS_WIN)
+// TODO(kkanetkar): Taken from gears. Replace this when
kinuko 2010/12/22 23:20:49 'Replace this' may not correctly state what we wan
Kavita Kanetkar 2010/12/23 03:14:28 Done.
+// crbug.com/67384 is addressed.
+StringType FilePath::ToLongFileNameHack(const StringType& path) const {
+ StringType long_path;
+ // This cast is for countering the compiler warning.
+ DWORD length_to_try = static_cast<DWORD>(path.length() * 2);
+ long_path.resize(length_to_try);
+ DWORD actual_length = GetLongPathName(path.c_str(),
+ &long_path.at(0),
+ length_to_try);
+ if (actual_length == 0) {
+ return path;
+ } else if (actual_length <= length_to_try) {
+ long_path.resize(actual_length);
+ return long_path;
+ }
+
+ length_to_try = actual_length;
+ long_path.resize(length_to_try);
+ actual_length = GetLongPathName(path.c_str(),
+ &long_path.at(0),
+ length_to_try + 1);
+ if (actual_length > 0 && actual_length <= length_to_try) {
+ long_path.resize(actual_length);
+ return long_path;
+ } else {
+ return path;
+ }
+}
+
+FilePath FilePath::GetLongPathHack() const {
+ if (StartsWith(path_, kExtendedPathPrefix, false) ||
+ StartsWith(path_, kUNCExtendedPathPrefix, false)) {
+ return FilePath(path_);
+ }
+
+ // Note that the 8.3 short file name can not be simply prefixed with the long
+ // path prefix. It has to be converted to long file name first.
+ if (StartsWith(path_, kSharePrefix, false)) {
+ return FilePath(kUNCExtendedPathPrefix + ToLongFileNameHack(
+ path_.substr(kSharePrefixLength)));
+ } else {
+ return FilePath(kExtendedPathPrefix + ToLongFileNameHack(path_));
+ }
+}
+#endif

Powered by Google App Engine
This is Rietveld 408576698