1
#include "source/common/filesystem/file_shared_impl.h"
2

            
3
#include <random>
4

            
5
#include "source/common/common/utility.h"
6

            
7
namespace Envoy {
8
namespace Filesystem {
9

            
10
5
Api::IoError::IoErrorCode IoFileError::getErrorCode() const {
11
5
  switch (errno_) {
12
1
  case HANDLE_ERROR_PERM:
13
1
    return IoErrorCode::Permission;
14
3
  case HANDLE_ERROR_INVALID:
15
3
    return IoErrorCode::BadFd;
16
1
  default:
17
1
    ENVOY_LOG_MISC(debug, "Unknown error code {} details {}", errno_, getErrorDetails());
18
1
    return IoErrorCode::UnknownError;
19
5
  }
20
5
}
21

            
22
4
std::string IoFileError::getErrorDetails() const { return errorDetails(errno_); }
23

            
24
87728
bool FileSharedImpl::isOpen() const { return fd_ != INVALID_HANDLE; };
25

            
26
20174
absl::string_view FileSharedImpl::path() const { return filepath_and_type_.path_; };
27

            
28
67527
DestinationType FileSharedImpl::destinationType() const { return filepath_and_type_.file_type_; };
29

            
30
9
std::string FileSharedImpl::generateTmpFilePath(absl::string_view path) {
31
9
  static std::random_device rd;
32
9
  static std::mt19937 gen(rd());
33
9
  static std::uniform_int_distribution<> distribution('A', 'Z');
34
9
  std::array<char, 8> out;
35
81
  for (int i = 0; i < 8; i++) {
36
72
    out[i] = distribution(gen);
37
72
  }
38
9
  return absl::StrCat(path, "/envoy_", absl::string_view{&out[0], out.size()}, ".tmp");
39
9
}
40

            
41
} // namespace Filesystem
42
} // namespace Envoy