uvw  1.3.0
fs.hpp
1 #pragma once
2 
3 
4 #include <utility>
5 #include <memory>
6 #include <string>
7 #include <chrono>
8 #include <uv.h>
9 #include "request.hpp"
10 #include "util.hpp"
11 #include "loop.hpp"
12 
13 
14 namespace uvw {
15 
16 
17 namespace details {
18 
19 
20 enum class UVFsType: std::underlying_type_t<uv_fs_type> {
21  UNKNOWN = UV_FS_UNKNOWN,
22  CUSTOM = UV_FS_CUSTOM,
23  OPEN = UV_FS_OPEN,
24  CLOSE = UV_FS_CLOSE,
25  READ = UV_FS_READ,
26  WRITE = UV_FS_WRITE,
27  SENDFILE = UV_FS_SENDFILE,
28  STAT = UV_FS_STAT,
29  LSTAT = UV_FS_LSTAT,
30  FSTAT = UV_FS_FSTAT,
31  FTRUNCATE = UV_FS_FTRUNCATE,
32  UTIME = UV_FS_UTIME,
33  FUTIME = UV_FS_FUTIME,
34  ACCESS = UV_FS_ACCESS,
35  CHMOD = UV_FS_CHMOD,
36  FCHMOD = UV_FS_FCHMOD,
37  FSYNC = UV_FS_FSYNC,
38  FDATASYNC = UV_FS_FDATASYNC,
39  UNLINK = UV_FS_UNLINK,
40  RMDIR = UV_FS_RMDIR,
41  MKDIR = UV_FS_MKDIR,
42  MKDTEMP = UV_FS_MKDTEMP,
43  RENAME = UV_FS_RENAME,
44  SCANDIR = UV_FS_SCANDIR,
45  LINK = UV_FS_LINK,
46  SYMLINK = UV_FS_SYMLINK,
47  READLINK = UV_FS_READLINK,
48  CHOWN = UV_FS_CHOWN,
49  FCHOWN = UV_FS_FCHOWN,
50  REALPATH = UV_FS_REALPATH,
51  COPYFILE = UV_FS_COPYFILE
52 };
53 
54 
55 enum class UVDirentTypeT: std::underlying_type_t<uv_dirent_type_t> {
56  UNKNOWN = UV_DIRENT_UNKNOWN,
57  FILE = UV_DIRENT_FILE,
58  DIR = UV_DIRENT_DIR,
59  LINK = UV_DIRENT_LINK,
60  FIFO = UV_DIRENT_FIFO,
61  SOCKET = UV_DIRENT_SOCKET,
62  CHAR = UV_DIRENT_CHAR,
63  BLOCK = UV_DIRENT_BLOCK
64 };
65 
66 
67 enum class UVCopyFileFlags: int {
68  EXCL = UV_FS_COPYFILE_EXCL
69 };
70 
71 
72 enum class UVSymLinkFlags: int {
73  DIR = UV_FS_SYMLINK_DIR,
74  JUNCTION = UV_FS_SYMLINK_JUNCTION
75 };
76 
77 
78 }
79 
80 
125 template<details::UVFsType e>
126 struct FsEvent {
127  FsEvent(const char *pathname) noexcept: path{pathname} {}
128 
129  const char * path;
130 };
131 
132 
139 template<>
140 struct FsEvent<details::UVFsType::READ> {
141  FsEvent(const char *pathname, std::unique_ptr<const char[]> buf, std::size_t sz) noexcept
142  : path{pathname}, data{std::move(buf)}, size{sz}
143  {}
144 
145  const char * path;
146  std::unique_ptr<const char[]> data;
147  std::size_t size;
148 };
149 
150 
157 template<>
158 struct FsEvent<details::UVFsType::WRITE> {
159  FsEvent(const char *pathname, std::size_t sz) noexcept
160  : path{pathname}, size{sz}
161  {}
162 
163  const char * path;
164  std::size_t size;
165 };
166 
167 
174 template<>
175 struct FsEvent<details::UVFsType::SENDFILE> {
176  FsEvent(const char *pathname, std::size_t sz) noexcept
177  : path{pathname}, size{sz}
178  {}
179 
180  const char * path;
181  std::size_t size;
182 };
183 
184 
191 template<>
192 struct FsEvent<details::UVFsType::STAT> {
193  FsEvent(const char *pathname, Stat curr) noexcept
194  : path{pathname}, stat{std::move(curr)}
195  {}
196 
197  const char * path;
199 };
200 
201 
208 template<>
209 struct FsEvent<details::UVFsType::FSTAT> {
210  FsEvent(const char *pathname, Stat curr) noexcept
211  : path{pathname}, stat{std::move(curr)}
212  {}
213 
214  const char * path;
216 };
217 
218 
225 template<>
226 struct FsEvent<details::UVFsType::LSTAT> {
227  FsEvent(const char *pathname, Stat curr) noexcept
228  : path{pathname}, stat{std::move(curr)}
229  {}
230 
231  const char * path;
233 };
234 
235 
242 template<>
243 struct FsEvent<details::UVFsType::SCANDIR> {
244  FsEvent(const char *pathname, std::size_t sz) noexcept
245  : path{pathname}, size{sz}
246  {}
247 
248  const char * path;
249  std::size_t size;
250 };
251 
252 
259 template<>
260 struct FsEvent<details::UVFsType::READLINK> {
261  explicit FsEvent(const char *pathname, const char *buf, std::size_t sz) noexcept
262  : path{pathname}, data{buf}, size{sz}
263  {}
264 
265  const char * path;
266  const char * data;
267  std::size_t size;
268 };
269 
270 
276 template<typename T>
277 class FsRequest: public Request<T, uv_fs_t> {
278 protected:
279  template<details::UVFsType e>
280  static void fsGenericCallback(uv_fs_t *req) {
281  auto ptr = Request<T, uv_fs_t>::reserve(req);
282  if(req->result < 0) { ptr->publish(ErrorEvent{req->result}); }
283  else { ptr->publish(FsEvent<e>{req->path}); }
284  }
285 
286  template<details::UVFsType e>
287  static void fsResultCallback(uv_fs_t *req) {
288  auto ptr = Request<T, uv_fs_t>::reserve(req);
289  if(req->result < 0) { ptr->publish(ErrorEvent{req->result}); }
290  else { ptr->publish(FsEvent<e>{req->path, static_cast<std::size_t>(req->result)}); }
291  }
292 
293  template<details::UVFsType e>
294  static void fsStatCallback(uv_fs_t *req) {
295  auto ptr = Request<T, uv_fs_t>::reserve(req);
296  if(req->result < 0) { ptr->publish(ErrorEvent{req->result}); }
297  else { ptr->publish(FsEvent<e>{req->path, req->statbuf}); }
298  }
299 
300  template<typename... Args>
301  void cleanupAndInvoke(Args&&... args) {
302  uv_fs_req_cleanup(this->get());
303  this->invoke(std::forward<Args>(args)...);
304  }
305 
306  template<typename F, typename... Args>
307  void cleanupAndInvokeSync(F &&f, Args&&... args) {
308  uv_fs_req_cleanup(this->get());
309  std::forward<F>(f)(std::forward<Args>(args)..., nullptr);
310  }
311 
312 public:
313  using Time = std::chrono::duration<double>;
314  using Type = details::UVFsType;
315  using EntryType = details::UVDirentTypeT;
316  using Entry = std::pair<EntryType, std::string>;
317 
318  using Request<T, uv_fs_t>::Request;
319 };
320 
321 
334 class FileReq final: public FsRequest<FileReq> {
335  static constexpr uv_file BAD_FD = -1;
336 
337  static void fsOpenCallback(uv_fs_t *req) {
338  auto ptr = reserve(req);
339 
340  if(req->result < 0) {
341  ptr->publish(ErrorEvent{req->result});
342  } else {
343  ptr->file = static_cast<uv_file>(req->result);
344  ptr->publish(FsEvent<Type::OPEN>{req->path});
345  }
346  }
347 
348  static void fsCloseCallback(uv_fs_t *req) {
349  auto ptr = reserve(req);
350 
351  if(req->result < 0) {
352  ptr->publish(ErrorEvent{req->result});
353  } else {
354  ptr->file = BAD_FD;
355  ptr->publish(FsEvent<Type::CLOSE>{req->path});
356  }
357  }
358 
359  static void fsReadCallback(uv_fs_t *req) {
360  auto ptr = reserve(req);
361  if(req->result < 0) { ptr->publish(ErrorEvent{req->result}); }
362  else { ptr->publish(FsEvent<Type::READ>{req->path, std::move(ptr->data), static_cast<std::size_t>(req->result)}); }
363  }
364 
365 public:
366  using FsRequest::FsRequest;
367 
368  ~FileReq() noexcept {
369  uv_fs_req_cleanup(get());
370  }
371 
378  void close() {
379  cleanupAndInvoke(&uv_fs_close, parent(), get(), file, &fsCloseCallback);
380  }
381 
386  bool closeSync() {
387  auto req = get();
388  cleanupAndInvokeSync(&uv_fs_close, parent(), req, file);
389  if(req->result >= 0) { file = BAD_FD; }
390  return !(req->result < 0);
391  }
392 
403  void open(std::string path, int flags, int mode) {
404  cleanupAndInvoke(&uv_fs_open, parent(), get(), path.data(), flags, mode, &fsOpenCallback);
405  }
406 
414  bool openSync(std::string path, int flags, int mode) {
415  auto req = get();
416  cleanupAndInvokeSync(&uv_fs_open, parent(), req, path.data(), flags, mode);
417  if(req->result >= 0) { file = static_cast<uv_file>(req->result); }
418  return !(req->result < 0);
419  }
420 
430  void read(int64_t offset, unsigned int len) {
431  data = std::unique_ptr<char[]>{new char[len]};
432  buffer = uv_buf_init(data.get(), len);
433  uv_buf_t bufs[] = { buffer };
434  cleanupAndInvoke(&uv_fs_read, parent(), get(), file, bufs, 1, offset, &fsReadCallback);
435  }
436 
449  std::pair<bool, std::pair<std::unique_ptr<const char[]>, std::size_t>>
450  readSync(int64_t offset, unsigned int len) {
451  data = std::unique_ptr<char[]>{new char[len]};
452  buffer = uv_buf_init(data.get(), len);
453  uv_buf_t bufs[] = { buffer };
454  auto req = get();
455  cleanupAndInvokeSync(&uv_fs_read, parent(), req, file, bufs, 1, offset);
456  bool err = req->result < 0;
457  return std::make_pair(!err, std::make_pair(std::move(data), err ? 0 : std::size_t(req->result)));
458  }
459 
473  void write(std::unique_ptr<char[]> buf, unsigned int len, int64_t offset) {
474  this->data = std::move(buf);
475  uv_buf_t bufs[] = { uv_buf_init(this->data.get(), len) };
476  cleanupAndInvoke(&uv_fs_write, parent(), get(), file, bufs, 1, offset, &fsResultCallback<Type::WRITE>);
477  }
478 
492  void write(char *buf, unsigned int len, int64_t offset) {
493  uv_buf_t bufs[] = { uv_buf_init(buf, len) };
494  cleanupAndInvoke(&uv_fs_write, parent(), get(), file, bufs, 1, offset, &fsResultCallback<Type::WRITE>);
495  }
496 
508  std::pair<bool, std::size_t> writeSync(std::unique_ptr<char[]> buf, unsigned int len, int64_t offset) {
509  this->data = std::move(buf);
510  uv_buf_t bufs[] = { uv_buf_init(this->data.get(), len) };
511  auto req = get();
512  cleanupAndInvokeSync(&uv_fs_write, parent(), req, file, bufs, 1, offset);
513  bool err = req->result < 0;
514  return std::make_pair(!err, err ? 0 : std::size_t(req->result));
515  }
516 
523  void stat() {
524  cleanupAndInvoke(&uv_fs_fstat, parent(), get(), file, &fsStatCallback<Type::FSTAT>);
525  }
526 
534  std::pair<bool, Stat> statSync() {
535  auto req = get();
536  cleanupAndInvokeSync(&uv_fs_fstat, parent(), req, file);
537  return std::make_pair(!(req->result < 0), req->statbuf);
538  }
539 
546  void sync() {
547  cleanupAndInvoke(&uv_fs_fsync, parent(), get(), file, &fsGenericCallback<Type::FSYNC>);
548  }
549 
554  bool syncSync() {
555  auto req = get();
556  cleanupAndInvokeSync(&uv_fs_fsync, parent(), req, file);
557  return !(req->result < 0);
558  }
559 
566  void datasync() {
567  cleanupAndInvoke(&uv_fs_fdatasync, parent(), get(), file, &fsGenericCallback<Type::FDATASYNC>);
568  }
569 
574  bool datasyncSync() {
575  auto req = get();
576  cleanupAndInvokeSync(&uv_fs_fdatasync, parent(), req, file);
577  return !(req->result < 0);
578  }
579 
588  void truncate(int64_t offset) {
589  cleanupAndInvoke(&uv_fs_ftruncate, parent(), get(), file, offset, &fsGenericCallback<Type::FTRUNCATE>);
590  }
591 
597  bool truncateSync(int64_t offset) {
598  auto req = get();
599  cleanupAndInvokeSync(&uv_fs_ftruncate, parent(), req, file, offset);
600  return !(req->result < 0);
601  }
602 
613  void sendfile(FileHandle out, int64_t offset, std::size_t length) {
614  cleanupAndInvoke(&uv_fs_sendfile, parent(), get(), out, file, offset, length, &fsResultCallback<Type::SENDFILE>);
615  }
616 
628  std::pair<bool, std::size_t> sendfileSync(FileHandle out, int64_t offset, std::size_t length) {
629  auto req = get();
630  cleanupAndInvokeSync(&uv_fs_sendfile, parent(), req, out, file, offset, length);
631  bool err = req->result < 0;
632  return std::make_pair(!err, err ? 0 : std::size_t(req->result));
633  }
634 
643  void chmod(int mode) {
644  cleanupAndInvoke(&uv_fs_fchmod, parent(), get(), file, mode, &fsGenericCallback<Type::FCHMOD>);
645  }
646 
652  bool chmodSync(int mode) {
653  auto req = get();
654  cleanupAndInvokeSync(&uv_fs_fchmod, parent(), req, file, mode);
655  return !(req->result < 0);
656  }
657 
669  void utime(Time atime, Time mtime) {
670  cleanupAndInvoke(&uv_fs_futime, parent(), get(), file, atime.count(), mtime.count(), &fsGenericCallback<Type::FUTIME>);
671  }
672 
681  bool utimeSync(Time atime, Time mtime) {
682  auto req = get();
683  cleanupAndInvokeSync(&uv_fs_futime, parent(), req, file, atime.count(), mtime.count());
684  return !(req->result < 0);
685  }
686 
696  void chown(Uid uid, Gid gid) {
697  cleanupAndInvoke(&uv_fs_fchown, parent(), get(), file, uid, gid, &fsGenericCallback<Type::FCHOWN>);
698  }
699 
706  bool chownSync(Uid uid, Gid gid) {
707  auto req = get();
708  cleanupAndInvokeSync(&uv_fs_fchown, parent(), req, file, uid, gid);
709  return !(req->result < 0);
710  }
711 
722  OSFileDescriptor handle() const noexcept {
723  return uv_get_osfhandle(file);
724  }
725 
734  operator FileHandle() const noexcept { return file; }
735 
736 private:
737  std::unique_ptr<char[]> data{nullptr};
738  uv_buf_t buffer{};
739  uv_file file{BAD_FD};
740 };
741 
742 
755 class FsReq final: public FsRequest<FsReq> {
756  static void fsReadlinkCallback(uv_fs_t *req) {
757  auto ptr = reserve(req);
758  if(req->result < 0) { ptr->publish(ErrorEvent{req->result}); }
759  else { ptr->publish(FsEvent<Type::READLINK>{req->path, static_cast<char *>(req->ptr), static_cast<std::size_t>(req->result)}); }
760  }
761 
762 public:
763  using CopyFile = details::UVCopyFileFlags;
764  using SymLink = details::UVSymLinkFlags;
765 
766  using FsRequest::FsRequest;
767 
768  ~FsReq() noexcept {
769  uv_fs_req_cleanup(get());
770  }
771 
780  void unlink(std::string path) {
781  cleanupAndInvoke(&uv_fs_unlink, parent(), get(), path.data(), &fsGenericCallback<Type::UNLINK>);
782  }
783 
789  bool unlinkSync(std::string path) {
790  auto req = get();
791  cleanupAndInvokeSync(&uv_fs_unlink, parent(), req, path.data());
792  return !(req->result < 0);
793  }
794 
804  void mkdir(std::string path, int mode) {
805  cleanupAndInvoke(&uv_fs_mkdir, parent(), get(), path.data(), mode, &fsGenericCallback<Type::MKDIR>);
806  }
807 
814  bool mkdirSync(std::string path, int mode) {
815  auto req = get();
816  cleanupAndInvokeSync(&uv_fs_mkdir, parent(), req, path.data(), mode);
817  return !(req->result < 0);
818  }
819 
828  void mkdtemp(std::string tpl) {
829  cleanupAndInvoke(&uv_fs_mkdtemp, parent(), get(), tpl.data(), &fsGenericCallback<Type::MKDTEMP>);
830  }
831 
841  std::pair<bool, const char *> mkdtempSync(std::string tpl) {
842  auto req = get();
843  cleanupAndInvokeSync(&uv_fs_mkdtemp, parent(), req, tpl.data());
844  return std::make_pair(!(req->result < 0), req->path);
845  }
846 
855  void rmdir(std::string path) {
856  cleanupAndInvoke(&uv_fs_rmdir, parent(), get(), path.data(), &fsGenericCallback<Type::RMDIR>);
857  }
858 
864  bool rmdirSync(std::string path) {
865  auto req = get();
866  cleanupAndInvokeSync(&uv_fs_rmdir, parent(), req, path.data());
867  return !(req->result < 0);
868  }
869 
879  void scandir(std::string path, int flags) {
880  cleanupAndInvoke(&uv_fs_scandir, parent(), get(), path.data(), flags, &fsResultCallback<Type::SCANDIR>);
881  }
882 
893  std::pair<bool, std::size_t> scandirSync(std::string path, int flags) {
894  auto req = get();
895  cleanupAndInvokeSync(&uv_fs_scandir, parent(), req, path.data(), flags);
896  bool err = req->result < 0;
897  return std::make_pair(!err, err ? 0 : std::size_t(req->result));
898  }
899 
929  std::pair<bool, Entry> scandirNext() {
930  uv_dirent_t dirent;
931  std::pair<bool, Entry> ret{false, { EntryType::UNKNOWN, "" }};
932  auto res = uv_fs_scandir_next(get(), &dirent);
933 
934  if(UV_EOF != res) {
935  ret.second.first = static_cast<EntryType>(dirent.type);
936  ret.second.second = dirent.name;
937  ret.first = true;
938  }
939 
940  return ret;
941  }
942 
951  void stat(std::string path) {
952  cleanupAndInvoke(&uv_fs_stat, parent(), get(), path.data(), &fsStatCallback<Type::STAT>);
953  }
954 
964  std::pair<bool, Stat> statSync(std::string path) {
965  auto req = get();
966  cleanupAndInvokeSync(&uv_fs_stat, parent(), req, path.data());
967  return std::make_pair(!(req->result < 0), req->statbuf);
968  }
969 
978  void lstat(std::string path) {
979  cleanupAndInvoke(&uv_fs_lstat, parent(), get(), path.data(), &fsStatCallback<Type::LSTAT>);
980  }
981 
991  std::pair<bool, Stat> lstatSync(std::string path) {
992  auto req = get();
993  cleanupAndInvokeSync(&uv_fs_lstat, parent(), req, path.data());
994  return std::make_pair(!(req->result < 0), req->statbuf);
995  }
996 
1006  void rename(std::string old, std::string path) {
1007  cleanupAndInvoke(&uv_fs_rename, parent(), get(), old.data(), path.data(), &fsGenericCallback<Type::RENAME>);
1008  }
1009 
1016  bool renameSync(std::string old, std::string path) {
1017  auto req = get();
1018  cleanupAndInvokeSync(&uv_fs_rename, parent(), req, old.data(), path.data());
1019  return !(req->result < 0);
1020  }
1021 
1044  void copyfile(std::string old, std::string path, Flags<CopyFile> flags = Flags<CopyFile>{}) {
1045  cleanupAndInvoke(&uv_fs_copyfile, parent(), get(), old.data(), path.data(), flags, &fsGenericCallback<Type::COPYFILE>);
1046  }
1047 
1067  bool copyfileSync(std::string old, std::string path, Flags<CopyFile> flags = Flags<CopyFile>{}) {
1068  auto req = get();
1069  cleanupAndInvokeSync(&uv_fs_copyfile, parent(), get(), old.data(), path.data(), flags);
1070  return !(req->result < 0);
1071  }
1072 
1082  void access(std::string path, int mode) {
1083  cleanupAndInvoke(&uv_fs_access, parent(), get(), path.data(), mode, &fsGenericCallback<Type::ACCESS>);
1084  }
1085 
1092  bool accessSync(std::string path, int mode) {
1093  auto req = get();
1094  cleanupAndInvokeSync(&uv_fs_access, parent(), req, path.data(), mode);
1095  return !(req->result < 0);
1096  }
1097 
1107  void chmod(std::string path, int mode) {
1108  cleanupAndInvoke(&uv_fs_chmod, parent(), get(), path.data(), mode, &fsGenericCallback<Type::CHMOD>);
1109  }
1110 
1117  bool chmodSync(std::string path, int mode) {
1118  auto req = get();
1119  cleanupAndInvokeSync(&uv_fs_chmod, parent(), req, path.data(), mode);
1120  return !(req->result < 0);
1121  }
1122 
1135  void utime(std::string path, Time atime, Time mtime) {
1136  cleanupAndInvoke(&uv_fs_utime, parent(), get(), path.data(), atime.count(), mtime.count(), &fsGenericCallback<Type::UTIME>);
1137  }
1138 
1148  bool utimeSync(std::string path, Time atime, Time mtime) {
1149  auto req = get();
1150  cleanupAndInvokeSync(&uv_fs_utime, parent(), req, path.data(), atime.count(), mtime.count());
1151  return !(req->result < 0);
1152  }
1153 
1163  void link(std::string old, std::string path) {
1164  cleanupAndInvoke(&uv_fs_link, parent(), get(), old.data(), path.data(), &fsGenericCallback<Type::LINK>);
1165  }
1166 
1173  bool linkSync(std::string old, std::string path) {
1174  auto req = get();
1175  cleanupAndInvokeSync(&uv_fs_link, parent(), req, old.data(), path.data());
1176  return !(req->result < 0);
1177  }
1178 
1196  void symlink(std::string old, std::string path, Flags<SymLink> flags = Flags<SymLink>{}) {
1197  cleanupAndInvoke(&uv_fs_symlink, parent(), get(), old.data(), path.data(), flags, &fsGenericCallback<Type::SYMLINK>);
1198  }
1199 
1215  bool symlinkSync(std::string old, std::string path, Flags<SymLink> flags = Flags<SymLink>{}) {
1216  auto req = get();
1217  cleanupAndInvokeSync(&uv_fs_symlink, parent(), req, old.data(), path.data(), flags);
1218  return !(req->result < 0);
1219  }
1220 
1229  void readlink(std::string path) {
1230  cleanupAndInvoke(&uv_fs_readlink, parent(), get(), path.data(), &fsReadlinkCallback);
1231  }
1232 
1244  std::pair<bool, std::pair<const char *, std::size_t>>
1245  readlinkSync(std::string path) {
1246  auto req = get();
1247  cleanupAndInvokeSync(&uv_fs_readlink, parent(), req, path.data());
1248  bool err = req->result < 0;
1249  return std::make_pair(!err, std::make_pair(static_cast<char *>(req->ptr), err ? 0 : std::size_t(req->result)));
1250  }
1251 
1260  void realpath(std::string path) {
1261  cleanupAndInvoke(&uv_fs_realpath, parent(), get(), path.data(), &fsGenericCallback<Type::REALPATH>);
1262  }
1263 
1273  std::pair<bool, const char *> realpathSync(std::string path) {
1274  auto req = get();
1275  cleanupAndInvokeSync(&uv_fs_realpath, parent(), req, path.data());
1276  return std::make_pair(!(req->result < 0), req->path);
1277  }
1278 
1289  void chown(std::string path, Uid uid, Gid gid) {
1290  cleanupAndInvoke(&uv_fs_chown, parent(), get(), path.data(), uid, gid, &fsGenericCallback<Type::CHOWN>);
1291  }
1292 
1300  bool chownSync(std::string path, Uid uid, Gid gid) {
1301  auto req = get();
1302  cleanupAndInvokeSync(&uv_fs_chown, parent(), req, path.data(), uid, gid);
1303  return !(req->result < 0);
1304  }
1305 };
1306 
1307 
1308 }
void utime(std::string path, Time atime, Time mtime)
Async utime.
Definition: fs.hpp:1135
The FileReq request.
Definition: fs.hpp:334
void symlink(std::string old, std::string path, Flags< SymLink > flags=Flags< SymLink >{})
Async symlink.
Definition: fs.hpp:1196
bool truncateSync(int64_t offset)
Sync ftruncate.
Definition: fs.hpp:597
bool unlinkSync(std::string path)
Sync unlink.
Definition: fs.hpp:789
void chown(Uid uid, Gid gid)
Async fchown.
Definition: fs.hpp:696
std::pair< bool, std::pair< const char *, std::size_t > > readlinkSync(std::string path)
Sync readlink.
Definition: fs.hpp:1245
void access(std::string path, int mode)
Async access.
Definition: fs.hpp:1082
bool datasyncSync()
Sync fdatasync.
Definition: fs.hpp:574
details::UVTypeWrapper< uv_file > FileHandle
Definition: util.hpp:186
bool accessSync(std::string path, int mode)
Sync access.
Definition: fs.hpp:1092
std::pair< bool, Stat > statSync(std::string path)
Sync stat.
Definition: fs.hpp:964
void chmod(std::string path, int mode)
Async chmod.
Definition: fs.hpp:1107
bool utimeSync(Time atime, Time mtime)
Sync futime.
Definition: fs.hpp:681
The FsReq request.
Definition: fs.hpp:755
void rmdir(std::string path)
Async rmdir.
Definition: fs.hpp:855
bool chmodSync(std::string path, int mode)
Sync chmod.
Definition: fs.hpp:1117
std::pair< bool, Stat > lstatSync(std::string path)
Sync lstat.
Definition: fs.hpp:991
bool utimeSync(std::string path, Time atime, Time mtime)
Sync utime.
Definition: fs.hpp:1148
std::unique_ptr< const char[]> data
Definition: fs.hpp:146
Default FsEvent event.
Definition: fs.hpp:126
Base class for FsReq and/or FileReq.
Definition: fs.hpp:277
bool mkdirSync(std::string path, int mode)
Sync mkdir.
Definition: fs.hpp:814
void open(std::string path, int flags, int mode)
Async open.
Definition: fs.hpp:403
details::UVTypeWrapper< uv_os_fd_t > OSFileDescriptor
Definition: util.hpp:188
std::pair< bool, const char * > realpathSync(std::string path)
Sync realpath.
Definition: fs.hpp:1273
void write(std::unique_ptr< char[]> buf, unsigned int len, int64_t offset)
Async write.
Definition: fs.hpp:473
bool chownSync(std::string path, Uid uid, Gid gid)
Sync chown.
Definition: fs.hpp:1300
void chmod(int mode)
Async fchmod.
Definition: fs.hpp:643
void rename(std::string old, std::string path)
Async rename.
Definition: fs.hpp:1006
void close()
Async close.
Definition: fs.hpp:378
void scandir(std::string path, int flags)
Async scandir.
Definition: fs.hpp:879
std::pair< bool, Entry > scandirNext()
Gets entries populated with the next directory entry data.
Definition: fs.hpp:929
Utility class to handle flags.
Definition: util.hpp:77
std::pair< bool, const char * > mkdtempSync(std::string tpl)
Sync mktemp.
Definition: fs.hpp:841
bool symlinkSync(std::string old, std::string path, Flags< SymLink > flags=Flags< SymLink >{})
Sync symlink.
Definition: fs.hpp:1215
void mkdir(std::string path, int mode)
Async mkdir.
Definition: fs.hpp:804
void unlink(std::string path)
Async unlink.
Definition: fs.hpp:780
std::pair< bool, Stat > statSync()
Sync fstat.
Definition: fs.hpp:534
void sync()
Async fsync.
Definition: fs.hpp:546
void stat()
Async fstat.
Definition: fs.hpp:523
bool openSync(std::string path, int flags, int mode)
Sync open.
Definition: fs.hpp:414
std::pair< bool, std::size_t > writeSync(std::unique_ptr< char[]> buf, unsigned int len, int64_t offset)
Sync write.
Definition: fs.hpp:508
bool syncSync()
Sync fsync.
Definition: fs.hpp:554
void utime(Time atime, Time mtime)
Async futime.
Definition: fs.hpp:669
bool rmdirSync(std::string path)
Sync rmdir.
Definition: fs.hpp:864
void datasync()
Async fdatasync.
Definition: fs.hpp:566
uv_gid_t Gid
Definition: util.hpp:197
uv_uid_t Uid
Definition: util.hpp:196
void readlink(std::string path)
Async readlink.
Definition: fs.hpp:1229
bool closeSync()
Sync close.
Definition: fs.hpp:386
std::pair< bool, std::pair< std::unique_ptr< const char[]>, std::size_t > > readSync(int64_t offset, unsigned int len)
Sync read.
Definition: fs.hpp:450
bool chmodSync(int mode)
Sync fchmod.
Definition: fs.hpp:652
void lstat(std::string path)
Async lstat.
Definition: fs.hpp:978
The ErrorEvent event.
Definition: emitter.hpp:23
std::pair< bool, std::size_t > sendfileSync(FileHandle out, int64_t offset, std::size_t length)
Sync sendfile.
Definition: fs.hpp:628
void mkdtemp(std::string tpl)
Async mktemp.
Definition: fs.hpp:828
void link(std::string old, std::string path)
Async link.
Definition: fs.hpp:1163
void chown(std::string path, Uid uid, Gid gid)
Async chown.
Definition: fs.hpp:1289
bool renameSync(std::string old, std::string path)
Sync rename.
Definition: fs.hpp:1016
void truncate(int64_t offset)
Async ftruncate.
Definition: fs.hpp:588
bool linkSync(std::string old, std::string path)
Sync link.
Definition: fs.hpp:1173
const char * path
Definition: fs.hpp:129
void realpath(std::string path)
Async realpath.
Definition: fs.hpp:1260
void copyfile(std::string old, std::string path, Flags< CopyFile > flags=Flags< CopyFile >{})
Copies a file asynchronously from a path to a new one.
Definition: fs.hpp:1044
OSFileDescriptor handle() const noexcept
Gets the OS dependent handle.
Definition: fs.hpp:722
void read(int64_t offset, unsigned int len)
Async read.
Definition: fs.hpp:430
void write(char *buf, unsigned int len, int64_t offset)
Async write.
Definition: fs.hpp:492
uv_stat_t Stat
Definition: util.hpp:195
void stat(std::string path)
Async stat.
Definition: fs.hpp:951
bool copyfileSync(std::string old, std::string path, Flags< CopyFile > flags=Flags< CopyFile >{})
Copies a file synchronously from a path to a new one.
Definition: fs.hpp:1067
void sendfile(FileHandle out, int64_t offset, std::size_t length)
Async sendfile.
Definition: fs.hpp:613
std::pair< bool, std::size_t > scandirSync(std::string path, int flags)
Sync scandir.
Definition: fs.hpp:893
bool chownSync(Uid uid, Gid gid)
Sync fchown.
Definition: fs.hpp:706
uvw default namespace.
Definition: async.hpp:11