DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
File.cpp
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 src/File.cxx to src/File.cpp).
5
6/*
7 * File.cxx
8 * ers
9 *
10 * Created by Matthias Wiesmann on 04.01.05.
11 * Copyright 2005 CERN. All rights reserved.
12 *
13 */
14
15#include <unistd.h>
16#include <stdio.h>
17#include <libgen.h>
18#include <unistd.h>
19#include <fcntl.h>
20#include <errno.h>
21#include <assert.h>
22#include <dirent.h>
23#include <sys/types.h>
24#include <sys/stat.h>
25#include <sys/param.h>
26#include <iostream>
27#include <sstream>
28#include <fstream>
29#include <pwd.h>
30
31#include "ers/ers.hpp"
32
33#include "okssystem/File.hpp"
36#include "okssystem/User.hpp"
37
38#define SPACE_CHAR ' '
39
40const char * const OksSystem::File::HUMAN_SIZE_STR[] = { "B", "KB", "MB", "GB" };
41const char * const OksSystem::File::HUMAN_OPEN_STR[] = { "READ", "WRITE", "NOBLOCK", "APPEND", "CREATE", "TRUNCATE","EXCLUSIVE" };
42const char * const OksSystem::File::FILE_COMMAND_PATH = "/usr/bin/file";
43const char * const OksSystem::File::FILE_FLAG_STR = "-rwxS";
44const char * const OksSystem::File::FILE_PROTOCOL = "file";
45
46
47#define READ_CHAR_CODE (OksSystem::File::FILE_FLAG_STR[1])
48#define WRITE_CHAR_CODE (OksSystem::File::FILE_FLAG_STR[2])
49#define EXECUTE_CHAR_CODE (OksSystem::File::FILE_FLAG_STR[3])
50#define NOTHING_CHAR_CODE (OksSystem::File::FILE_FLAG_STR[0])
51#define SETUID_CHAR_CODE (OksSystem::File::FILE_FLAG_STR[4])
52
53#define SLASH_CHAR '/'
54#define COLON_CHAR ':'
55#define DOT_CHAR '.'
56
57const int OksSystem::File::KILOBYTE = 1024;
58
59
60// --------------------------------------
61// Static Methods
62// --------------------------------------
63
64
70
71std::string OksSystem::File::protocol(const std::string &url) throw() {
72 std::string::size_type colon = url.find(COLON_CHAR);
73 if (colon==std::string::npos) return std::string();
74 return url.substr(0,colon);
75} // protocol
76
81
82std::string OksSystem::File::extension(const std::string &url) throw() {
83 std::string::size_type dot = url.rfind(DOT_CHAR);
84 if (dot==std::string::npos) return std::string();
85 return url.substr(dot+1);
86} // extension
87
92
93std::string OksSystem::File::short_name(const std::string &url) throw() {
94 std::string::size_type slash = url.rfind(SLASH_CHAR);
95 if (slash==std::string::npos) return url;
96 return url.substr(slash+1);
97} // extension
98
105
106std::string OksSystem::File::uri(const std::string &url) throw() {
107 std::string::size_type colon = url.find(COLON_CHAR);
108 if (colon==std::string::npos) return url;
109 return url.substr(colon+1);
110} // uri
111
112
120
121int OksSystem::File::depth(const std::string &path) throw() {
122 if (path[0] == SLASH_CHAR) {
123 int count = 0;
124 std::string rest = path.substr(1);
125 while(! rest.empty()) {
126 std::string::size_type slash = rest.find(SLASH_CHAR);
127 if (slash==std::string::npos) return count;
128 count++;
129 rest = rest.substr(slash+1);
130 } // while
131 return count;
132 } // path with slash
133 if (protocol(path) == FILE_PROTOCOL) {
134 return depth(uri(path));
135 } //
136 return -1;
137} // depth
138
143
144std::string OksSystem::File::first_line(const std::string &text) {
145 std::string::size_type nl = text.find('\n');
146 if (nl>0) return text.substr(0,nl);
147 return text;
148} // first_line
149
150
155
157 std::string prot = protocol(url);
159 const std::string path = uri(url);
160 return File(path);
161} // from_url
162
164
166 char *wd_buffer = getcwd(0,MAXPATHLEN);
167 if (wd_buffer) {
168 std::string directory = std::string(wd_buffer);
169 free(wd_buffer);
170 return directory;
171 }
172 std::string message("getting the current working directory");
173 throw OksSystem::OksSystemCallIssue( ERS_HERE, errno, "getcwd", message.c_str() );
174} // working_directory
175
177 const char * path = dir.c_full_name();
178 const int status = ::chdir(path);
179 if (status<0) {
180 std::string message = "on directory " + dir.full_name();
181 throw OksSystem::OksSystemCallIssue( ERS_HERE, errno, "chdir", message.c_str() );
182 }
183} // working_directory
184
185
188
189
190std::string OksSystem::File::expand_home(const std::string path) {
191 ERS_PRECONDITION(! path.empty());
192 ERS_PRECONDITION(path[0] == '~');
193 std::string::size_type slash = path.find('/');
194 const std::string user_name = path.substr(1,slash-1);
195 const std::string rest_path = path.substr(slash);
196 OksSystem::User user;
197 if (! user_name.empty()) {
198 user = OksSystem::User(user_name);
199 }
200 return user.home() + rest_path;
201} // home_directory
202
203
209
211 char buffer[11];
212 buffer[0] = (permissions & S_ISUID) ? SETUID_CHAR_CODE : NOTHING_CHAR_CODE;
213 buffer[1] = (permissions & S_IRUSR) ? READ_CHAR_CODE : NOTHING_CHAR_CODE;
214 buffer[2] = (permissions & S_IWUSR) ? WRITE_CHAR_CODE : NOTHING_CHAR_CODE;
215 buffer[3] = (permissions & S_IXUSR) ? EXECUTE_CHAR_CODE : NOTHING_CHAR_CODE;
216 buffer[4] = (permissions & S_IRGRP) ? READ_CHAR_CODE : NOTHING_CHAR_CODE;
217 buffer[5] = (permissions & S_IWGRP) ? WRITE_CHAR_CODE : NOTHING_CHAR_CODE;
218 buffer[6] = (permissions & S_IXGRP) ? EXECUTE_CHAR_CODE : NOTHING_CHAR_CODE;
219 buffer[7] = (permissions & S_IROTH) ? READ_CHAR_CODE : NOTHING_CHAR_CODE;
220 buffer[8] = (permissions & S_IWOTH) ? WRITE_CHAR_CODE : NOTHING_CHAR_CODE;
221 buffer[9] = (permissions & S_IXOTH) ? EXECUTE_CHAR_CODE : NOTHING_CHAR_CODE;
222 buffer[10] = '\0';
223 return std::string(buffer);
224} // pretty_permissions
225
231
232std::string OksSystem::File::pretty_open_flag(int flags) {
233 std::ostringstream flag_str;
234 if (flags & O_WRONLY) {
235 flag_str << HUMAN_OPEN_STR[1];
236 } else if (flags & O_RDWR) {
237 flag_str << HUMAN_OPEN_STR[0] << "-" << HUMAN_OPEN_STR[1];
238 } else {
239 flag_str << HUMAN_OPEN_STR[0];
240 }
241 if (flags & O_NONBLOCK) {
242 flag_str << "/" << HUMAN_OPEN_STR[2];
243 }
244 if (flags & O_APPEND) {
245 flag_str << "/" << HUMAN_OPEN_STR[3];
246 }
247 if (flags & O_CREAT) {
248 flag_str << "/" << HUMAN_OPEN_STR[4];
249 }
250 if (flags & O_TRUNC) {
251 flag_str << "/" << HUMAN_OPEN_STR[5];
252 }
253 if (flags & O_EXCL) {
254 flag_str << "/" << HUMAN_OPEN_STR[6];
255 }
256 flag_str << "(" << flags << ")";
257 return flag_str.str();
258} // pretty_open_permission
259
260
262 ERS_PRECONDITION(u >= 0);
263 if (u==0) return 1;
264 return KILOBYTE * unit(u-1);
265} // unit
266
275
276std::string OksSystem::File::pretty_size(size_t size, bool cut_small) {
277 if (0==size) return "0";
278 std::ostringstream size_str;
279 bool writen_something = false;
280 for(int i=3;i>=0;i--) {
281 const unsigned int size_unit = unit(i);
282 if (size > size_unit && ! (cut_small && writen_something)) {
283 const int amount = size / size_unit;
284 size = size % size_unit;
285 size_str << amount << SPACE_CHAR << HUMAN_SIZE_STR[i];
286 writen_something = true;
287 } // if unit is present
288 } // loop
289 return size_str.str();
290} // pretty_size
291
292// --------------------------------------
293// Constructors
294// --------------------------------------
295
296
300
301OksSystem::File::File(const std::string &name) {
302 set_name(name);
303} // File
304
308
309OksSystem::File::File(const char* c_name) {
310 ERS_PRECONDITION(c_name);
311 std::string name = std::string(c_name);
312 set_name(name);
313} // File
314
318
320 set_name(other.m_full_name);
321} // File
322
323// --------------------------------------
324// Operators
325// --------------------------------------
326
327
328
329OksSystem::File::operator std::string() const throw() {
330 return m_full_name;
331} // operator std::string
332
333OksSystem::File::operator const char*() const throw() {
334 return m_full_name.c_str();
335} // operator const char*
336
340
341OksSystem::File::operator bool() const throw() {
342 return exists();
343} // operator bool
344
351
352bool OksSystem::File::equals(const File &other) const throw() {
353 return (m_full_name == other.m_full_name);
354} // operator==
355
360
361OksSystem::File::operator size_t() const {
362 return size();
363} // operator size_t
364
365
366
367
368// --------------------------------------
369// Methods
370// --------------------------------------
371
372
384
385void OksSystem::File::set_name(const std::string &name) {
386 ERS_PRECONDITION(! name.empty());
387 const char c = name[0];
388 std::string long_path;
389 switch (c) {
390 case '/' :
391 long_path = name;
392 break;
393 case '~' :
394 long_path = expand_home(name);
395 break;
396 default:
397 long_path = working_directory() + "/" + name;
398 break;
399 } // switch
400 char buffer[PATH_MAX];
401 const char* result = realpath(long_path.c_str(),buffer);
402 if (result==0) { // could not resolve path
403 m_full_name = long_path;
404 } else { // we could canonicalize the path
405 m_full_name = buffer;
406 } //
407} // set_name
408
410
411const std::string & OksSystem::File::full_name() const throw() {
412 return m_full_name;
413} // full_name
414
416
417const char* OksSystem::File::c_full_name() const throw() {
418 return m_full_name.c_str();
419} // c_full_name
420
421
423
424std::string OksSystem::File::short_name() const throw() {
425 return short_name(m_full_name);
426} // short_name
427
431
432std::string OksSystem::File::parent_name() const throw() {
433 std::string::size_type size = m_full_name.size();
434 std::string::size_type slash = m_full_name.rfind(SLASH_CHAR,size-1);
435 if (slash==std::string::npos || slash==0) return ("/");
436 return m_full_name.substr(0,slash);
437} // directory
438
440
441std::string OksSystem::File::extension() const throw() {
442 return extension(m_full_name);
443} // extension
444
445int OksSystem::File::depth() const throw() {
446 return depth(m_full_name);
447} // depth
448
450
452 return File(parent_name());
453} // parent
454
455OksSystem::File OksSystem::File::child(const std::string &name) const {
456 std::string child_name = m_full_name + "/" + name;
457 return OksSystem::File(child_name);
458} // child
459
460OksSystem::File OksSystem::File::temporary(const std::string &prefix) const {
461 char *tmp_name = tempnam(m_full_name.c_str(),prefix.c_str());
462 if ( !tmp_name ) {
463 std::string message = "while creating a valid filename in directory " + m_full_name;
464 throw OksSystem::OksSystemCallIssue( ERS_HERE, errno, "tempnam", message.c_str() );
465 }
466 OksSystem::File tmp_file(tmp_name);
467 free(tmp_name);
468 return tmp_file;
469} // temporary
470
471
476
477bool OksSystem::File::exists() const throw() {
478 struct stat file_status;
479 const int result = stat(m_full_name.c_str(),&file_status);
480 if (0==result) return true;
481 return false;
482} // exists
483
489
491 struct stat file_status;
492 const int result = stat(m_full_name.c_str(),&file_status);
493 if (0==result) {
494 return file_status.st_mode;
495 } // if
496 std::string message = "on file/directory " + m_full_name;
497 throw OksSystem::OksSystemCallIssue( ERS_HERE, errno, "stat", message.c_str() );
498} // mode
499
500
504
506 mode_t mode = get_mode();
507 return (mode & 07777);
508} // permissions
509
513
516} // pretty_permissions
517
522
523std::string OksSystem::File::to_string(mode_t permissions) throw() {
524 std::ostringstream stream;
525 stream.setf(std::ios::oct,std::ios::basefield);
526 stream << permissions;
527 return stream.str();
528} // to_string
529
530
534
535size_t OksSystem::File::size() const {
536 struct stat file_status;
537 const int result = stat(m_full_name.c_str(),&file_status);
538 if (0==result) return file_status.st_size;
539 std::string message = "on file/directory " + m_full_name;
540 throw OksSystem::OksSystemCallIssue( ERS_HERE, errno, "stat", message.c_str() );
541} // size
542
546
548 struct stat file_status;
549 const int result = stat(m_full_name.c_str(),&file_status);
550 if (0==result) return file_status.st_uid;
551 std::string message = "on file/directory " + m_full_name;
552 throw OksSystem::OksSystemCallIssue( ERS_HERE, errno, "stat", message.c_str() );
553} // owner_id
554
556 return User(owner_id());
557} // owner
558
559
563
565 struct stat file_status;
566 const int result = stat(m_full_name.c_str(),&file_status);
567 if (0==result) return file_status.st_gid;
568 std::string message = "on file/directory " + m_full_name;
569 throw OksSystem::OksSystemCallIssue( ERS_HERE, errno, "stat", message.c_str() );
570} // owner
571
572
577
579 const mode_t mode = get_mode();
580 return (mode & S_IFREG);
581} // is_regular
582
583
588
590 const mode_t mode = get_mode();
591 return (mode & S_IFDIR);
592} // is_regular
593
598
600 const mode_t mode = get_mode();
601 return (mode & S_IFIFO);
602} // is_pipe
603
604
605std::string OksSystem::File::file_type() const {
608 params.push_back("-b");
609 params.push_back(full_name());
610 return first_line(file_command.pipe_in(params));
611} // file_type
612
618
620 file_list_t file_vector;
621 DIR* directory_ptr = opendir(m_full_name.c_str());
622 if (! directory_ptr) {
623 std::string message = "on directory " + m_full_name;
624 throw OksSystem::OksSystemCallIssue( ERS_HERE, errno, "opendir", message.c_str() );
625 }
626 while(true) {
627 struct dirent* directory_entry = readdir(directory_ptr);
628 if (directory_entry) {
629 const std::string name = directory_entry->d_name;
630 if ((name!=".") && (name!="..")) {
631 std::string path = m_full_name + "/" + name;
632 OksSystem::File file(path);
633 file_vector.push_back(file);
634 } // if
635 } else {
636 break;
637 } // if / else
638 } // while
639 int status = closedir(directory_ptr);
640 if (status<0) {
641 std::string message = "on directory " + m_full_name;
642 throw OksSystem::OksSystemCallIssue( ERS_HERE, errno, "closedir", message.c_str() );
643 }
644 return file_vector;
645} // directory
646
650
652 const int result = ::unlink(m_full_name.c_str());
653 if (0==result) return;
654 throw OksSystem::RemoveFileIssue( ERS_HERE, errno, m_full_name.c_str() );
655} //unlink
656
658 const int result = ::rmdir(m_full_name.c_str());
659 if (0==result) return;
660 std::string message = "on directory " + m_full_name;
661 throw OksSystem::OksSystemCallIssue( ERS_HERE, errno, "rmdir", message.c_str() );
662} // rmdir
663
664
669
671 if (is_directory()) {
672 file_list_t childs = directory();
673 for (file_list_t::const_iterator p=childs.begin();p!=childs.end();p++) {
674 const File f = *p;
675 if(f.exists()) {
676 f.remove();
677 }
678 } // for
679 rmdir();
680 } else {
681 unlink();
682 }
683} // remove
684
685
690
691void OksSystem::File::rename(const File &other) const {
692 const char *source = c_full_name() ;
693 const char *dest = other.c_full_name();
694 const int result = ::rename(source,dest);
695 if (0==result) return;
696 throw OksSystem::RenameFileIssue( ERS_HERE, errno, source, dest );
697} // rename
698
703
704void OksSystem::File::permissions(mode_t perm) const {
705 if(perm != permissions()) {
706 const int result = ::chmod(m_full_name.c_str(),perm);
707 if (0==result) {
708 return;
709 }
710 std::string message = "on file/directory " + m_full_name;
711 throw OksSystem::OksSystemCallIssue( ERS_HERE, errno, "chmod", message.c_str());
712 }
713} // permissions
714
721
722void OksSystem::File::make_dir(mode_t perm) const {
723
724 errno = 0;
725 const int result = ::mkdir(m_full_name.c_str(),perm);
726 int mkdir_error = errno;
727
728 if (0==result) {
729 try {
730 permissions(perm);
731 }
732 catch (OksSystem::OksSystemCallIssue &e){
733 std::string message = "on directory " + m_full_name;
734 throw OksSystem::OksSystemCallIssue( ERS_HERE, errno, "mkdir -> chmod", message.c_str() );
735 }
736 return;
737 } else {
738 if (exists()) {
739 if (is_directory()) { // already exists we attempt a chmod
740 try {
741 permissions(perm);
742 }
743 catch (OksSystem::OksSystemCallIssue &e){
744 // ignore this case...
745 }
746 return;
747 } // is directory
748 } else { // exists
749 std::string message = "on directory " + m_full_name;
750 throw OksSystem::OksSystemCallIssue(ERS_HERE, mkdir_error, "mkdir", message.c_str());
751 }
752 }
753
754} // makedir
755
765
766void OksSystem::File::make_path(mode_t perm) const {
767 const File father = parent();
768 if (! father.exists()) {
769 mode_t father_permission = perm | S_IRWXU;// we need rights to write sons
770 father.make_path(father_permission);
771 } // if
772 make_dir(perm);
773} // makepath
774
780
781void OksSystem::File::ensure_path(mode_t perm) const {
782 const File father = parent();
783 father.make_path(perm);
784} // ensure_path
785
786
790
791void OksSystem::File::make_fifo(mode_t perm) const {
792 if (exists()) {
793 if (is_fifo()) {
794 if(perm != permissions()) {
795 permissions(perm);
796 return;
797 } else {
798 return;
799 }
800 } // is_fifo
801 } // exists
802 const int status = ::mkfifo(m_full_name.c_str(),perm);
803 if (status==0) {
804 permissions(perm);
805 return;
806 }
807 std::string message = "while creating FIFO " + m_full_name;
808 throw OksSystem::OksSystemCallIssue( ERS_HERE, errno, "mkfifo", message.c_str() );
809} // makefifo
810
811
812
813
819
820std::istream* OksSystem::File::input() const {
821 try {
822 std::ifstream *stream = new std::ifstream(m_full_name.c_str());
823 stream->exceptions(std::ios::failbit | std::ios::badbit);
824 return stream;
825 } catch (std::ios_base::failure &ex) {
826 throw OksSystem::OpenFileIssue( ERS_HERE, errno, m_full_name.c_str(), ex );
827 } // catch
828} // std::istream*
829
836
837std::ostream* OksSystem::File::output(bool append) const {
838 try {
839 std::ios::openmode mode = std::ios::out;
840 if (append) {
841 mode |= std::ios::app;
842 }
843 std::ofstream *stream = new std::ofstream(m_full_name.c_str(),mode);
844 stream->exceptions(std::ios::failbit | std::ios::badbit);
845 return stream;
846 } catch (std::ios_base::failure &ex) {
847 throw OksSystem::OpenFileIssue( ERS_HERE, errno, m_full_name.c_str(), ex );
848 } // catch
849} // std::ostream*
850
856
857std::ostream& operator<<(std::ostream& stream, const OksSystem::File& file) {
858 stream << OksSystem::File::FILE_PROTOCOL << ":/" << file.full_name();
859 return stream;
860} // operator<<
861
862bool operator ==(const OksSystem::File &a, const OksSystem::File &b) throw() {
863 return a.equals(b);
864} // operator ==
865
866bool operator !=(const OksSystem::File &a, const OksSystem::File &b) throw() {
867 return ! a.equals(b);
868} // operator !=
869
870
871
872
873
#define ERS_PRECONDITION(expression)
#define SETUID_CHAR_CODE
Definition File.cpp:51
#define NOTHING_CHAR_CODE
Definition File.cpp:50
#define WRITE_CHAR_CODE
Definition File.cpp:48
#define SLASH_CHAR
Definition File.cpp:53
#define EXECUTE_CHAR_CODE
Definition File.cpp:49
#define DOT_CHAR
Definition File.cpp:55
#define READ_CHAR_CODE
Definition File.cpp:47
#define COLON_CHAR
Definition File.cpp:54
#define SPACE_CHAR
Definition File.cpp:38
#define ERS_HERE
void operator<<(TraceStreamer &x, const ers::Issue &r)
Definition Logger.hxx:102
Wrapper for executable file manipulation.
std::string pipe_in(const param_collection &params) const
run the executable and pipe results back
std::vector< std::string > param_collection
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
static std::string short_name(const std::string &url)
extracts the short file name of an url *‍/
Definition File.cpp:93
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
static std::string pretty_permissions(mode_t permissions)
pretty prints permissions *‍/
Definition File.cpp:210
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 int depth(const std::string &path)
calculates depth of a path *‍/
Definition File.cpp:121
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
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
static std::string extension(const std::string &url)
extracts the extension of a path or an url *‍/
Definition File.cpp:82
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
const std::string & home() const
home directory name
Definition User.cpp:218
bool operator!=(const Host &a, const Host &b)
inequality operator
Definition Host.cpp:188
bool operator==(const Host &a, const Host &b)
equality operator
Definition Host.cpp:184