Qore Programming Language  1.12.0
QoreDir.h
1 /* -*- mode: c++; indent-tabs-mode: nil -*- */
2 /*
3  QoreDir.h
4 
5  thread-safe Directory object with a private implementation
6 
7  Qore Programming Language
8 
9  Copyright (C) 2003 - 2022 Qore Technologies, s.r.o.
10 
11  Permission is hereby granted, free of charge, to any person obtaining a
12  copy of this software and associated documentation files (the "Software"),
13  to deal in the Software without restriction, including without limitation
14  the rights to use, copy, modify, merge, publish, distribute, sublicense,
15  and/or sell copies of the Software, and to permit persons to whom the
16  Software is furnished to do so, subject to the following conditions:
17 
18  The above copyright notice and this permission notice shall be included in
19  all copies or substantial portions of the Software.
20 
21  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27  DEALINGS IN THE SOFTWARE.
28 
29  Note that the Qore library is released under a choice of three open-source
30  licenses: MIT (as above), LGPL 2+, or GPL 2+; see README-LICENSE for more
31  information.
32 */
33 
34 #ifndef _QORE_QOREDIR_H
35 
36 #define _QORE_QOREDIR_H
37 
38 #include <dirent.h>
39 #include <string>
40 #include <vector>
41 
42 #ifndef HAVE_DIRENT_D_TYPE
43 #include <sys/stat.h>
44 #include <sys/types.h>
45 #include <unistd.h>
46 #endif
47 
49 
52 class QoreDir {
53 public:
55 
60  DLLEXPORT QoreDir(ExceptionSink* xsink, const QoreEncoding* cs = QCS_DEFAULT, const char* dir = nullptr);
61 
63 
66  DLLEXPORT QoreDir(ExceptionSink* xsink, const QoreDir& old);
67 
69  DLLEXPORT ~QoreDir();
70 
72 
76  DLLEXPORT static bool file_exists(const QoreString& filePath);
77 
79 
85  DLLEXPORT static bool folder_exists(const QoreString& folderPath, ExceptionSink& xsink, const QoreEncoding* cs = QCS_DEFAULT);
86 
88 
92  DLLEXPORT static std::string get_file_content(const QoreString& fullPath);
93 
95 
102  DLLEXPORT static QoreListNode* get_files(const QoreString& path, ExceptionSink& xsink, QoreString* regex = nullptr, const QoreEncoding* cs = QCS_DEFAULT);
103 
105 
110  DLLEXPORT int chdir(const char* dir, ExceptionSink* xsink);
111 
113 
118  DLLEXPORT int chdir(const char* dir);
119 
121 
126  DLLEXPORT int mkdir(ExceptionSink* xsink, const char* subdir, int mode = 0777) const;
127 
129 
133  DLLEXPORT int rmdir(const char* subdir, ExceptionSink* xsink) const;
134 
136 
140  DLLEXPORT int chmod(int mode, ExceptionSink* xsink) const;
141 
142 #ifdef HAVE_PWD_H
144 
149  DLLEXPORT int chown(uid_t uid, gid_t gid, ExceptionSink* xsink) const;
150 #endif
151 
153 
157  DLLEXPORT int create(int mode, ExceptionSink* xsink) const;
158 
160 
166  DLLEXPORT int create(int mode) const;
167 
169 
171  DLLEXPORT int checkPath() const;
172 
174 
176  DLLEXPORT QoreStringNode* dirname() const;
177 
179 
182  DLLEXPORT std::string getPath(const char* sub) const;
183 
185 
187  DLLEXPORT const QoreEncoding* getEncoding() const;
188 
190 
198  DLLEXPORT QoreFile openFile(ExceptionSink* xsink, const char* fn, int flags = O_RDONLY, int mode = 0777, const QoreEncoding* cs = QCS_DEFAULT);
199 
201 
208  DLLEXPORT QoreListNode* list(ExceptionSink* xsink, int stat_filter, const QoreString* regex = nullptr, int regex_options = 0, bool full = false) const;
209 
211 
214  DLLEXPORT QoreListNode* stat(ExceptionSink* xsink) const;
215 
217 
220  DLLEXPORT QoreHashNode* hstat(ExceptionSink* xsink) const;
221 
223 
226  DLLEXPORT QoreHashNode* statvfs(ExceptionSink* xsink) const;
227 
228 private:
230  class qore_qd_private *priv;
231 
233  DLLLOCAL QoreDir(const QoreDir&);
234 
236  DLLLOCAL QoreDir& operator=(const QoreDir&);
237 };
238 
239 #endif // _QORE_QOREDIR_H
DLLEXPORT const QoreEncoding * QCS_DEFAULT
the default encoding for the Qore library
container for holding Qore-language exception information and also for registering a "thread_exit" ca...
Definition: ExceptionSink.h:48
provides controlled access to the filesystem through directories
Definition: QoreDir.h:52
DLLEXPORT int mkdir(ExceptionSink *xsink, const char *subdir, int mode=0777) const
creates a subdirectory of the current directory
DLLEXPORT QoreHashNode * statvfs(ExceptionSink *xsink) const
returns a QoreHashNode with filesystem status information
DLLEXPORT QoreStringNode * dirname() const
returns the current directory name or 0 if none is set
DLLEXPORT const QoreEncoding * getEncoding() const
returns the encoding used for the filesystem
DLLEXPORT int chmod(int mode, ExceptionSink *xsink) const
changes the mode of the current directory
DLLEXPORT QoreFile openFile(ExceptionSink *xsink, const char *fn, int flags=O_RDONLY, int mode=0777, const QoreEncoding *cs=QCS_DEFAULT)
returns a new file in this directory
static DLLEXPORT bool folder_exists(const QoreString &folderPath, ExceptionSink &xsink, const QoreEncoding *cs=QCS_DEFAULT)
checks whether folder exists
DLLEXPORT int create(int mode, ExceptionSink *xsink) const
creates the current directory, including all parent directories, if they do not exist
DLLEXPORT QoreDir(ExceptionSink *xsink, const QoreEncoding *cs=QCS_DEFAULT, const char *dir=nullptr)
creates the object and sets the default encoding
static DLLEXPORT bool file_exists(const QoreString &filePath)
checks whether file exists
DLLEXPORT QoreListNode * list(ExceptionSink *xsink, int stat_filter, const QoreString *regex=nullptr, int regex_options=0, bool full=false) const
returns a list of files in the current directory, taking an option regular expression filter
DLLEXPORT int checkPath() const
returns 0 = OK (path exists), non-zero = errno returned by opendir()
DLLEXPORT int rmdir(const char *subdir, ExceptionSink *xsink) const
removes a subdirectory of the current directory
DLLEXPORT std::string getPath(const char *sub) const
returns a complete path with the argument appended to the current directory name
DLLEXPORT ~QoreDir()
closes the directory and frees all memory allocated to the object
DLLEXPORT int chdir(const char *dir, ExceptionSink *xsink)
changes the directory in relation to the current
DLLEXPORT QoreHashNode * hstat(ExceptionSink *xsink) const
returns a QoreHashNode with directory status information
DLLEXPORT QoreListNode * stat(ExceptionSink *xsink) const
returns a QoreListNode with directory status information
static DLLEXPORT QoreListNode * get_files(const QoreString &path, ExceptionSink &xsink, QoreString *regex=nullptr, const QoreEncoding *cs=QCS_DEFAULT)
look up files
static DLLEXPORT std::string get_file_content(const QoreString &fullPath)
reads file content
defines string encoding functions in Qore
Definition: QoreEncoding.h:83
provides controlled access to file data through Qore data structures
Definition: QoreFile.h:66
This is the hash or associative list container type in Qore, dynamically allocated only,...
Definition: QoreHashNode.h:50
This is the list container type in Qore, dynamically allocated only, reference counted.
Definition: QoreListNode.h:52
Qore's string type supported by the QoreEncoding class.
Definition: QoreString.h:93
Qore's string value type, reference counted, dynamically-allocated only.
Definition: QoreStringNode.h:50