From 7e1fde6a79fbc323f22a132dba6777dcd3464218 Mon Sep 17 00:00:00 2001 From: "erikkay@google.com" Date: Tue, 23 Dec 2008 20:20:10 +0000 Subject: file_util minor cleanup: * add POSIX version of IsPathWritable * convert IsPathWritable to FilePath * convert CreateNewTempDirectory to FilePath * fix a bug where recursive delete errors weren't being handled in POSIX Review URL: http://codereview.chromium.org/16241 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7430 0039d316-1c4b-4281-b951-d872f2087c98 --- base/file_util_win.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'base/file_util_win.cc') diff --git a/base/file_util_win.cc b/base/file_util_win.cc index 8f372b1..c2dbf0a 100644 --- a/base/file_util_win.cc +++ b/base/file_util_win.cc @@ -168,9 +168,9 @@ bool PathExists(const FilePath& path) { return (GetFileAttributes(path.value().c_str()) != INVALID_FILE_ATTRIBUTES); } -bool PathIsWritable(const std::wstring& path) { +bool PathIsWritable(const FilePath& path) { HANDLE dir = - CreateFile(path.c_str(), FILE_ADD_FILE, + CreateFile(path.value().c_str(), FILE_ADD_FILE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); @@ -421,26 +421,26 @@ bool CreateTemporaryFileNameInDir(const std::wstring& dir, return true; } -bool CreateNewTempDirectory(const std::wstring& prefix, - std::wstring* new_temp_path) { - std::wstring system_temp_dir; +bool CreateNewTempDirectory(const FilePath::StringType& prefix, + FilePath* new_temp_path) { + FilePath system_temp_dir; if (!GetTempDir(&system_temp_dir)) return false; - std::wstring path_to_create; + FilePath path_to_create; srand(static_cast(time(NULL))); int count = 0; while (count < 50) { // Try create a new temporary directory with random generated name. If // the one exists, keep trying another path name until we reach some limit. - path_to_create.assign(system_temp_dir); + path_to_create = system_temp_dir; std::wstring new_dir_name; new_dir_name.assign(prefix); new_dir_name.append(IntToWString(rand() % kint16max)); - file_util::AppendToPath(&path_to_create, new_dir_name); + path_to_create = path_to_create.Append(new_dir_name); - if (::CreateDirectory(path_to_create.c_str(), NULL)) + if (::CreateDirectory(path_to_create.value().c_str(), NULL)) break; count++; } @@ -449,7 +449,7 @@ bool CreateNewTempDirectory(const std::wstring& prefix, return false; } - new_temp_path->assign(path_to_create); + *new_temp_path = path_to_create; return true; } -- cgit v1.1