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 <assert.h>
16#include <dirent.h>
17#include <errno.h>
18#include <fcntl.h>
19#include <fstream>
20#include <iostream>
21#include <libgen.h>
22#include <pwd.h>
23#include <sstream>
24#include <stdio.h>
25#include <sys/param.h>
26#include <sys/stat.h>
27#include <sys/types.h>
28#include <unistd.h>
29
30#include "ers/ers.hpp"
31
33#include "okssystem/File.hpp"
34#include "okssystem/User.hpp"
36
37#define SPACE_CHAR ' '
38
39const char* const OksSystem::File::HUMAN_SIZE_STR[] = { "B", "KB", "MB", "GB" };
40const char* const OksSystem::File::HUMAN_OPEN_STR[] = { "READ", "WRITE", "NOBLOCK", "APPEND",
41 "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#define READ_CHAR_CODE (OksSystem::File::FILE_FLAG_STR[1])
47#define WRITE_CHAR_CODE (OksSystem::File::FILE_FLAG_STR[2])
48#define EXECUTE_CHAR_CODE (OksSystem::File::FILE_FLAG_STR[3])
49#define NOTHING_CHAR_CODE (OksSystem::File::FILE_FLAG_STR[0])
50#define SETUID_CHAR_CODE (OksSystem::File::FILE_FLAG_STR[4])
51
52#define SLASH_CHAR '/'
53#define COLON_CHAR ':'
54#define DOT_CHAR '.'
55
56const int OksSystem::File::KILOBYTE = 1024;
57
58// --------------------------------------
59// Static Methods
60// --------------------------------------
61
67
68std::string
69OksSystem::File::protocol(const std::string& url) throw()
70{
71 std::string::size_type colon = url.find(COLON_CHAR);
72 if (colon == std::string::npos)
73 return std::string();
74 return url.substr(0, colon);
75} // protocol
76
81
82std::string
83OksSystem::File::extension(const std::string& url) throw()
84{
85 std::string::size_type dot = url.rfind(DOT_CHAR);
86 if (dot == std::string::npos)
87 return std::string();
88 return url.substr(dot + 1);
89} // extension
90
95
96std::string
97OksSystem::File::short_name(const std::string& url) throw()
98{
99 std::string::size_type slash = url.rfind(SLASH_CHAR);
100 if (slash == std::string::npos)
101 return url;
102 return url.substr(slash + 1);
103} // extension
104
111
112std::string
113OksSystem::File::uri(const std::string& url) throw()
114{
115 std::string::size_type colon = url.find(COLON_CHAR);
116 if (colon == std::string::npos)
117 return url;
118 return url.substr(colon + 1);
119} // uri
120
128
129int
130OksSystem::File::depth(const std::string& path) throw()
131{
132 if (path[0] == SLASH_CHAR) {
133 int count = 0;
134 std::string rest = path.substr(1);
135 while (!rest.empty()) {
136 std::string::size_type slash = rest.find(SLASH_CHAR);
137 if (slash == std::string::npos)
138 return count;
139 count++;
140 rest = rest.substr(slash + 1);
141 } // while
142 return count;
143 } // path with slash
144 if (protocol(path) == FILE_PROTOCOL) {
145 return depth(uri(path));
146 } //
147 return -1;
148} // depth
149
154
155std::string
156OksSystem::File::first_line(const std::string& text)
157{
158 std::string::size_type nl = text.find('\n');
159 if (nl > 0)
160 return text.substr(0, nl);
161 return text;
162} // first_line
163
168
170OksSystem::File::from_url(const std::string& url)
171{
172 std::string prot = protocol(url);
174 const std::string path = uri(url);
175 return File(path);
176} // from_url
177
179
180std::string
182{
183 char* wd_buffer = getcwd(0, MAXPATHLEN);
184 if (wd_buffer) {
185 std::string directory = std::string(wd_buffer);
186 free(wd_buffer);
187 return directory;
188 }
189 std::string message("getting the current working directory");
190 throw OksSystem::OksSystemCallIssue(ERS_HERE, errno, "getcwd", message.c_str());
191} // working_directory
192
193void
195{
196 const char* path = dir.c_full_name();
197 const int status = ::chdir(path);
198 if (status < 0) {
199 std::string message = "on directory " + dir.full_name();
200 throw OksSystem::OksSystemCallIssue(ERS_HERE, errno, "chdir", message.c_str());
201 }
202} // working_directory
203
206
207std::string
208OksSystem::File::expand_home(const std::string path)
209{
210 ERS_PRECONDITION(!path.empty());
211 ERS_PRECONDITION(path[0] == '~');
212 std::string::size_type slash = path.find('/');
213 const std::string user_name = path.substr(1, slash - 1);
214 const std::string rest_path = path.substr(slash);
215 OksSystem::User user;
216 if (!user_name.empty()) {
217 user = OksSystem::User(user_name);
218 }
219 return user.home() + rest_path;
220} // home_directory
221
227
228std::string
230{
231 char buffer[11];
232 buffer[0] = (permissions & S_ISUID) ? SETUID_CHAR_CODE : NOTHING_CHAR_CODE;
233 buffer[1] = (permissions & S_IRUSR) ? READ_CHAR_CODE : NOTHING_CHAR_CODE;
234 buffer[2] = (permissions & S_IWUSR) ? WRITE_CHAR_CODE : NOTHING_CHAR_CODE;
235 buffer[3] = (permissions & S_IXUSR) ? EXECUTE_CHAR_CODE : NOTHING_CHAR_CODE;
236 buffer[4] = (permissions & S_IRGRP) ? READ_CHAR_CODE : NOTHING_CHAR_CODE;
237 buffer[5] = (permissions & S_IWGRP) ? WRITE_CHAR_CODE : NOTHING_CHAR_CODE;
238 buffer[6] = (permissions & S_IXGRP) ? EXECUTE_CHAR_CODE : NOTHING_CHAR_CODE;
239 buffer[7] = (permissions & S_IROTH) ? READ_CHAR_CODE : NOTHING_CHAR_CODE;
240 buffer[8] = (permissions & S_IWOTH) ? WRITE_CHAR_CODE : NOTHING_CHAR_CODE;
241 buffer[9] = (permissions & S_IXOTH) ? EXECUTE_CHAR_CODE : NOTHING_CHAR_CODE;
242 buffer[10] = '\0';
243 return std::string(buffer);
244} // pretty_permissions
245
251
252std::string
254{
255 std::ostringstream flag_str;
256 if (flags & O_WRONLY) {
257 flag_str << HUMAN_OPEN_STR[1];
258 } else if (flags & O_RDWR) {
259 flag_str << HUMAN_OPEN_STR[0] << "-" << HUMAN_OPEN_STR[1];
260 } else {
261 flag_str << HUMAN_OPEN_STR[0];
262 }
263 if (flags & O_NONBLOCK) {
264 flag_str << "/" << HUMAN_OPEN_STR[2];
265 }
266 if (flags & O_APPEND) {
267 flag_str << "/" << HUMAN_OPEN_STR[3];
268 }
269 if (flags & O_CREAT) {
270 flag_str << "/" << HUMAN_OPEN_STR[4];
271 }
272 if (flags & O_TRUNC) {
273 flag_str << "/" << HUMAN_OPEN_STR[5];
274 }
275 if (flags & O_EXCL) {
276 flag_str << "/" << HUMAN_OPEN_STR[6];
277 }
278 flag_str << "(" << flags << ")";
279 return flag_str.str();
280} // pretty_open_permission
281
282int
284{
285 ERS_PRECONDITION(u >= 0);
286 if (u == 0)
287 return 1;
288 return KILOBYTE * unit(u - 1);
289} // unit
290
299
300std::string
301OksSystem::File::pretty_size(size_t size, bool cut_small)
302{
303 if (0 == size)
304 return "0";
305 std::ostringstream size_str;
306 bool writen_something = false;
307 for (int i = 3; i >= 0; i--) {
308 const unsigned int size_unit = unit(i);
309 if (size > size_unit && !(cut_small && writen_something)) {
310 const int amount = size / size_unit;
311 size = size % size_unit;
312 size_str << amount << SPACE_CHAR << HUMAN_SIZE_STR[i];
313 writen_something = true;
314 } // if unit is present
315 } // loop
316 return size_str.str();
317} // pretty_size
318
319// --------------------------------------
320// Constructors
321// --------------------------------------
322
326
327OksSystem::File::File(const std::string& name)
328{
329 set_name(name);
330} // File
331
335
336OksSystem::File::File(const char* c_name)
337{
338 ERS_PRECONDITION(c_name);
339 std::string name = std::string(c_name);
340 set_name(name);
341} // File
342
346
348{
349 set_name(other.m_full_name);
350} // File
351
352// --------------------------------------
353// Operators
354// --------------------------------------
355
356OksSystem::File::operator std::string() const throw()
357{
358 return m_full_name;
359} // operator std::string
360
361OksSystem::File::operator const char*() const throw()
362{
363 return m_full_name.c_str();
364} // operator const char*
365
369
370OksSystem::File::operator bool() const throw()
371{
372 return exists();
373} // operator bool
374
381
382bool
383OksSystem::File::equals(const File& other) const throw()
384{
385 return (m_full_name == other.m_full_name);
386} // operator==
387
392
393OksSystem::File::operator size_t() const
394{
395 return size();
396} // operator size_t
397
398// --------------------------------------
399// Methods
400// --------------------------------------
401
413
414void
415OksSystem::File::set_name(const std::string& name)
416{
417 ERS_PRECONDITION(!name.empty());
418 const char c = name[0];
419 std::string long_path;
420 switch (c) {
421 case '/':
422 long_path = name;
423 break;
424 case '~':
425 long_path = expand_home(name);
426 break;
427 default:
428 long_path = working_directory() + "/" + name;
429 break;
430 } // switch
431 char buffer[PATH_MAX];
432 const char* result = realpath(long_path.c_str(), buffer);
433 if (result == 0) { // could not resolve path
434 m_full_name = long_path;
435 } else { // we could canonicalize the path
436 m_full_name = buffer;
437 } //
438} // set_name
439
441
442const std::string&
444{
445 return m_full_name;
446} // full_name
447
449
450const char*
452{
453 return m_full_name.c_str();
454} // c_full_name
455
457
458std::string
460{
461 return short_name(m_full_name);
462} // short_name
463
467
468std::string
470{
471 std::string::size_type size = m_full_name.size();
472 std::string::size_type slash = m_full_name.rfind(SLASH_CHAR, size - 1);
473 if (slash == std::string::npos || slash == 0)
474 return ("/");
475 return m_full_name.substr(0, slash);
476} // directory
477
479
480std::string
482{
483 return extension(m_full_name);
484} // extension
485
486int
488{
489 return depth(m_full_name);
490} // depth
491
493
496{
497 return File(parent_name());
498} // parent
499
501OksSystem::File::child(const std::string& name) const
502{
503 std::string child_name = m_full_name + "/" + name;
504 return OksSystem::File(child_name);
505} // child
506
508OksSystem::File::temporary(const std::string& prefix) const
509{
510 char* tmp_name = tempnam(m_full_name.c_str(), prefix.c_str());
511 if (!tmp_name) {
512 std::string message = "while creating a valid filename in directory " + m_full_name;
513 throw OksSystem::OksSystemCallIssue(ERS_HERE, errno, "tempnam", message.c_str());
514 }
515 OksSystem::File tmp_file(tmp_name);
516 free(tmp_name);
517 return tmp_file;
518} // temporary
519
524
525bool
527{
528 struct stat file_status;
529 const int result = stat(m_full_name.c_str(), &file_status);
530 if (0 == result)
531 return true;
532 return false;
533} // exists
534
540
541mode_t
543{
544 struct stat file_status;
545 const int result = stat(m_full_name.c_str(), &file_status);
546 if (0 == result) {
547 return file_status.st_mode;
548 } // if
549 std::string message = "on file/directory " + m_full_name;
550 throw OksSystem::OksSystemCallIssue(ERS_HERE, errno, "stat", message.c_str());
551} // mode
552
556
557mode_t
559{
560 mode_t mode = get_mode();
561 return (mode & 07777);
562} // permissions
563
567
568std::string
570{
572} // pretty_permissions
573
578
579std::string
581{
582 std::ostringstream stream;
583 stream.setf(std::ios::oct, std::ios::basefield);
584 stream << permissions;
585 return stream.str();
586} // to_string
587
591
592size_t
594{
595 struct stat file_status;
596 const int result = stat(m_full_name.c_str(), &file_status);
597 if (0 == result)
598 return file_status.st_size;
599 std::string message = "on file/directory " + m_full_name;
600 throw OksSystem::OksSystemCallIssue(ERS_HERE, errno, "stat", message.c_str());
601} // size
602
606
607uid_t
609{
610 struct stat file_status;
611 const int result = stat(m_full_name.c_str(), &file_status);
612 if (0 == result)
613 return file_status.st_uid;
614 std::string message = "on file/directory " + m_full_name;
615 throw OksSystem::OksSystemCallIssue(ERS_HERE, errno, "stat", message.c_str());
616} // owner_id
617
620{
621 return User(owner_id());
622} // owner
623
627
628gid_t
630{
631 struct stat file_status;
632 const int result = stat(m_full_name.c_str(), &file_status);
633 if (0 == result)
634 return file_status.st_gid;
635 std::string message = "on file/directory " + m_full_name;
636 throw OksSystem::OksSystemCallIssue(ERS_HERE, errno, "stat", message.c_str());
637} // owner
638
643
644bool
646{
647 const mode_t mode = get_mode();
648 return (mode & S_IFREG);
649} // is_regular
650
655
656bool
658{
659 const mode_t mode = get_mode();
660 return (mode & S_IFDIR);
661} // is_regular
662
667
668bool
670{
671 const mode_t mode = get_mode();
672 return (mode & S_IFIFO);
673} // is_pipe
674
675std::string
677{
680 params.push_back("-b");
681 params.push_back(full_name());
682 return first_line(file_command.pipe_in(params));
683} // file_type
684
690
693{
694 file_list_t file_vector;
695 DIR* directory_ptr = opendir(m_full_name.c_str());
696 if (!directory_ptr) {
697 std::string message = "on directory " + m_full_name;
698 throw OksSystem::OksSystemCallIssue(ERS_HERE, errno, "opendir", message.c_str());
699 }
700 while (true) {
701 struct dirent* directory_entry = readdir(directory_ptr);
702 if (directory_entry) {
703 const std::string name = directory_entry->d_name;
704 if ((name != ".") && (name != "..")) {
705 std::string path = m_full_name + "/" + name;
706 OksSystem::File file(path);
707 file_vector.push_back(file);
708 } // if
709 } else {
710 break;
711 } // if / else
712 } // while
713 int status = closedir(directory_ptr);
714 if (status < 0) {
715 std::string message = "on directory " + m_full_name;
716 throw OksSystem::OksSystemCallIssue(ERS_HERE, errno, "closedir", message.c_str());
717 }
718 return file_vector;
719} // directory
720
724
725void
727{
728 const int result = ::unlink(m_full_name.c_str());
729 if (0 == result)
730 return;
731 throw OksSystem::RemoveFileIssue(ERS_HERE, errno, m_full_name.c_str());
732} // unlink
733
734void
736{
737 const int result = ::rmdir(m_full_name.c_str());
738 if (0 == result)
739 return;
740 std::string message = "on directory " + m_full_name;
741 throw OksSystem::OksSystemCallIssue(ERS_HERE, errno, "rmdir", message.c_str());
742} // rmdir
743
748
749void
751{
752 if (is_directory()) {
753 file_list_t childs = directory();
754 for (file_list_t::const_iterator p = childs.begin(); p != childs.end(); p++) {
755 const File f = *p;
756 if (f.exists()) {
757 f.remove();
758 }
759 } // for
760 rmdir();
761 } else {
762 unlink();
763 }
764} // remove
765
770
771void
772OksSystem::File::rename(const File& other) const
773{
774 const char* source = c_full_name();
775 const char* dest = other.c_full_name();
776 const int result = ::rename(source, dest);
777 if (0 == result)
778 return;
779 throw OksSystem::RenameFileIssue(ERS_HERE, errno, source, dest);
780} // rename
781
786
787void
789{
790 if (perm != permissions()) {
791 const int result = ::chmod(m_full_name.c_str(), perm);
792 if (0 == result) {
793 return;
794 }
795 std::string message = "on file/directory " + m_full_name;
796 throw OksSystem::OksSystemCallIssue(ERS_HERE, errno, "chmod", message.c_str());
797 }
798} // permissions
799
806
807void
809{
810
811 errno = 0;
812 const int result = ::mkdir(m_full_name.c_str(), perm);
813 int mkdir_error = errno;
814
815 if (0 == result) {
816 try {
817 permissions(perm);
818 } catch (OksSystem::OksSystemCallIssue& e) {
819 std::string message = "on directory " + m_full_name;
820 throw OksSystem::OksSystemCallIssue(ERS_HERE, errno, "mkdir -> chmod", message.c_str());
821 }
822 return;
823 } else {
824 if (exists()) {
825 if (is_directory()) { // already exists we attempt a chmod
826 try {
827 permissions(perm);
828 } catch (OksSystem::OksSystemCallIssue& e) {
829 // ignore this case...
830 }
831 return;
832 } // is directory
833 } else { // exists
834 std::string message = "on directory " + m_full_name;
835 throw OksSystem::OksSystemCallIssue(ERS_HERE, mkdir_error, "mkdir", message.c_str());
836 }
837 }
838
839} // makedir
840
850
851void
853{
854 const File father = parent();
855 if (!father.exists()) {
856 mode_t father_permission = perm | S_IRWXU; // we need rights to write sons
857 father.make_path(father_permission);
858 } // if
859 make_dir(perm);
860} // makepath
861
867
868void
870{
871 const File father = parent();
872 father.make_path(perm);
873} // ensure_path
874
878
879void
881{
882 if (exists()) {
883 if (is_fifo()) {
884 if (perm != permissions()) {
885 permissions(perm);
886 return;
887 } else {
888 return;
889 }
890 } // is_fifo
891 } // exists
892 const int status = ::mkfifo(m_full_name.c_str(), perm);
893 if (status == 0) {
894 permissions(perm);
895 return;
896 }
897 std::string message = "while creating FIFO " + m_full_name;
898 throw OksSystem::OksSystemCallIssue(ERS_HERE, errno, "mkfifo", message.c_str());
899} // makefifo
900
906
907std::istream*
909{
910 try {
911 std::ifstream* stream = new std::ifstream(m_full_name.c_str());
912 stream->exceptions(std::ios::failbit | std::ios::badbit);
913 return stream;
914 } catch (std::ios_base::failure& ex) {
915 throw OksSystem::OpenFileIssue(ERS_HERE, errno, m_full_name.c_str(), ex);
916 } // catch
917} // std::istream*
918
925
926std::ostream*
927OksSystem::File::output(bool append) const
928{
929 try {
930 std::ios::openmode mode = std::ios::out;
931 if (append) {
932 mode |= std::ios::app;
933 }
934 std::ofstream* stream = new std::ofstream(m_full_name.c_str(), mode);
935 stream->exceptions(std::ios::failbit | std::ios::badbit);
936 return stream;
937 } catch (std::ios_base::failure& ex) {
938 throw OksSystem::OpenFileIssue(ERS_HERE, errno, m_full_name.c_str(), ex);
939 } // catch
940} // std::ostream*
941
947
948std::ostream&
949operator<<(std::ostream& stream, const OksSystem::File& file)
950{
951 stream << OksSystem::File::FILE_PROTOCOL << ":/" << file.full_name();
952 return stream;
953} // operator<<
954
955bool
956operator==(const OksSystem::File& a, const OksSystem::File& b) throw()
957{
958 return a.equals(b);
959} // operator ==
960
961bool
962operator!=(const OksSystem::File& a, const OksSystem::File& b) throw()
963{
964 return !a.equals(b);
965} // operator !=
#define ERS_PRECONDITION(expression)
#define SETUID_CHAR_CODE
Definition File.cpp:50
#define NOTHING_CHAR_CODE
Definition File.cpp:49
#define WRITE_CHAR_CODE
Definition File.cpp:47
#define SLASH_CHAR
Definition File.cpp:52
#define EXECUTE_CHAR_CODE
Definition File.cpp:48
#define DOT_CHAR
Definition File.cpp:54
#define READ_CHAR_CODE
Definition File.cpp:46
#define COLON_CHAR
Definition File.cpp:53
#define SPACE_CHAR
Definition File.cpp:37
bool operator==(const OksSystem::File &a, const OksSystem::File &b)
Definition File.cpp:956
bool operator!=(const OksSystem::File &a, const OksSystem::File &b)
Definition File.cpp:962
#define ERS_HERE
void operator<<(TraceStreamer &x, const ers::Issue &r)
Definition Logger.hxx:128
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: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
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
const std::string & home() const
home directory name
Definition User.cpp:241
User()
constructor for current user
Definition User.cpp:27