Thrill  0.1
vfs_tool.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * examples/vfs_tool/vfs_tool.cpp
3  *
4  * Part of Project Thrill - http://project-thrill.org
5  *
6  * Copyright (C) 2016 Timo Bingmann <[email protected]>
7  *
8  * All rights reserved. Published under the BSD-2 license in the LICENSE file.
9  ******************************************************************************/
10 
11 #include <thrill/common/logger.hpp>
12 #include <thrill/vfs/file_io.hpp>
13 #include <tlx/cmdline_parser.hpp>
14 #include <tlx/die.hpp>
15 
16 #include <iostream>
17 #include <string>
18 #include <vector>
19 
20 using namespace thrill; // NOLINT
21 
22 int main(int argc, char* argv[]) {
23 
25 
26  clp.set_description("Simple VFS tool for Thrill");
27 
28  std::string op;
29  clp.add_param_string("op", op, "operation: glob | glob_files | read | write");
30 
31  std::vector<std::string> paths;
32  clp.add_param_stringlist("paths", paths, "file path(s)");
33 
34  if (!clp.process(argc, argv)) {
35  return -1;
36  }
37 
39 
40  if (op == "glob")
41  {
42  vfs::FileList fl = vfs::Glob(paths);
43 
44  if (fl.size() == 0)
45  std::cout << "No entries returned in glob." << std::endl;
46 
47  for (const vfs::FileInfo& fi : fl) {
48  std::cout << fi.path
49  << " type " << fi.type
50  << " size " << fi.size
51  << " size_ex_psum " << fi.size_ex_psum
52  << '\n';
53  }
54  }
55  else if (op == "glob_files")
56  {
58 
59  if (fl.size() == 0)
60  std::cout << "No files returned in glob." << std::endl;
61 
62  for (const vfs::FileInfo& fi : fl) {
63  std::cout << fi.path
64  << " type " << fi.type
65  << " size " << fi.size
66  << " size_ex_psum " << fi.size_ex_psum
67  << '\n';
68  }
69  }
70  else if (op == "read")
71  {
73 
74  for (const vfs::FileInfo& fi : fl) {
76 
77  char buffer[64 * 1024];
78  ssize_t rb = 0;
79  while ((rb = rs->read(buffer, sizeof(buffer))) > 0) {
80  std::cout.write(buffer, rb);
81  }
82  }
83  }
84  else if (op == "write")
85  {
86  die_unless(paths.size() == 1);
87 
89 
90  char buffer[64 * 1024];
91  while (std::cin.read(buffer, sizeof(buffer)), std::cin.gcount()) {
92  ws->write(buffer, std::cin.gcount());
93  }
94  }
95  else
96  {
97  LOG1 << "Unknown operation \"" << op << "\".";
98  }
99 
101 
102  return 0;
103 }
104 
105 /******************************************************************************/
int main(int argc, char *argv[])
Definition: vfs_tool.cpp:22
FileList Glob(const std::vector< std::string > &globlist, const GlobType &gtype)
Reads a glob path list and deliver a file list, sizes, and prefixsums (in bytes) for all matching fil...
Definition: file_io.cpp:128
#define die_unless(X)
Definition: die.hpp:27
void set_description(const std::string &description)
Set description of program, text will be wrapped.
void Initialize()
Initialize VFS layer.
Definition: file_io.cpp:35
#define LOG1
Definition: logger.hpp:28
ReadStreamPtr OpenReadStream(const std::string &path, const common::Range &range)
Construct reader for given path uri.
Definition: file_io.cpp:180
General information of vfs file.
Definition: file_io.hpp:57
void Deinitialize()
Deinitialize VFS layer.
Definition: file_io.cpp:40
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
Definition: allocator.hpp:220
Command line parser which automatically fills variables and prints nice usage messages.
void add_param_string(const std::string &name, std::string &dest, const std::string &desc)
add string parameter [name] with description and store to dest
void add_param_stringlist(const std::string &name, std::vector< std::string > &dest, const std::string &desc)
List of file info and additional overall info.
Definition: file_io.hpp:79
WriteStreamPtr OpenWriteStream(const std::string &path)
Definition: file_io.cpp:211
bool process(int argc, const char *const *argv, std::ostream &os)