| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <fnmatch.h> | 9 #include <fnmatch.h> |
| 10 #include <fts.h> | 10 #include <fts.h> |
| 11 #include <libgen.h> | 11 #include <libgen.h> |
| 12 #include <stdio.h> | 12 #include <stdio.h> |
| 13 #include <string.h> | 13 #include <string.h> |
| 14 #include <sys/errno.h> | 14 #include <sys/errno.h> |
| 15 #include <sys/stat.h> | 15 #include <sys/stat.h> |
| 16 #include <time.h> | 16 #include <time.h> |
| 17 | 17 |
| 18 #include <fstream> | 18 #include <fstream> |
| 19 | 19 |
| 20 #include "base/basictypes.h" | 20 #include "base/basictypes.h" |
| 21 #include "base/file_path.h" | 21 #include "base/file_path.h" |
| 22 #include "base/logging.h" | 22 #include "base/logging.h" |
| 23 #include "base/string_util.h" | 23 #include "base/string_util.h" |
| 24 | 24 |
| 25 namespace file_util { | 25 namespace file_util { |
| 26 | 26 |
| 27 static const wchar_t* kTempFileName = L"com.google.chrome.XXXXXX"; | 27 static const char* kTempFileName = "com.google.chrome.XXXXXX"; |
| 28 | 28 |
| 29 std::wstring GetDirectoryFromPath(const std::wstring& path) { | 29 std::wstring GetDirectoryFromPath(const std::wstring& path) { |
| 30 if (EndsWithSeparator(path)) { | 30 if (EndsWithSeparator(path)) { |
| 31 std::wstring dir = path; | 31 std::wstring dir = path; |
| 32 TrimTrailingSeparator(&dir); | 32 TrimTrailingSeparator(&dir); |
| 33 return dir; | 33 return dir; |
| 34 } else { | 34 } else { |
| 35 char full_path[PATH_MAX]; | 35 char full_path[PATH_MAX]; |
| 36 base::strlcpy(full_path, WideToUTF8(path).c_str(), arraysize(full_path)); | 36 base::strlcpy(full_path, WideToUTF8(path).c_str(), arraysize(full_path)); |
| 37 return UTF8ToWide(dirname(full_path)); | 37 return UTF8ToWide(dirname(full_path)); |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 242 bool GetFileCreationLocalTime(const std::string& filename, | 242 bool GetFileCreationLocalTime(const std::string& filename, |
| 243 LPSYSTEMTIME creation_time) { | 243 LPSYSTEMTIME creation_time) { |
| 244 ScopedHandle file_handle( | 244 ScopedHandle file_handle( |
| 245 CreateFile(filename.c_str(), GENERIC_READ, | 245 CreateFile(filename.c_str(), GENERIC_READ, |
| 246 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, | 246 FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, |
| 247 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)); | 247 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)); |
| 248 return GetFileCreationLocalTimeFromHandle(file_handle.Get(), creation_time); | 248 return GetFileCreationLocalTimeFromHandle(file_handle.Get(), creation_time); |
| 249 } | 249 } |
| 250 #endif | 250 #endif |
| 251 | 251 |
| 252 bool CreateTemporaryFileName(std::wstring* temp_file) { | 252 bool CreateTemporaryFileName(FilePath* path) { |
| 253 std::wstring tmpdir; | 253 if (!GetTempDir(path)) |
| 254 if (!GetTempDir(&tmpdir)) | |
| 255 return false; | 254 return false; |
| 256 AppendToPath(&tmpdir, kTempFileName); | 255 |
| 257 std::string tmpdir_string = WideToUTF8(tmpdir); | 256 *path = path->Append(kTempFileName); |
| 257 std::string tmpdir_string = path->value(); |
| 258 // this should be OK since mkstemp just replaces characters in place | 258 // this should be OK since mkstemp just replaces characters in place |
| 259 char* buffer = const_cast<char*>(tmpdir_string.c_str()); | 259 char* buffer = const_cast<char*>(tmpdir_string.c_str()); |
| 260 |
| 260 int fd = mkstemp(buffer); | 261 int fd = mkstemp(buffer); |
| 261 if (fd < 0) | 262 if (fd < 0) |
| 262 return false; | 263 return false; |
| 263 *temp_file = UTF8ToWide(buffer); | 264 |
| 264 close(fd); | 265 close(fd); |
| 265 return true; | 266 return true; |
| 266 } | 267 } |
| 267 | 268 |
| 268 bool CreateTemporaryFileNameInDir(const std::wstring& dir, | 269 bool CreateTemporaryFileNameInDir(const std::wstring& dir, |
| 269 std::wstring* temp_file) { | 270 std::wstring* temp_file) { |
| 270 // Not implemented yet. | 271 // Not implemented yet. |
| 271 NOTREACHED(); | 272 NOTREACHED(); |
| 272 return false; | 273 return false; |
| 273 } | 274 } |
| 274 | 275 |
| 275 bool CreateNewTempDirectory(const std::wstring& prefix, | 276 bool CreateNewTempDirectory(const std::wstring& prefix, |
| 276 std::wstring* new_temp_path) { | 277 std::wstring* new_temp_path) { |
| 277 std::wstring tmpdir; | 278 FilePath tmpdir; |
| 278 if (!GetTempDir(&tmpdir)) | 279 if (!GetTempDir(&tmpdir)) |
| 279 return false; | 280 return false; |
| 280 AppendToPath(&tmpdir, kTempFileName); | 281 tmpdir = tmpdir.Append(kTempFileName); |
| 281 std::string tmpdir_string = WideToUTF8(tmpdir); | 282 std::string tmpdir_string = tmpdir.value(); |
| 282 // this should be OK since mkdtemp just replaces characters in place | 283 // this should be OK since mkdtemp just replaces characters in place |
| 283 char* buffer = const_cast<char*>(tmpdir_string.c_str()); | 284 char* buffer = const_cast<char*>(tmpdir_string.c_str()); |
| 284 char* dtemp = mkdtemp(buffer); | 285 char* dtemp = mkdtemp(buffer); |
| 285 if (!dtemp) | 286 if (!dtemp) |
| 286 return false; | 287 return false; |
| 287 *new_temp_path = UTF8ToWide(dtemp); | 288 *new_temp_path = UTF8ToWide(dtemp); |
| 288 return true; | 289 return true; |
| 289 } | 290 } |
| 290 | 291 |
| 291 bool CreateDirectory(const FilePath& full_path) { | 292 bool CreateDirectory(const FilePath& full_path) { |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 return (file_type_ & FileEnumerator::DIRECTORIES) ? cur_file : Next(); | 464 return (file_type_ & FileEnumerator::DIRECTORIES) ? cur_file : Next(); |
| 464 } else if (fts_ent->fts_info == FTS_F) { | 465 } else if (fts_ent->fts_info == FTS_F) { |
| 465 return (file_type_ & FileEnumerator::FILES) ? cur_file : Next(); | 466 return (file_type_ & FileEnumerator::FILES) ? cur_file : Next(); |
| 466 } | 467 } |
| 467 // TODO(erikkay) - verify that the other fts_info types aren't interesting | 468 // TODO(erikkay) - verify that the other fts_info types aren't interesting |
| 468 return Next(); | 469 return Next(); |
| 469 } | 470 } |
| 470 | 471 |
| 471 | 472 |
| 472 } // namespace file_util | 473 } // namespace file_util |
| OLD | NEW |