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/types.h>
22#include <sys/stat.h>
23
24#include "okssystem/User.hpp"
25
26namespace OksSystem {
27
36
37 class File {
38public:
39 typedef std::vector<OksSystem::File> file_list_t ;
40protected:
41 std::string m_full_name ;
42 void set_name(const std::string &name);
43 static const char * const HUMAN_SIZE_STR[] ;
44 static const char * const HUMAN_OPEN_STR[] ;
45 static const int KILOBYTE ;
46 static int unit(int u) ;
47 mode_t get_mode() const ;
48 static const char * const FILE_COMMAND_PATH ;
49public:
50 static const char * const FILE_FLAG_STR ;
51 static const char * const FILE_PROTOCOL ;
52
53 static std::string protocol(const std::string &url) throw();
54 static std::string extension(const std::string &url) throw();
55 static std::string uri(const std::string &url) throw() ;
56 static std::string short_name(const std::string &url) throw();
57 static int depth(const std::string &path) throw() ;
58
59 static std::string first_line(const std::string &text);
60
61 static File from_url(const std::string &url);
62
63 static std::string working_directory() ;
64 static void working_directory(const File &dir);
65 static std::string expand_home(const std::string path) ;
66 static std::string pretty_permissions(mode_t permissions);
67 static std::string to_string(mode_t permissions) throw() ;
68 static std::string pretty_open_flag(int flags) ;
69 static std::string pretty_size(size_t size, bool cut_small);
70
71 File(const std::string &name);
72 File(const char* name) ;
73 File(const File& other) ;
74 virtual ~File() {}
75 operator std::string() const throw() ;
76 operator const char* () const throw() ;
77 operator bool() const throw() ;
78 bool equals(const File &other) const throw() ;
79 operator size_t() const ;
80
81 const std::string &full_name() const throw() ;
82 const char* c_full_name() const throw() ;
83 std::string short_name() const throw() ;
84 std::string parent_name() const throw() ;
85 std::string extension() const throw();
86 int depth() const throw() ;
87
88 OksSystem::File parent() const ;
89 OksSystem::File child(const std::string &name) const ;
90 OksSystem::File temporary(const std::string &prefix) const ;
91
92 bool exists() const throw() ;
93 mode_t permissions() const ;
94 std::string pretty_permissions() const ;
95 size_t size() const ;
96 uid_t owner_id() const ;
97 User owner() const ;
98 gid_t group() const ;
99 bool is_regular() const ;
100 bool is_directory() const ;
101 bool is_fifo() const ;
102 std::string file_type() const ;
103 file_list_t directory() const ;
104
105 void unlink() const ;
106 void rmdir() const ;
107
108 void remove() const ;
109 void rename(const File &other) const ;
110 void permissions(mode_t permissions) const ;
111 void make_dir(mode_t permissions) const ;
112 void make_path(mode_t permissions) const ;
113 void make_fifo(mode_t permissions) const ;
114
115 void ensure_path(mode_t permissions) const ;
116
117 std::istream* input() const ;
118 std::ostream* output(bool append=false) const ;
119 } ; // File
120} // OksSystem
121
122std::ostream& operator<<(std::ostream& stream, const OksSystem::File& file);
123bool operator ==(const OksSystem::File &a, const OksSystem::File &b) throw();
124bool operator !=(const OksSystem::File &a, const OksSystem::File &b) throw();
125
126
127#endif
128
129
130
Wrapper for file operations.
Definition File.hpp:37
static std::string protocol(const std::string &url)
extracts the protocol part of an url *‍/
Definition File.cpp:71
static const int KILOBYTE
number of bytes in a kilobyte *‍/
Definition File.hpp:45
std::string short_name() const
short name for file *‍/
Definition File.cpp:424
void unlink() const
deletes (unlinks) file *‍/
Definition File.cpp:651
bool is_directory() const
is the file a regular file *‍/
Definition File.cpp:589
void make_path(mode_t permissions) const
creates a full path *‍/
Definition File.cpp:766
static std::string uri(const std::string &url)
extracts the local path of an url *‍/
Definition File.cpp:106
static const char *const FILE_PROTOCOL
string for the file protocol *‍/
Definition File.hpp:51
bool exists() const
does the file exist *‍/
Definition File.cpp:477
User owner() const
owner of the file *‍/
Definition File.cpp:555
OksSystem::File parent() const
parent of the current file *‍/
Definition File.cpp:451
void rmdir() const
deletes directory *‍/
Definition File.cpp:657
file_list_t directory() const
list of file in directory *‍/
Definition File.cpp:619
std::string extension() const
extension for file *‍/
Definition File.cpp:441
mode_t permissions() const
permissions for the file *‍/
Definition File.cpp:505
std::istream * input() const
returns an input stream from the file*‍/
Definition File.cpp:820
std::string parent_name() const
path of directory containing file *‍/
Definition File.cpp:432
File(const std::string &name)
Definition File.cpp:301
static std::string pretty_open_flag(int flags)
pretty prints open flags *‍/
Definition File.cpp:232
static File from_url(const std::string &url)
build a file out of an URL *‍/
Definition File.cpp:156
static const char *const HUMAN_OPEN_STR[]
strings for pretty printing open flags *‍/
Definition File.hpp:41
std::string file_type() const
type of the file *‍/
Definition File.cpp:605
int depth() const
depth of the file *‍/
Definition File.cpp:445
static std::string first_line(const std::string &text)
extracts the first line of a text *‍/
Definition File.cpp:144
size_t size() const
size of file *‍/
Definition File.cpp:535
static int unit(int u)
calculates the value of a computer unit of order n (i.e KB,GB, etc *‍/
Definition File.cpp:261
static const char *const FILE_COMMAND_PATH
Definition File.hpp:48
static std::string to_string(mode_t permissions)
converts permission to string *‍/
Definition File.cpp:523
void ensure_path(mode_t permissions) const
creates the parent path *‍/
Definition File.cpp:781
void rename(const File &other) const
rename or moves the file *‍/
Definition File.cpp:691
void remove() const
recursively delete files and directories *‍/
Definition File.cpp:670
OksSystem::File temporary(const std::string &prefix) const
Definition File.cpp:460
static const char *const HUMAN_SIZE_STR[]
strings for pretty printing file sizes *‍/
Definition File.hpp:40
std::vector< OksSystem::File > file_list_t
Definition File.hpp:39
const char * c_full_name() const
Definition File.cpp:417
static std::string working_directory()
current directory of process *‍/
Definition File.cpp:165
void make_dir(mode_t permissions) const
creates a directory *‍/
Definition File.cpp:722
static std::string pretty_size(size_t size, bool cut_small)
pretty prints a file size *‍/
Definition File.cpp:276
uid_t owner_id() const
owner id of file *‍/
Definition File.cpp:547
void make_fifo(mode_t permissions) const
creates a FIFO (named pipe) *‍/
Definition File.cpp:791
bool equals(const File &other) const
compare two files *‍/
Definition File.cpp:352
OksSystem::File child(const std::string &name) const
named child of the current directory *‍/
Definition File.cpp:455
void set_name(const std::string &name)
sets the name of the file *‍/
Definition File.cpp:385
static const char *const FILE_FLAG_STR
column headers for display of permissions *‍/
Definition File.hpp:50
gid_t group() const
group of file *‍/
Definition File.cpp:564
const std::string & full_name() const
full name for file *‍/
Definition File.cpp:411
static std::string expand_home(const std::string path)
resolve home directory *‍/
Definition File.cpp:190
std::ostream * output(bool append=false) const
returns an output stream to the file*‍/
Definition File.cpp:837
virtual ~File()
Definition File.hpp:74
mode_t get_mode() const
get mode associated with file (permission + type) *‍/
Definition File.cpp:490
std::string m_full_name
full name (path) of the file *‍/
Definition File.hpp:41
bool is_fifo() const
is the file a named pipe *‍/
Definition File.cpp:599
bool is_regular() const
is the file a directory *‍/
Definition File.cpp:578
std::string pretty_permissions() const
pretty permissions for the file *‍/
Definition File.cpp:514