OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "webkit/fileapi/file_system_file_util.h" | 5 #include "webkit/fileapi/file_system_file_util.h" |
6 | 6 |
7 #include <stack> | 7 #include <stack> |
8 | 8 |
9 #include "base/file_util_proxy.h" | 9 #include "base/file_util_proxy.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 return base::PLATFORM_FILE_OK; | 88 return base::PLATFORM_FILE_OK; |
89 } | 89 } |
90 | 90 |
91 PlatformFileError FileSystemFileUtil::GetFileInfo( | 91 PlatformFileError FileSystemFileUtil::GetFileInfo( |
92 FileSystemOperationContext* unused, | 92 FileSystemOperationContext* unused, |
93 const FilePath& file_path, | 93 const FilePath& file_path, |
94 base::PlatformFileInfo* file_info, | 94 base::PlatformFileInfo* file_info, |
95 FilePath* platform_file_path) { | 95 FilePath* platform_file_path) { |
96 if (!file_util::PathExists(file_path)) | 96 if (!file_util::PathExists(file_path)) |
97 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 97 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 98 // TODO(rkc): Fix this hack once we have refactored file_util to handle |
| 99 // symlinks correctly. |
| 100 // http://code.google.com/p/chromium-os/issues/detail?id=15948 |
| 101 if (file_util::IsLink(file_path)) |
| 102 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
98 if (!file_util::GetFileInfo(file_path, file_info)) | 103 if (!file_util::GetFileInfo(file_path, file_info)) |
99 return base::PLATFORM_FILE_ERROR_FAILED; | 104 return base::PLATFORM_FILE_ERROR_FAILED; |
100 *platform_file_path = file_path; | 105 *platform_file_path = file_path; |
101 return base::PLATFORM_FILE_OK; | 106 return base::PLATFORM_FILE_OK; |
102 } | 107 } |
103 | 108 |
104 PlatformFileError FileSystemFileUtil::ReadDirectory( | 109 PlatformFileError FileSystemFileUtil::ReadDirectory( |
105 FileSystemOperationContext* unused, | 110 FileSystemOperationContext* unused, |
106 const FilePath& file_path, | 111 const FilePath& file_path, |
107 std::vector<base::FileUtilProxy::Entry>* entries) { | 112 std::vector<base::FileUtilProxy::Entry>* entries) { |
108 // TODO(kkanetkar): Implement directory read in multiple chunks. | 113 // TODO(kkanetkar): Implement directory read in multiple chunks. |
109 if (!file_util::DirectoryExists(file_path)) | 114 if (!file_util::DirectoryExists(file_path)) |
110 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 115 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
111 | 116 |
112 file_util::FileEnumerator file_enum( | 117 file_util::FileEnumerator file_enum( |
113 file_path, false, static_cast<file_util::FileEnumerator::FILE_TYPE>( | 118 file_path, false, static_cast<file_util::FileEnumerator::FILE_TYPE>( |
114 file_util::FileEnumerator::FILES | | 119 file_util::FileEnumerator::FILES | |
115 file_util::FileEnumerator::DIRECTORIES)); | 120 file_util::FileEnumerator::DIRECTORIES)); |
116 FilePath current; | 121 FilePath current; |
117 while (!(current = file_enum.Next()).empty()) { | 122 while (!(current = file_enum.Next()).empty()) { |
118 base::FileUtilProxy::Entry entry; | 123 base::FileUtilProxy::Entry entry; |
119 file_util::FileEnumerator::FindInfo info; | 124 file_util::FileEnumerator::FindInfo info; |
120 file_enum.GetFindInfo(&info); | 125 file_enum.GetFindInfo(&info); |
121 entry.is_directory = file_enum.IsDirectory(info); | 126 entry.is_directory = file_enum.IsDirectory(info); |
122 // This will just give the entry's name instead of entire path | 127 // This will just give the entry's name instead of entire path |
123 // if we use current.value(). | 128 // if we use current.value(). |
124 entry.name = file_util::FileEnumerator::GetFilename(info).value(); | 129 entry.name = file_util::FileEnumerator::GetFilename(info).value(); |
125 entries->push_back(entry); | 130 // TODO(rkc): Fix this also once we've refactored file_util |
| 131 // http://code.google.com/p/chromium-os/issues/detail?id=15948 |
| 132 // This currently just prevents a file from showing up at all |
| 133 // if it's a link, hence preventing arbitary 'read' exploits. |
| 134 if (!file_util::IsLink(file_path.Append(entry.name))) |
| 135 entries->push_back(entry); |
126 } | 136 } |
127 return base::PLATFORM_FILE_OK; | 137 return base::PLATFORM_FILE_OK; |
128 } | 138 } |
129 | 139 |
130 PlatformFileError FileSystemFileUtil::CreateDirectory( | 140 PlatformFileError FileSystemFileUtil::CreateDirectory( |
131 FileSystemOperationContext* unused, | 141 FileSystemOperationContext* unused, |
132 const FilePath& file_path, | 142 const FilePath& file_path, |
133 bool exclusive, | 143 bool exclusive, |
134 bool recursive) { | 144 bool recursive) { |
135 // If parent dir of file doesn't exist. | 145 // If parent dir of file doesn't exist. |
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 FileSystemFileUtil::CreateFileEnumerator( | 541 FileSystemFileUtil::CreateFileEnumerator( |
532 FileSystemOperationContext* unused, | 542 FileSystemOperationContext* unused, |
533 const FilePath& root_path) { | 543 const FilePath& root_path) { |
534 return new FileSystemFileEnumerator( | 544 return new FileSystemFileEnumerator( |
535 root_path, true, static_cast<file_util::FileEnumerator::FILE_TYPE>( | 545 root_path, true, static_cast<file_util::FileEnumerator::FILE_TYPE>( |
536 file_util::FileEnumerator::FILES | | 546 file_util::FileEnumerator::FILES | |
537 file_util::FileEnumerator::DIRECTORIES)); | 547 file_util::FileEnumerator::DIRECTORIES)); |
538 } | 548 } |
539 | 549 |
540 } // namespace fileapi | 550 } // namespace fileapi |
OLD | NEW |