1 // Copyright 2023 Google LLC
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #pragma once
16 
17 #include <filesystem>
18 #include <system_error>
19 
20 namespace google
21 {
22 namespace ipmi
23 {
24 namespace fs = std::filesystem;
25 
26 class FileSystemInterface
27 {
28   public:
29     virtual ~FileSystemInterface() = default;
30 
31     /**
32      * Checks if the given file status or path corresponds to an existing file
33      * or directory
34      *
35      * @param[in] path - path to examine.
36      * @param[in] ec - out-parameter for error reporting in the non-throwing
37      * overload
38      * @return the name of the device.
39      */
40     virtual bool exists(const fs::path& path, std::error_code& ec) const = 0;
41 
42     /**
43      * Moves or renames the filesystem object identified by oldPath to newPath
44      *
45      * @param[in] oldPath - path to move or rename.
46      * @param[in] newPath - target path for the move/rename operation.
47      * @param[in] ec - out-parameter for error reporting in the non-throwing
48      * overload
49      * @return the name of the device.
50      */
51     virtual void rename(const fs::path& oldPath, const fs::path& newPath,
52                         std::error_code& ec) const = 0;
53 
54     /**
55      * Create an empty file at path specified
56      *
57      * @param[in] path - path to create the empty file.
58      * @return the name of the device.
59      */
60     virtual void create(const char* path) const = 0;
61 };
62 
63 } // namespace ipmi
64 } // namespace google
65