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

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: Review fix (#14), rebase. 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
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 <time.h> 11 #include <time.h>
12 12
13 #include <algorithm>
13 #include <limits> 14 #include <limits>
14 #include <string> 15 #include <string>
15 16
16 #include "base/file_path.h" 17 #include "base/file_path.h"
17 #include "base/logging.h" 18 #include "base/logging.h"
18 #include "base/metrics/histogram.h" 19 #include "base/metrics/histogram.h"
19 #include "base/process_util.h" 20 #include "base/process_util.h"
20 #include "base/string_util.h" 21 #include "base/string_util.h"
21 #include "base/strings/string_number_conversions.h" 22 #include "base/strings/string_number_conversions.h"
22 #include "base/threading/thread_restrictions.h" 23 #include "base/threading/thread_restrictions.h"
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after
941 bool success = false; 942 bool success = false;
942 HANDLE cp = GetCurrentProcess(); 943 HANDLE cp = GetCurrentProcess();
943 if (::GetMappedFileNameW(cp, file_view, mapped_file_path, kMaxPathLength)) { 944 if (::GetMappedFileNameW(cp, file_view, mapped_file_path, kMaxPathLength)) {
944 *nt_path = FilePath(mapped_file_path); 945 *nt_path = FilePath(mapped_file_path);
945 success = true; 946 success = true;
946 } 947 }
947 ::UnmapViewOfFile(file_view); 948 ::UnmapViewOfFile(file_view);
948 return success; 949 return success;
949 } 950 }
950 951
952 int GetMaximumPathComponentLength(const FilePath& path) {
953 base::ThreadRestrictions::AssertIOAllowed();
954
955 wchar_t volume_path[MAX_PATH];
956 if (!GetVolumePathNameW(path.NormalizePathSeparators().value().c_str(),
957 volume_path,
958 arraysize(volume_path))) {
959 return -1;
960 }
961
962 DWORD max_length = 0;
963 if (!GetVolumeInformationW(volume_path, NULL, 0, NULL, &max_length, NULL,
964 NULL, 0)) {
965 return -1;
966 }
967
968 // Length of |path| with path separator appended.
969 size_t prefix = path.StripTrailingSeparators().value().size() + 1;
970 // The whole path string must be shorter than MAX_PATH. That is, it must be
971 // prefix + component_length < MAX_PATH (or equivalently, <= MAX_PATH - 1).
972 int whole_path_limit = std::max(0, MAX_PATH - 1 - static_cast<int>(prefix));
973 return std::min(whole_path_limit, static_cast<int>(max_length));
974 }
975
951 } // namespace file_util 976 } // namespace file_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698