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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/file_util.h" 5 #include "base/file_util.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <psapi.h> 8 #include <psapi.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #include <shlobj.h> 10 #include <shlobj.h>
11 #include <shlwapi.h>
11 #include <time.h> 12 #include <time.h>
12 13
14 #include <algorithm>
13 #include <limits> 15 #include <limits>
14 #include <string> 16 #include <string>
15 17
16 #include "base/file_path.h" 18 #include "base/file_path.h"
17 #include "base/logging.h" 19 #include "base/logging.h"
18 #include "base/metrics/histogram.h" 20 #include "base/metrics/histogram.h"
19 #include "base/process_util.h" 21 #include "base/process_util.h"
20 #include "base/string_util.h" 22 #include "base/string_util.h"
21 #include "base/strings/string_number_conversions.h" 23 #include "base/strings/string_number_conversions.h"
22 #include "base/threading/thread_restrictions.h" 24 #include "base/threading/thread_restrictions.h"
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 bool success = false; 943 bool success = false;
942 HANDLE cp = GetCurrentProcess(); 944 HANDLE cp = GetCurrentProcess();
943 if (::GetMappedFileNameW(cp, file_view, mapped_file_path, kMaxPathLength)) { 945 if (::GetMappedFileNameW(cp, file_view, mapped_file_path, kMaxPathLength)) {
944 *nt_path = FilePath(mapped_file_path); 946 *nt_path = FilePath(mapped_file_path);
945 success = true; 947 success = true;
946 } 948 }
947 ::UnmapViewOfFile(file_view); 949 ::UnmapViewOfFile(file_view);
948 return success; 950 return success;
949 } 951 }
950 952
953 int GetMaximumPathComponentLength(const FilePath& path) {
954 base::ThreadRestrictions::AssertIOAllowed();
955 FilePath full_path(path);
956 if (!full_path.IsAbsolute() && !file_util::AbsolutePath(&full_path))
957 return -1;
958
959 // GetVolumeInformationW takes a root path ended with a backslash.
960 std::vector<FilePath::CharType> root(full_path.value().begin(),
961 full_path.value().end());
962 root.resize(root.size() + 2); // +2 for trailing \0 and backslash.
963 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
964 PathAddBackslashW(&root[0]);
Mark Mentovai 2013/02/14 13:40:58 Same with PathCchAddBackslash. See http://msdn.mic
965
966 DWORD max_length = 0;
967 if (!GetVolumeInformationW(&root[0], NULL, 0, NULL, &max_length, NULL, NULL,
968 0)) {
969 return -1;
970 }
971
972 // path.Append(name) cannot exceed MAX_PATH.
973 int whole_path_limit =
974 std::max(0, MAX_PATH - static_cast<int>(path.value().size()) - 1);
975 return std::min(whole_path_limit, static_cast<int>(max_length));
976 }
977
951 } // namespace file_util 978 } // namespace file_util
OLDNEW
« 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