Arbiter  0.0.0
fs.hpp
1 #pragma once
2 
3 #ifndef ARBITER_IS_AMALGAMATION
4 #include <arbiter/driver.hpp>
5 
6 #ifndef ARBITER_EXTERNAL_JSON
7 #include <arbiter/third/json/json.hpp>
8 #endif
9 
10 #endif
11 
12 
13 
14 
15 #ifdef ARBITER_EXTERNAL_JSON
16 #include <json/json.h>
17 #endif
18 
19 #ifdef ARBITER_CUSTOM_NAMESPACE
20 namespace ARBITER_CUSTOM_NAMESPACE
21 {
22 #endif
23 
24 namespace arbiter
25 {
26 
27 class Arbiter;
28 
35 namespace fs
36 {
38  bool mkdirp(std::string dir);
39 
41  bool remove(std::string filename);
42 
45  std::string expandTilde(std::string path);
46 
48  std::string getTempPath();
49 
59  {
60  friend class arbiter::Arbiter;
61 
62  public:
68  ~LocalHandle();
69 
75  std::string localPath() const { return m_localPath; }
76 
83  std::string release()
84  {
85  m_erase = false;
86  return localPath();
87  }
88 
89  private:
90  LocalHandle(std::string localPath, bool isRemote);
91 
92  const std::string m_localPath;
93  bool m_erase;
94  };
95 }
98 namespace drivers
99 {
100 
102 class Fs : public Driver
103 {
104 public:
105  static std::unique_ptr<Fs> create(const Json::Value& json);
106 
107  virtual std::string type() const override { return "file"; }
108 
109  virtual std::unique_ptr<std::size_t> tryGetSize(
110  std::string path) const override;
111 
112  virtual void put(
113  std::string path,
114  const std::vector<char>& data) const override;
115 
116  virtual std::vector<std::string> glob(
117  std::string path,
118  bool verbose) const override;
119 
120  virtual bool isRemote() const override { return false; }
121 
122 protected:
123  virtual bool get(std::string path, std::vector<char>& data) const override;
124 };
125 
126 } // namespace drivers
127 
128 } // namespace arbiter
129 
130 #ifdef ARBITER_CUSTOM_NAMESPACE
131 }
132 #endif
133 
Base class for interacting with a storage type.
Definition: driver.hpp:34
std::string getTempPath()
Get temporary path from environment.
Definition: fs.cpp:265
virtual std::string type() const override
Definition: fs.hpp:107
bool mkdirp(std::string raw)
Returns true if created, false if already existed.
Definition: fs.cpp:204
bool isRemote(std::string path) const
Definition: arbiter.cpp:250
virtual bool isRemote() const override
Definition: fs.hpp:120
Definition: arbiter.cpp:16
std::string expandTilde(std::string in)
Performs tilde expansion to a fully-qualified path, if possible.
Definition: fs.cpp:251
The primary interface for storage abstraction.
Definition: arbiter.hpp:59
std::string release()
Release the managed local path and return the path from LocalHandle::localPath.
Definition: fs.hpp:83
Local filesystem driver.
Definition: fs.hpp:102
A scoped local filehandle for a possibly remote path.
Definition: fs.hpp:58
std::string localPath() const
Get the path of the locally stored file.
Definition: fs.hpp:75