Line data Source code
1 : #pragma once 2 : 3 : #include <string> 4 : 5 : #include "envoy/filesystem/filesystem.h" 6 : 7 : #include "source/common/common/assert.h" 8 : 9 : namespace Envoy { 10 : namespace Filesystem { 11 : 12 : class IoFileError : public Api::IoError { 13 : public: 14 0 : explicit IoFileError(int sys_errno) : errno_(sys_errno) {} 15 : 16 0 : ~IoFileError() override = default; 17 : 18 : Api::IoError::IoErrorCode getErrorCode() const override; 19 : std::string getErrorDetails() const override; 20 0 : int getSystemErrorCode() const override { return errno_; } 21 : 22 : private: 23 : const int errno_; 24 : }; 25 : 26 : using IoFileErrorPtr = std::unique_ptr<IoFileError, Api::IoErrorDeleterType>; 27 : 28 0 : template <typename T> Api::IoCallResult<T> resultFailure(T result, int sys_errno) { 29 0 : return {result, IoFileErrorPtr(new IoFileError(sys_errno), [](Api::IoError* err) { 30 0 : ASSERT(err != nullptr); 31 0 : delete err; 32 0 : })}; 33 0 : } 34 : 35 1467 : template <typename T> Api::IoCallResult<T> resultSuccess(T result) { 36 1467 : return {result, IoFileErrorPtr(nullptr, [](Api::IoError*) { PANIC("unimplemented"); })}; 37 1467 : } 38 : 39 : class FileSharedImpl : public File { 40 : public: 41 : FileSharedImpl(const FilePathAndType& filepath_and_type) 42 659 : : filepath_and_type_(filepath_and_type) {} 43 : 44 659 : ~FileSharedImpl() override = default; 45 : 46 : bool isOpen() const override; 47 : std::string path() const override; 48 : DestinationType destinationType() const override; 49 : 50 : protected: 51 : filesystem_os_id_t fd_{INVALID_HANDLE}; 52 : const FilePathAndType filepath_and_type_; 53 : static std::string generateTmpFilePath(absl::string_view path); 54 : }; 55 : 56 : } // namespace Filesystem 57 : } // namespace Envoy