diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-12 14:27:29 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2020-10-13 09:35:20 +0000 |
commit | c30a6232df03e1efbd9f3b226777b07e087a1122 (patch) | |
tree | e992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/base/files/file_util_posix.cc | |
parent | 7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff) | |
download | qtwebengine-chromium-85-based.tar.gz |
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/base/files/file_util_posix.cc')
-rw-r--r-- | chromium/base/files/file_util_posix.cc | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/chromium/base/files/file_util_posix.cc b/chromium/base/files/file_util_posix.cc index 91514251d9c..dea1a945826 100644 --- a/chromium/base/files/file_util_posix.cc +++ b/chromium/base/files/file_util_posix.cc @@ -367,14 +367,18 @@ FilePath MakeAbsoluteFilePath(const FilePath& input) { return FilePath(full_path); } -bool DeleteFile(const FilePath& path, bool recursive) { - return DoDeleteFile(path, recursive); +bool DeleteFile(const FilePath& path) { + return DoDeleteFile(path, /*recursive=*/false); } bool DeleteFileRecursively(const FilePath& path) { return DoDeleteFile(path, /*recursive=*/true); } +bool DeleteFile(const FilePath& path, bool recursive) { + return DoDeleteFile(path, recursive); +} + bool ReplaceFile(const FilePath& from_path, const FilePath& to_path, File::Error* error) { @@ -736,6 +740,37 @@ bool CreateDirectoryAndGetError(const FilePath& full_path, return true; } +// ReadFileToStringNonBlockingNonBlocking will read a file to a string. This +// method should only be used on files which are known to be non-blocking such +// as procfs or sysfs nodes. Additionally, the file is opened as O_NONBLOCK so +// it WILL NOT block even if opened on a blocking file. It will return true if +// the file read until EOF and it will return false otherwise, errno will remain +// set on error conditions. |ret| will be populated with the contents of the +// file. +bool ReadFileToStringNonBlocking(const base::FilePath& file, std::string* ret) { + DCHECK(ret); + ret->clear(); + + base::ScopedFD fd(HANDLE_EINTR( + open(file.MaybeAsASCII().c_str(), O_CLOEXEC | O_NONBLOCK | O_RDONLY))); + if (!fd.is_valid()) { + return false; + } + + ssize_t bytes_read = 0; + do { + char buf[4096]; + bytes_read = HANDLE_EINTR(read(fd.get(), buf, sizeof(buf))); + if (bytes_read < 0) { + return false; + } else if (bytes_read > 0) { + ret->append(buf, bytes_read); + } + } while (bytes_read > 0); + + return true; +} + bool NormalizeFilePath(const FilePath& path, FilePath* normalized_path) { FilePath real_path_result = MakeAbsoluteFilePath(path); if (real_path_result.empty()) |