| /* |
| * Copyright 2020 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| #pragma once |
| |
| #include <chrono> |
| #include <iterator> |
| #include <optional> |
| |
| namespace bluetooth { |
| namespace os { |
| |
| // Return true if |path| exists on disk |
| bool FileExists(const std::string& path); |
| |
| // Rename file from |from| to |to| |
| bool RenameFile(const std::string& from, const std::string& to); |
| |
| // Implement ability to read a whole file from |path| into a C++ string, return std::nullopt on failure |
| // |
| // Do not use this with large files |
| std::optional<std::string> ReadSmallFile(const std::string& path); |
| |
| // Implement ability to safely write to a file. This function is needed because of deficiencies in existing C++ file |
| // libraries, namely: |
| // - The ability to open and sync directories with storage media |
| // - The ability to block and sync file to storage media |
| // Return true on success, false on failure |
| bool WriteToFile(const std::string& path, const std::string& data); |
| |
| // Remove file and print error message if failed |
| // Print error log when file is failed to be removed, hence user should make sure file exists before calling this |
| // Return true on success, false on failure (e.g. file not exist, failed to remove, etc) |
| bool RemoveFile(const std::string& path); |
| |
| // Returns created time_point of given file, return std::nullopt on failure |
| std::optional<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> FileCreatedTime( |
| const std::string& path); |
| |
| } // namespace os |
| } // namespace bluetooth |