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

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,17 @@
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("\\\\");
+#endif
+
const FilePath::CharType FilePath::kExtensionSeparator = FILE_PATH_LITERAL('.');
typedef FilePath::StringType StringType;
@@ -155,6 +166,39 @@
return last_dot;
}
+#if defined(OS_WIN)
+// TODO(kkanetkar): Taken from gears. When crbug.com/67384 is addressed
+// this logic will be used in a different way such that the callers
+// would not be aware of the extended path or UNC formats.
+StringType ToLongFileNameHack(const FilePath::StringType& path) {
+ StringType long_path;
+ // This cast is for countering the compiler warning.
+ DWORD length_to_try = static_cast<DWORD>(path.length() * 2);
Erik does not do reviews 2010/12/23 17:57:27 I don't understand this *2 logic. Why not just pa
+ 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;
Erik does not do reviews 2010/12/23 17:57:27 I'm a bit nervous that this won't work in all case
+ } 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;
+ }
+}
+#endif
+
} // namespace
FilePath::FilePath() {
@@ -1190,3 +1234,28 @@
return FilePath(copy);
}
#endif
+
+#if defined(OS_WIN)
+FilePath FilePath::GetLongPathHack() const {
+ if (StartsWith(path_, kExtendedPathPrefix, false) ||
Erik does not do reviews 2010/12/23 17:57:27 why not call StartsWithExtendedPathOrUNCPrefix?
+ 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(arraysize(FilePath::kSharePrefix) - 1)));
+ } else {
+ return FilePath(kExtendedPathPrefix + ToLongFileNameHack(path_));
+ }
+}
+#endif
+
+#if defined(OS_WIN)
+bool FilePath::StartsWithExtendedPathOrUNCPrefix() const {
+ return StartsWith(path_, kExtendedPathPrefix, false) ||
+ StartsWith(path_, kUNCExtendedPathPrefix, false);
+}
+#endif

Powered by Google App Engine
This is Rietveld 408576698