LCOV - code coverage report
Current view: top level - source/common/filesystem/posix - filesystem_impl.h (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 1 2 50.0 %
Date: 2024-01-05 06:35:25 Functions: 1 2 50.0 %

          Line data    Source code
       1             : #pragma once
       2             : 
       3             : #include <cstdint>
       4             : #include <string>
       5             : 
       6             : #include "envoy/api/os_sys_calls.h"
       7             : 
       8             : #include "source/common/filesystem/file_shared_impl.h"
       9             : 
      10             : namespace Envoy {
      11             : namespace Filesystem {
      12             : 
      13             : class FileImplPosix : public FileSharedImpl {
      14             : public:
      15         206 :   FileImplPosix(const FilePathAndType& file_info) : FileSharedImpl(file_info) {}
      16             :   ~FileImplPosix() override;
      17             : 
      18             : protected:
      19             :   struct FlagsAndMode {
      20             :     int flags_ = 0;
      21             :     mode_t mode_ = 0;
      22             :   };
      23             : 
      24             :   Api::IoCallBoolResult open(FlagSet flag) override;
      25             :   Api::IoCallSizeResult write(absl::string_view buffer) override;
      26             :   Api::IoCallBoolResult close() override;
      27             :   Api::IoCallSizeResult pread(void* buf, uint64_t count, uint64_t offset) override;
      28             :   Api::IoCallSizeResult pwrite(const void* buf, uint64_t count, uint64_t offset) override;
      29             :   Api::IoCallResult<FileInfo> info() override;
      30             :   FlagsAndMode translateFlag(FlagSet in);
      31             : 
      32             : private:
      33             :   friend class FileSystemImplTest;
      34             : };
      35             : 
      36             : class TmpFileImplPosix : public FileImplPosix {
      37             : public:
      38           0 :   TmpFileImplPosix(const FilePathAndType& file_info) : FileImplPosix(file_info) {}
      39             :   Api::IoCallBoolResult open(FlagSet flag) override;
      40             :   Api::IoCallBoolResult close() override;
      41             :   ~TmpFileImplPosix() override;
      42             : 
      43             : private:
      44             :   // Ideally opening a tmp file opens it with no name; this is a fallback option for
      45             :   // when the OS or filesystem doesn't support that. with_unlink is a test-only
      46             :   // parameter to allow us to also test-cover the path where unlinking an open file
      47             :   // doesn't work.
      48             :   Api::IoCallBoolResult openNamedTmpFile(FlagsAndMode flags_and_mode, bool with_unlink = true);
      49             :   // This is only set in the case where the file system does not support nameless tmp files.
      50             :   std::string tmp_file_path_;
      51             :   friend class FileSystemImplTest;
      52             : };
      53             : 
      54             : class InstanceImplPosix : public Instance {
      55             : public:
      56             :   // Filesystem::Instance
      57             :   FilePtr createFile(const FilePathAndType& file_info) override;
      58             :   bool fileExists(const std::string& path) override;
      59             :   bool directoryExists(const std::string& path) override;
      60             :   ssize_t fileSize(const std::string& path) override;
      61             :   absl::StatusOr<std::string> fileReadToEnd(const std::string& path) override;
      62             :   absl::StatusOr<PathSplitResult> splitPathFromFilename(absl::string_view path) override;
      63             :   bool illegalPath(const std::string& path) override;
      64             :   Api::IoCallResult<FileInfo> stat(absl::string_view path) override;
      65             :   Api::IoCallBoolResult createPath(absl::string_view path) override;
      66             : 
      67             : private:
      68             :   Api::SysCallStringResult canonicalPath(const std::string& path);
      69             :   friend class FileSystemImplTest;
      70             : };
      71             : 
      72             : using FileImpl = FileImplPosix;
      73             : using InstanceImpl = InstanceImplPosix;
      74             : } // namespace Filesystem
      75             : } // namespace Envoy

Generated by: LCOV version 1.15