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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 return base::PLATFORM_FILE_OK; | 73 return base::PLATFORM_FILE_OK; |
74 } | 74 } |
75 | 75 |
76 PlatformFileError FileSystemFileUtil::GetFileInfo( | 76 PlatformFileError FileSystemFileUtil::GetFileInfo( |
77 FileSystemOperationContext* unused, | 77 FileSystemOperationContext* unused, |
78 const FilePath& file_path, | 78 const FilePath& file_path, |
79 base::PlatformFileInfo* file_info, | 79 base::PlatformFileInfo* file_info, |
80 FilePath* platform_file_path) { | 80 FilePath* platform_file_path) { |
81 if (!file_util::PathExists(file_path)) | 81 if (!file_util::PathExists(file_path)) |
82 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 82 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
83 // TODO(rkc): Fix this hack once we have refactored file_util to handle | |
84 // symlinks correctly. This check prevents handled extensions from accessing | |
85 // links | |
Evan Martin
2011/05/31 21:22:32
Can you describe how this is a hack? Or link to a
rkc
2011/05/31 21:49:56
Done.
| |
86 if (file_util::IsLink(file_path)) | |
87 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
83 if (!file_util::GetFileInfo(file_path, file_info)) | 88 if (!file_util::GetFileInfo(file_path, file_info)) |
84 return base::PLATFORM_FILE_ERROR_FAILED; | 89 return base::PLATFORM_FILE_ERROR_FAILED; |
85 *platform_file_path = file_path; | 90 *platform_file_path = file_path; |
86 return base::PLATFORM_FILE_OK; | 91 return base::PLATFORM_FILE_OK; |
87 } | 92 } |
88 | 93 |
89 PlatformFileError FileSystemFileUtil::ReadDirectory( | 94 PlatformFileError FileSystemFileUtil::ReadDirectory( |
90 FileSystemOperationContext* unused, | 95 FileSystemOperationContext* unused, |
91 const FilePath& file_path, | 96 const FilePath& file_path, |
92 std::vector<base::FileUtilProxy::Entry>* entries) { | 97 std::vector<base::FileUtilProxy::Entry>* entries) { |
93 // TODO(kkanetkar): Implement directory read in multiple chunks. | 98 // TODO(kkanetkar): Implement directory read in multiple chunks. |
94 if (!file_util::DirectoryExists(file_path)) | 99 if (!file_util::DirectoryExists(file_path)) |
95 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 100 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
96 | 101 |
97 file_util::FileEnumerator file_enum( | 102 file_util::FileEnumerator file_enum( |
98 file_path, false, static_cast<file_util::FileEnumerator::FILE_TYPE>( | 103 file_path, false, static_cast<file_util::FileEnumerator::FILE_TYPE>( |
99 file_util::FileEnumerator::FILES | | 104 file_util::FileEnumerator::FILES | |
100 file_util::FileEnumerator::DIRECTORIES)); | 105 file_util::FileEnumerator::DIRECTORIES)); |
101 FilePath current; | 106 FilePath current; |
102 while (!(current = file_enum.Next()).empty()) { | 107 while (!(current = file_enum.Next()).empty()) { |
103 base::FileUtilProxy::Entry entry; | 108 base::FileUtilProxy::Entry entry; |
104 file_util::FileEnumerator::FindInfo info; | 109 file_util::FileEnumerator::FindInfo info; |
105 file_enum.GetFindInfo(&info); | 110 file_enum.GetFindInfo(&info); |
106 entry.is_directory = file_enum.IsDirectory(info); | 111 entry.is_directory = file_enum.IsDirectory(info); |
107 // This will just give the entry's name instead of entire path | 112 // This will just give the entry's name instead of entire path |
108 // if we use current.value(). | 113 // if we use current.value(). |
109 entry.name = file_util::FileEnumerator::GetFilename(info).value(); | 114 entry.name = file_util::FileEnumerator::GetFilename(info).value(); |
115 // TODO(rkc): Fix this also once we've refactored file_util | |
116 // This currently just prevents a file from showing up at all | |
117 // if it's a link, hence preventing arbitary 'read' exploits | |
118 if (!file_util::IsLink(file_path.Append(entry.name))) | |
110 entries->push_back(entry); | 119 entries->push_back(entry); |
Evan Martin
2011/05/31 21:22:32
tabbing wrong here.
rkc
2011/05/31 21:49:56
Done.
| |
111 } | 120 } |
112 return base::PLATFORM_FILE_OK; | 121 return base::PLATFORM_FILE_OK; |
113 } | 122 } |
114 | 123 |
115 PlatformFileError FileSystemFileUtil::CreateDirectory( | 124 PlatformFileError FileSystemFileUtil::CreateDirectory( |
116 FileSystemOperationContext* unused, | 125 FileSystemOperationContext* unused, |
117 const FilePath& file_path, | 126 const FilePath& file_path, |
118 bool exclusive, | 127 bool exclusive, |
119 bool recursive) { | 128 bool recursive) { |
120 // If parent dir of file doesn't exist. | 129 // If parent dir of file doesn't exist. |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
445 FileSystemFileUtil::CreateFileEnumerator( | 454 FileSystemFileUtil::CreateFileEnumerator( |
446 FileSystemOperationContext* unused, | 455 FileSystemOperationContext* unused, |
447 const FilePath& root_path) { | 456 const FilePath& root_path) { |
448 return new FileSystemFileEnumerator( | 457 return new FileSystemFileEnumerator( |
449 root_path, true, static_cast<file_util::FileEnumerator::FILE_TYPE>( | 458 root_path, true, static_cast<file_util::FileEnumerator::FILE_TYPE>( |
450 file_util::FileEnumerator::FILES | | 459 file_util::FileEnumerator::FILES | |
451 file_util::FileEnumerator::DIRECTORIES)); | 460 file_util::FileEnumerator::DIRECTORIES)); |
452 } | 461 } |
453 | 462 |
454 } // namespace fileapi | 463 } // namespace fileapi |
OLD | NEW |