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

Side by Side Diff: webrtc/rtc_base/win32filesystem.cc

Issue 2891923002: Delete Filesystem::CreateFolder. (Closed)
Patch Set: Rebased. Created 3 years, 3 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
« no previous file with comments | « webrtc/rtc_base/win32filesystem.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2004 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2004 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 15 matching lines...) Expand all
26 26
27 // In several places in this file, we test the integrity level of the process 27 // In several places in this file, we test the integrity level of the process
28 // before calling GetLongPathName. We do this because calling GetLongPathName 28 // before calling GetLongPathName. We do this because calling GetLongPathName
29 // when running under protected mode IE (a low integrity process) can result in 29 // when running under protected mode IE (a low integrity process) can result in
30 // a virtualized path being returned, which is wrong if you only plan to read. 30 // a virtualized path being returned, which is wrong if you only plan to read.
31 // TODO: Waiting to hear back from IE team on whether this is the 31 // TODO: Waiting to hear back from IE team on whether this is the
32 // best approach; IEIsProtectedModeProcess is another possible solution. 32 // best approach; IEIsProtectedModeProcess is another possible solution.
33 33
34 namespace rtc { 34 namespace rtc {
35 35
36 bool Win32Filesystem::CreateFolder(const Pathname &pathname) {
37 if (pathname.pathname().empty() || !pathname.filename().empty())
38 return false;
39
40 std::wstring path16;
41 if (!Utf8ToWindowsFilename(pathname.pathname(), &path16))
42 return false;
43
44 DWORD res = ::GetFileAttributes(path16.c_str());
45 if (res != INVALID_FILE_ATTRIBUTES) {
46 // Something exists at this location, check if it is a directory
47 return ((res & FILE_ATTRIBUTE_DIRECTORY) != 0);
48 } else if ((GetLastError() != ERROR_FILE_NOT_FOUND)
49 && (GetLastError() != ERROR_PATH_NOT_FOUND)) {
50 // Unexpected error
51 return false;
52 }
53
54 // Directory doesn't exist, look up one directory level
55 if (!pathname.parent_folder().empty()) {
56 Pathname parent(pathname);
57 parent.SetFolder(pathname.parent_folder());
58 if (!CreateFolder(parent)) {
59 return false;
60 }
61 }
62
63 return (::CreateDirectory(path16.c_str(), nullptr) != 0);
64 }
65
66 bool Win32Filesystem::DeleteFile(const Pathname &filename) { 36 bool Win32Filesystem::DeleteFile(const Pathname &filename) {
67 LOG(LS_INFO) << "Deleting file " << filename.pathname(); 37 LOG(LS_INFO) << "Deleting file " << filename.pathname();
68 if (!IsFile(filename)) { 38 if (!IsFile(filename)) {
69 RTC_DCHECK(IsFile(filename)); 39 RTC_DCHECK(IsFile(filename));
70 return false; 40 return false;
71 } 41 }
72 return ::DeleteFile(ToUtf16(filename.pathname()).c_str()) != 0; 42 return ::DeleteFile(ToUtf16(filename.pathname()).c_str()) != 0;
73 } 43 }
74 44
75 std::string Win32Filesystem::TempFilename(const Pathname &dir, 45 std::string Win32Filesystem::TempFilename(const Pathname &dir,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 bool Win32Filesystem::GetFileSize(const Pathname &pathname, size_t *size) { 84 bool Win32Filesystem::GetFileSize(const Pathname &pathname, size_t *size) {
115 WIN32_FILE_ATTRIBUTE_DATA data = {0}; 85 WIN32_FILE_ATTRIBUTE_DATA data = {0};
116 if (::GetFileAttributesEx(ToUtf16(pathname.pathname()).c_str(), 86 if (::GetFileAttributesEx(ToUtf16(pathname.pathname()).c_str(),
117 GetFileExInfoStandard, &data) == 0) 87 GetFileExInfoStandard, &data) == 0)
118 return false; 88 return false;
119 *size = data.nFileSizeLow; 89 *size = data.nFileSizeLow;
120 return true; 90 return true;
121 } 91 }
122 92
123 } // namespace rtc 93 } // namespace rtc
OLDNEW
« no previous file with comments | « webrtc/rtc_base/win32filesystem.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698