diff options
22 files changed, 90 insertions, 89 deletions
diff --git a/base/file_util.h b/base/file_util.h index 32dce3b..3c171f1 100644 --- a/base/file_util.h +++ b/base/file_util.h @@ -338,22 +338,22 @@ BASE_EXPORT int WriteFile(const FilePath& filename, const char* data, BASE_EXPORT int WriteFileDescriptor(const int fd, const char* data, int size); #endif -} // namespace base - -// ----------------------------------------------------------------------------- - -namespace file_util { - // Append the given buffer into the file. Returns the number of bytes written, // or -1 on error. -BASE_EXPORT int AppendToFile(const base::FilePath& filename, +BASE_EXPORT int AppendToFile(const FilePath& filename, const char* data, int size); // Gets the current working directory for the process. -BASE_EXPORT bool GetCurrentDirectory(base::FilePath* path); +BASE_EXPORT bool GetCurrentDirectory(FilePath* path); // Sets the current working directory for the process. -BASE_EXPORT bool SetCurrentDirectory(const base::FilePath& path); +BASE_EXPORT bool SetCurrentDirectory(const FilePath& path); + +} // namespace base + +// ----------------------------------------------------------------------------- + +namespace file_util { // Attempts to find a number that can be appended to the |path| to make it // unique. If |path| does not exist, 0 is returned. If it fails to find such diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc index 53c64da..db84c3f 100644 --- a/base/file_util_posix.cc +++ b/base/file_util_posix.cc @@ -739,6 +739,39 @@ int WriteFileDescriptor(const int fd, const char* data, int size) { return bytes_written_total; } +int AppendToFile(const FilePath& filename, const char* data, int size) { + ThreadRestrictions::AssertIOAllowed(); + int fd = HANDLE_EINTR(open(filename.value().c_str(), O_WRONLY | O_APPEND)); + if (fd < 0) + return -1; + + int bytes_written = WriteFileDescriptor(fd, data, size); + if (int ret = IGNORE_EINTR(close(fd)) < 0) + return ret; + return bytes_written; +} + +// Gets the current working directory for the process. +bool GetCurrentDirectory(FilePath* dir) { + // getcwd can return ENOENT, which implies it checks against the disk. + ThreadRestrictions::AssertIOAllowed(); + + char system_buffer[PATH_MAX] = ""; + if (!getcwd(system_buffer, sizeof(system_buffer))) { + NOTREACHED(); + return false; + } + *dir = FilePath(system_buffer); + return true; +} + +// Sets the current working directory for the process. +bool SetCurrentDirectory(const FilePath& path) { + ThreadRestrictions::AssertIOAllowed(); + int ret = chdir(path.value().c_str()); + return !ret; +} + } // namespace base // ----------------------------------------------------------------------------- @@ -777,39 +810,6 @@ FILE* OpenFile(const std::string& filename, const char* mode) { return OpenFile(FilePath(filename), mode); } -int AppendToFile(const FilePath& filename, const char* data, int size) { - base::ThreadRestrictions::AssertIOAllowed(); - int fd = HANDLE_EINTR(open(filename.value().c_str(), O_WRONLY | O_APPEND)); - if (fd < 0) - return -1; - - int bytes_written = base::WriteFileDescriptor(fd, data, size); - if (int ret = IGNORE_EINTR(close(fd)) < 0) - return ret; - return bytes_written; -} - -// Gets the current working directory for the process. -bool GetCurrentDirectory(FilePath* dir) { - // getcwd can return ENOENT, which implies it checks against the disk. - base::ThreadRestrictions::AssertIOAllowed(); - - char system_buffer[PATH_MAX] = ""; - if (!getcwd(system_buffer, sizeof(system_buffer))) { - NOTREACHED(); - return false; - } - *dir = FilePath(system_buffer); - return true; -} - -// Sets the current working directory for the process. -bool SetCurrentDirectory(const FilePath& path) { - base::ThreadRestrictions::AssertIOAllowed(); - int ret = chdir(path.value().c_str()); - return !ret; -} - bool VerifyPathControlledByUser(const FilePath& base, const FilePath& path, uid_t owner_uid, diff --git a/base/file_util_unittest.cc b/base/file_util_unittest.cc index f360c7a..5b8684f 100644 --- a/base/file_util_unittest.cc +++ b/base/file_util_unittest.cc @@ -1947,11 +1947,11 @@ TEST_F(FileUtilTest, AppendToFile) { FilePath foobar(data_dir.Append(FILE_PATH_LITERAL("foobar.txt"))); std::string data("hello"); - EXPECT_EQ(-1, file_util::AppendToFile(foobar, data.c_str(), data.length())); + EXPECT_EQ(-1, AppendToFile(foobar, data.c_str(), data.length())); EXPECT_EQ(static_cast<int>(data.length()), WriteFile(foobar, data.c_str(), data.length())); EXPECT_EQ(static_cast<int>(data.length()), - file_util::AppendToFile(foobar, data.c_str(), data.length())); + AppendToFile(foobar, data.c_str(), data.length())); const std::wstring read_content = ReadTextFile(foobar); EXPECT_EQ(L"hellohello", read_content); diff --git a/base/file_util_win.cc b/base/file_util_win.cc index 58e02dc..5350b34 100644 --- a/base/file_util_win.cc +++ b/base/file_util_win.cc @@ -631,23 +631,8 @@ int WriteFile(const FilePath& filename, const char* data, int size) { return -1; } -} // namespace base - -// ----------------------------------------------------------------------------- - -namespace file_util { - -using base::DirectoryExists; -using base::FilePath; -using base::kFileShareAll; - -FILE* OpenFile(const std::string& filename, const char* mode) { - base::ThreadRestrictions::AssertIOAllowed(); - return _fsopen(filename.c_str(), mode, _SH_DENYNO); -} - int AppendToFile(const FilePath& filename, const char* data, int size) { - base::ThreadRestrictions::AssertIOAllowed(); + ThreadRestrictions::AssertIOAllowed(); base::win::ScopedHandle file(CreateFile(filename.value().c_str(), FILE_APPEND_DATA, 0, @@ -657,7 +642,7 @@ int AppendToFile(const FilePath& filename, const char* data, int size) { NULL)); if (!file) { DLOG_GETLASTERROR(WARNING) << "CreateFile failed for path " - << filename.value(); + << UTF16ToUTF8(filename.value()); return -1; } @@ -668,19 +653,20 @@ int AppendToFile(const FilePath& filename, const char* data, int size) { if (!result) { // WriteFile failed. - DLOG_GETLASTERROR(WARNING) << "writing file " << filename.value() + DLOG_GETLASTERROR(WARNING) << "writing file " + << UTF16ToUTF8(filename.value()) << " failed"; } else { // Didn't write all the bytes. DLOG(WARNING) << "wrote" << written << " bytes to " - << filename.value() << " expected " << size; + << UTF16ToUTF8(filename.value()) << " expected " << size; } return -1; } // Gets the current working directory for the process. bool GetCurrentDirectory(FilePath* dir) { - base::ThreadRestrictions::AssertIOAllowed(); + ThreadRestrictions::AssertIOAllowed(); wchar_t system_buffer[MAX_PATH]; system_buffer[0] = 0; @@ -697,11 +683,26 @@ bool GetCurrentDirectory(FilePath* dir) { // Sets the current working directory for the process. bool SetCurrentDirectory(const FilePath& directory) { - base::ThreadRestrictions::AssertIOAllowed(); + ThreadRestrictions::AssertIOAllowed(); BOOL ret = ::SetCurrentDirectory(directory.value().c_str()); return ret != 0; } +} // namespace base + +// ----------------------------------------------------------------------------- + +namespace file_util { + +using base::DirectoryExists; +using base::FilePath; +using base::kFileShareAll; + +FILE* OpenFile(const std::string& filename, const char* mode) { + base::ThreadRestrictions::AssertIOAllowed(); + return _fsopen(filename.c_str(), mode, _SH_DENYNO); +} + int GetMaximumPathComponentLength(const FilePath& path) { base::ThreadRestrictions::AssertIOAllowed(); diff --git a/base/native_library_win.cc b/base/native_library_win.cc index 2d437fa..3d2af62 100644 --- a/base/native_library_win.cc +++ b/base/native_library_win.cc @@ -17,23 +17,23 @@ typedef HMODULE (WINAPI* LoadLibraryFunction)(const wchar_t* file_name); NativeLibrary LoadNativeLibraryHelper(const FilePath& library_path, LoadLibraryFunction load_library_api) { // LoadLibrary() opens the file off disk. - base::ThreadRestrictions::AssertIOAllowed(); + ThreadRestrictions::AssertIOAllowed(); // Switch the current directory to the library directory as the library // may have dependencies on DLLs in this directory. bool restore_directory = false; FilePath current_directory; - if (file_util::GetCurrentDirectory(¤t_directory)) { + if (GetCurrentDirectory(¤t_directory)) { FilePath plugin_path = library_path.DirName(); if (!plugin_path.empty()) { - file_util::SetCurrentDirectory(plugin_path); + SetCurrentDirectory(plugin_path); restore_directory = true; } } HMODULE module = (*load_library_api)(library_path.value().c_str()); if (restore_directory) - file_util::SetCurrentDirectory(current_directory); + SetCurrentDirectory(current_directory); return module; } diff --git a/base/path_service.cc b/base/path_service.cc index f0a6a84..61488d6 100644 --- a/base/path_service.cc +++ b/base/path_service.cc @@ -187,7 +187,7 @@ bool PathService::Get(int key, FilePath* result) { // special case the current directory because it can never be cached if (key == base::DIR_CURRENT) - return file_util::GetCurrentDirectory(result); + return base::GetCurrentDirectory(result); Provider* provider = NULL; { diff --git a/chrome/browser/chrome_process_finder_win.cc b/chrome/browser/chrome_process_finder_win.cc index 93116af..1599dac 100644 --- a/chrome/browser/chrome_process_finder_win.cc +++ b/chrome/browser/chrome_process_finder_win.cc @@ -164,7 +164,7 @@ NotifyChromeResult AttemptToNotifyRunningChrome(HWND remote_window, // Format is "START\0<<<current directory>>>\0<<<commandline>>>". std::wstring to_send(L"START\0", 6); // want the NULL in the string. base::FilePath cur_dir; - if (!file_util::GetCurrentDirectory(&cur_dir)) + if (!base::GetCurrentDirectory(&cur_dir)) return NOTIFY_FAILED; to_send.append(cur_dir.value()); to_send.append(L"\0", 1); // Null separator. diff --git a/chrome/browser/devtools/devtools_file_helper.cc b/chrome/browser/devtools/devtools_file_helper.cc index f3a10b5..107d4df 100644 --- a/chrome/browser/devtools/devtools_file_helper.cc +++ b/chrome/browser/devtools/devtools_file_helper.cc @@ -129,7 +129,7 @@ void AppendToFile(const base::FilePath& path, const std::string& content) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); DCHECK(!path.empty()); - file_util::AppendToFile(path, content.c_str(), content.length()); + base::AppendToFile(path, content.c_str(), content.length()); } fileapi::IsolatedContext* isolated_context() { diff --git a/chrome/browser/media_galleries/linux/mtp_read_file_worker.cc b/chrome/browser/media_galleries/linux/mtp_read_file_worker.cc index 456da92..88cec2e 100644 --- a/chrome/browser/media_galleries/linux/mtp_read_file_worker.cc +++ b/chrome/browser/media_galleries/linux/mtp_read_file_worker.cc @@ -28,8 +28,8 @@ uint32 WriteDataChunkIntoSnapshotFileOnFileThread( const std::string& data) { DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::FILE)); int bytes_written = - file_util::AppendToFile(snapshot_file_path, data.data(), - base::checked_cast<int>(data.size())); + base::AppendToFile(snapshot_file_path, data.data(), + base::checked_cast<int>(data.size())); return (static_cast<int>(data.size()) == bytes_written) ? base::checked_cast<uint32>(bytes_written) : 0; } diff --git a/chrome/browser/media_galleries/win/mtp_device_operations_util.cc b/chrome/browser/media_galleries/win/mtp_device_operations_util.cc index 6384e81..66d373d 100644 --- a/chrome/browser/media_galleries/win/mtp_device_operations_util.cc +++ b/chrome/browser/media_galleries/win/mtp_device_operations_util.cc @@ -386,7 +386,7 @@ DWORD CopyDataChunkToLocalFile(IStream* stream, base::checked_cast<int>( std::min(bytes_read, base::checked_cast<DWORD>(buffer.length()))); - if (file_util::AppendToFile(local_path, buffer.c_str(), data_len) != data_len) + if (base::AppendToFile(local_path, buffer.c_str(), data_len) != data_len) return 0U; return data_len; } diff --git a/chrome/browser/net/net_log_temp_file_unittest.cc b/chrome/browser/net/net_log_temp_file_unittest.cc index 78f55d1..ba5b6f3 100644 --- a/chrome/browser/net/net_log_temp_file_unittest.cc +++ b/chrome/browser/net/net_log_temp_file_unittest.cc @@ -232,7 +232,7 @@ TEST_F(NetLogTempFileTest, DoStartClearsFile) { // Add some junk at the end of the file. std::string junk_data("Hello"); - EXPECT_GT(file_util::AppendToFile( + EXPECT_GT(base::AppendToFile( net_export_log_, junk_data.c_str(), junk_data.size()), 0); int64 junk_file_size; diff --git a/chrome/common/net/url_fixer_upper.cc b/chrome/common/net/url_fixer_upper.cc index 3679d59..5c72023 100644 --- a/chrome/common/net/url_fixer_upper.cc +++ b/chrome/common/net/url_fixer_upper.cc @@ -585,8 +585,8 @@ GURL URLFixerUpper::FixupRelativeFile(const base::FilePath& base_dir, base::FilePath old_cur_directory; if (!base_dir.empty()) { // Save the old current directory before we move to the new one. - file_util::GetCurrentDirectory(&old_cur_directory); - file_util::SetCurrentDirectory(base_dir); + base::GetCurrentDirectory(&old_cur_directory); + base::SetCurrentDirectory(base_dir); } // Allow funny input with extra whitespace and the wrong kind of slashes. @@ -619,7 +619,7 @@ GURL URLFixerUpper::FixupRelativeFile(const base::FilePath& base_dir, // Put back the current directory if we saved it. if (!base_dir.empty()) - file_util::SetCurrentDirectory(old_cur_directory); + base::SetCurrentDirectory(old_cur_directory); if (is_file) { GURL file_url = net::FilePathToFileURL(full_path); diff --git a/chrome/installer/setup/uninstall.cc b/chrome/installer/setup/uninstall.cc index 430b3b3..3ffc12c 100644 --- a/chrome/installer/setup/uninstall.cc +++ b/chrome/installer/setup/uninstall.cc @@ -495,7 +495,7 @@ bool MoveSetupOutOfInstallFolder(const InstallerState& installer_state, // Change the current directory to the TMP directory. See method comment above // for details. VLOG(1) << "Changing current directory to: " << tmp_dir.value(); - if (!file_util::SetCurrentDirectory(tmp_dir)) + if (!base::SetCurrentDirectory(tmp_dir)) PLOG(ERROR) << "Failed to change the current directory."; for (std::vector<base::FilePath>::const_iterator it = setup_files.begin(); diff --git a/components/policy/core/common/policy_loader_win_unittest.cc b/components/policy/core/common/policy_loader_win_unittest.cc index 4b066ee..7ddc783 100644 --- a/components/policy/core/common/policy_loader_win_unittest.cc +++ b/components/policy/core/common/policy_loader_win_unittest.cc @@ -589,7 +589,7 @@ void PRegTestHarness::AppendRecordToPRegFile(const base::string16& path, AppendChars(&buffer, L"]"); ASSERT_EQ(buffer.size(), - file_util::AppendToFile( + base::AppendToFile( preg_file_path_, reinterpret_cast<const char*>(vector_as_array(&buffer)), buffer.size())); diff --git a/content/common/gpu/media/vaapi_h264_decoder_unittest.cc b/content/common/gpu/media/vaapi_h264_decoder_unittest.cc index 309dde3..6bd873e 100644 --- a/content/common/gpu/media/vaapi_h264_decoder_unittest.cc +++ b/content/common/gpu/media/vaapi_h264_decoder_unittest.cc @@ -248,7 +248,7 @@ bool VaapiH264DecoderLoop::ProcessVideoFrame( int to_write = media::VideoFrame::PlaneAllocationSize( frame->format(), i, frame->coded_size()); const char* buf = reinterpret_cast<const char*>(frame->data(i)); - int written = file_util::AppendToFile(output_file_, buf, to_write); + int written = base::AppendToFile(output_file_, buf, to_write); if (written != to_write) return false; } diff --git a/content/common/gpu/media/video_encode_accelerator_unittest.cc b/content/common/gpu/media/video_encode_accelerator_unittest.cc index 7593d9d..413d42c 100644 --- a/content/common/gpu/media/video_encode_accelerator_unittest.cc +++ b/content/common/gpu/media/video_encode_accelerator_unittest.cc @@ -497,7 +497,7 @@ void VEAClient::BitstreamBufferReady(int32 bitstream_buffer_id, if (save_to_file_) { int size = base::checked_cast<int>(payload_size); - EXPECT_EQ(file_util::AppendToFile( + EXPECT_EQ(base::AppendToFile( base::FilePath::FromUTF8Unsafe(test_stream_.out_filename), static_cast<char*>(shm->memory()), size), diff --git a/content/shell/browser/shell_browser_main.cc b/content/shell/browser/shell_browser_main.cc index b673d31..f8e1c26 100644 --- a/content/shell/browser/shell_browser_main.cc +++ b/content/shell/browser/shell_browser_main.cc @@ -87,7 +87,7 @@ GURL GetURLForLayoutTest(const std::string& test_name, if (net::FileURLToFilePath(test_url, &local_path)) *current_working_directory = local_path.DirName(); else - file_util::GetCurrentDirectory(current_working_directory); + base::GetCurrentDirectory(current_working_directory); } return test_url; } diff --git a/gin/shell/gin_main.cc b/gin/shell/gin_main.cc index 3b990f0..6673b6a 100644 --- a/gin/shell/gin_main.cc +++ b/gin/shell/gin_main.cc @@ -33,7 +33,7 @@ void Run(base::WeakPtr<Runner> runner, const base::FilePath& path) { std::vector<base::FilePath> GetModuleSearchPaths() { std::vector<base::FilePath> module_base(1); - CHECK(file_util::GetCurrentDirectory(&module_base[0])); + CHECK(base::GetCurrentDirectory(&module_base[0])); return module_base; } diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc index 68507f8..3ef7b1b 100644 --- a/net/url_request/url_request_unittest.cc +++ b/net/url_request/url_request_unittest.cc @@ -4735,7 +4735,7 @@ TEST_F(URLRequestTestHTTP, PostFileTest) { base::FilePath dir; PathService::Get(base::DIR_EXE, &dir); - file_util::SetCurrentDirectory(dir); + base::SetCurrentDirectory(dir); ScopedVector<UploadElementReader> element_readers; diff --git a/tools/gn/filesystem_utils.cc b/tools/gn/filesystem_utils.cc index fbc8506..18d31d0 100644 --- a/tools/gn/filesystem_utils.cc +++ b/tools/gn/filesystem_utils.cc @@ -666,7 +666,7 @@ SourceDir SourceDirForPath(const base::FilePath& source_root, SourceDir SourceDirForCurrentDirectory(const base::FilePath& source_root) { base::FilePath cd; - file_util::GetCurrentDirectory(&cd); + base::GetCurrentDirectory(&cd); return SourceDirForPath(source_root, cd); } diff --git a/tools/gn/function_exec_script.cc b/tools/gn/function_exec_script.cc index 4178925..34723e5 100644 --- a/tools/gn/function_exec_script.cc +++ b/tools/gn/function_exec_script.cc @@ -193,7 +193,7 @@ bool ExecProcess(const CommandLine& cmdline, if (!ShuffleFileDescriptors(&fd_shuffle1)) _exit(127); - file_util::SetCurrentDirectory(startup_dir); + base::SetCurrentDirectory(startup_dir); // TODO(brettw) the base version GetAppOutput does a // CloseSuperfluousFds call here. Do we need this? diff --git a/tools/gn/setup.cc b/tools/gn/setup.cc index 0c969ab..759b40a 100644 --- a/tools/gn/setup.cc +++ b/tools/gn/setup.cc @@ -274,7 +274,7 @@ bool Setup::FillSourceDir(const CommandLine& cmdline) { dotfile_name_ = root_path.Append(kGnFile); } else { base::FilePath cur_dir; - file_util::GetCurrentDirectory(&cur_dir); + base::GetCurrentDirectory(&cur_dir); dotfile_name_ = FindDotFile(cur_dir); if (dotfile_name_.empty()) { Err(Location(), "Can't find source root.", |