DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
File.hpp
Go to the documentation of this file.
1// DUNE DAQ modification notice:
2// This file has been modified from the original ATLAS system source for the DUNE DAQ project.
3// Fork baseline commit: system-00-00-20 (2020-09-25).
4// Renamed since fork: yes (from system/File.h to include/okssystem/File.hpp).
5
6/*
7 * File.h
8 * OksSystem
9 *
10 * Created by Matthias Wiesmann on 04.01.05.
11 * Copyright 2005 CERN. All rights reserved.
12 *
13 */
14
15#ifndef OKSSYSTEM_FILE
16#define OKSSYSTEM_FILE
17
18#include <string>
19#include <vector>
20
21#include <sys/stat.h>
22#include <sys/types.h>
23
24#include "okssystem/User.hpp"
25
26namespace OksSystem {
27
36
37class File
38{
39public:
40 typedef std::vector<OksSystem::File> file_list_t;
41
42protected:
43 std::string m_full_name;
44 void set_name(const std::string& name);
45 static const char* const HUMAN_SIZE_STR[];
46 static const char* const HUMAN_OPEN_STR[];
47 static const int KILOBYTE;
48 static int unit(int u);
49 mode_t get_mode() const;
50 static const char* const FILE_COMMAND_PATH;
51
52public:
53 static const char* const FILE_FLAG_STR;
54 static const char* const FILE_PROTOCOL;
55
56 static std::string protocol(const std::string& url) throw();
57 static std::string extension(
58 const std::string& url) throw();
59 static std::string uri(const std::string& url) throw();
60 static std::string short_name(const std::string& url) throw();
61 static int depth(const std::string& path) throw();
62
63 static std::string first_line(const std::string& text);
64
65 static File from_url(const std::string& url);
66
67 static std::string working_directory();
68 static void working_directory(const File& dir);
69 static std::string expand_home(const std::string path);
70 static std::string pretty_permissions(mode_t permissions);
71 static std::string to_string(mode_t permissions) throw();
72 static std::string pretty_open_flag(int flags);
73 static std::string pretty_size(size_t size, bool cut_small);
74
75 File(const std::string& name);
76 File(const char* name);
77 File(const File& other);
78 virtual ~File() {}
79 operator std::string() const throw();
80 operator const char*() const throw();
81 operator bool() const throw();
82 bool equals(const File& other) const throw();
83 operator size_t() const;
84
85 const std::string& full_name() const throw();
86 const char* c_full_name() const throw();
87 std::string short_name() const throw();
88 std::string parent_name() const throw();
89 std::string extension() const throw();
90 int depth() const throw();
91
92 OksSystem::File parent() const;
93 OksSystem::File child(const std::string& name) const;
94 OksSystem::File temporary(const std::string& prefix) const;
95
96 bool exists() const throw();
97 mode_t permissions() const;
98 std::string pretty_permissions() const;
99 size_t size() const;
100 uid_t owner_id() const;
101 User owner() const;
102 gid_t group() const;
103 bool is_regular() const;
104 bool is_directory() const;
105 bool is_fifo() const;
106 std::string file_type() const;
107 file_list_t directory() const;
108
109 void unlink() const;
110 void rmdir() const;
111
112 void remove() const;
113 void rename(const File& other) const;
114 void permissions(mode_t permissions) const;
115 void make_dir(mode_t permissions) const;
116 void make_path(mode_t permissions) const;
117 void make_fifo(mode_t permissions) const;
118
119 void ensure_path(mode_t permissions) const;
120
121 std::istream* input() const;
122 std::ostream* output(bool append = false) const;
123}; // File
124} // OksSystem
125
126std::ostream&
127operator<<(std::ostream& stream, const OksSystem::File& file);
128bool
129operator==(const OksSystem::File& a, const OksSystem::File& b) throw();
130bool
131operator!=(const OksSystem::File& a, const OksSystem::File& b) throw();
132
133#endif
Wrapper for file operations.
Definition File.hpp:38
static std::string protocol(const std::string &url)
extracts the protocol part of an url *‍/
Definition File.cpp:69
static const int KILOBYTE
number of bytes in a kilobyte *‍/
Definition File.hpp:47
std::string short_name() const
short name for file *‍/
Definition File.cpp:459
void unlink() const
deletes (unlinks) file *‍/
Definition File.cpp:726
bool is_directory() const
is the file a regular file *‍/
Definition File.cpp:657
void make_path(mode_t permissions) const
creates a full path *‍/
Definition File.cpp:852
static std::string uri(const std::string &url)
extracts the local path of an url *‍/
Definition File.cpp:113
static const char *const FILE_PROTOCOL
string for the file protocol *‍/
Definition File.hpp:54
static std::string short_name(const std::string &url)
extracts the short file name of an url *‍/
Definition File.cpp:97
bool exists() const
does the file exist *‍/
Definition File.cpp:526
User owner() const
owner of the file *‍/
Definition File.cpp:619
OksSystem::File parent() const
parent of the current file *‍/
Definition File.cpp:495
void rmdir() const
deletes directory *‍/
Definition File.cpp:735
file_list_t directory() const
list of file in directory *‍/
Definition File.cpp:692
std::string extension() const
extension for file *‍/
Definition File.cpp:481
mode_t permissions() const
permissions for the file *‍/
Definition File.cpp:558
std::istream * input() const
returns an input stream from the file*‍/
Definition File.cpp:908
std::string parent_name() const
path of directory containing file *‍/
Definition File.cpp:469
File(const std::string &name)
Definition File.cpp:327
static std::string pretty_open_flag(int flags)
pretty prints open flags *‍/
Definition File.cpp:253
static File from_url(const std::string &url)
build a file out of an URL *‍/
Definition File.cpp:170
static const char *const HUMAN_OPEN_STR[]
strings for pretty printing open flags *‍/
Definition File.hpp:40
std::string file_type() const
type of the file *‍/
Definition File.cpp:676
int depth() const
depth of the file *‍/
Definition File.cpp:487
static std::string first_line(const std::string &text)
extracts the first line of a text *‍/
Definition File.cpp:156
size_t size() const
size of file *‍/
Definition File.cpp:593
static int unit(int u)
calculates the value of a computer unit of order n (i.e KB,GB, etc *‍/
Definition File.cpp:283
static const char *const FILE_COMMAND_PATH
Definition File.hpp:50
static std::string to_string(mode_t permissions)
converts permission to string *‍/
Definition File.cpp:580
void ensure_path(mode_t permissions) const
creates the parent path *‍/
Definition File.cpp:869
void rename(const File &other) const
rename or moves the file *‍/
Definition File.cpp:772
void remove() const
recursively delete files and directories *‍/
Definition File.cpp:750
static std::string pretty_permissions(mode_t permissions)
pretty prints permissions *‍/
Definition File.cpp:229
OksSystem::File temporary(const std::string &prefix) const
Definition File.cpp:508
static const char *const HUMAN_SIZE_STR[]
strings for pretty printing file sizes *‍/
Definition File.hpp:39
std::vector< OksSystem::File > file_list_t
Definition File.hpp:40
const char * c_full_name() const
Definition File.cpp:451
static std::string working_directory()
current directory of process *‍/
Definition File.cpp:181
void make_dir(mode_t permissions) const
creates a directory *‍/
Definition File.cpp:808
static int depth(const std::string &path)
calculates depth of a path *‍/
Definition File.cpp:130
static std::string pretty_size(size_t size, bool cut_small)
pretty prints a file size *‍/
Definition File.cpp:301
uid_t owner_id() const
owner id of file *‍/
Definition File.cpp:608
void make_fifo(mode_t permissions) const
creates a FIFO (named pipe) *‍/
Definition File.cpp:880
bool equals(const File &other) const
compare two files *‍/
Definition File.cpp:383
OksSystem::File child(const std::string &name) const
named child of the current directory *‍/
Definition File.cpp:501
void set_name(const std::string &name)
sets the name of the file *‍/
Definition File.cpp:415
static const char *const FILE_FLAG_STR
column headers for display of permissions *‍/
Definition File.hpp:53
gid_t group() const
group of file *‍/
Definition File.cpp:629
const std::string & full_name() const
full name for file *‍/
Definition File.cpp:443
static std::string expand_home(const std::string path)
resolve home directory *‍/
Definition File.cpp:208
std::ostream * output(bool append=false) const
returns an output stream to the file*‍/
Definition File.cpp:927
virtual ~File()
Definition File.hpp:78
mode_t get_mode() const
get mode associated with file (permission + type) *‍/
Definition File.cpp:542
std::string m_full_name
full name (path) of the file *‍/
Definition File.hpp:43
static std::string extension(const std::string &url)
extracts the extension of a path or an url *‍/
Definition File.cpp:83
bool is_fifo() const
is the file a named pipe *‍/
Definition File.cpp:669
bool is_regular() const
is the file a directory *‍/
Definition File.cpp:645
std::string pretty_permissions() const
pretty permissions for the file *‍/
Definition File.cpp:569