Commit | Line | Data |
---|---|---|
8c15b8c7 TJ |
1 | /* |
2 | The software in this package is distributed under the GNU General | |
3 | Public License version 2 (with a special exception described below). | |
4 | ||
5 | A copy of GNU General Public License (GPL) is included in this distribution, | |
6 | in the file COPYING.GPL. | |
7 | ||
8 | As a special exception, if other files instantiate templates or use macros | |
9 | or inline functions from this file, or you compile this file and link it | |
10 | with other works to produce a work based on this file, this file | |
11 | does not by itself cause the resulting work to be covered | |
12 | by the GNU General Public License. | |
13 | ||
14 | However the source code for this file must still be made available | |
15 | in accordance with section (3) of the GNU General Public License. | |
16 | ||
17 | This exception does not invalidate any other reasons why a work based | |
18 | on this file might be covered by the GNU General Public License. | |
19 | */ | |
ef51ea7e RP |
20 | /** |
21 | * @file | |
22 | * @brief some functions to wrap some system functions | |
23 | * | |
24 | * @author Reinhard Pfau \<Reinhard.Pfau@gmx.de\> | |
25 | * @copyright © Copyright 2009 by Intra2net AG | |
ef51ea7e RP |
26 | */ |
27 | ||
28 | ||
29 | #ifndef _ASYNCIO_SYSTEM_TOOLS_HPP_ | |
30 | #define _ASYNCIO_SYSTEM_TOOLS_HPP_ | |
31 | ||
32 | #include <string> | |
33 | ||
34 | ||
35 | namespace AsyncIo | |
36 | { | |
37 | namespace Utils | |
38 | { | |
39 | ||
9b21df9d RP |
40 | /** |
41 | * @brief removed a file entry from file system (if existing). | |
42 | * @param path path to be removed. | |
43 | * @return @a true if the file was successfully deleted. | |
44 | */ | |
85108f09 RP |
45 | bool unlink( const std::string& path ); |
46 | ||
47 | ||
9b21df9d RP |
48 | /** |
49 | * @brief represents a file(/path) status. | |
50 | * | |
51 | * This is basically a wrapper around the "stat" call. | |
52 | */ | |
85108f09 RP |
53 | class FileStat |
54 | { | |
55 | public: | |
9b21df9d | 56 | FileStat( const std::string& path, bool follow_symlinks= true ); |
85108f09 RP |
57 | ~FileStat(); |
58 | ||
9b21df9d RP |
59 | /** |
60 | * @brief stat the path again and updates the values. | |
61 | */ | |
85108f09 RP |
62 | void refresh(); |
63 | ||
9b21df9d RP |
64 | /** |
65 | * @brief returns if the stat values are valid. | |
66 | * @return @a true if the stat values are valid. | |
67 | */ | |
85108f09 RP |
68 | bool is_valid() const { return m_is_valid; } |
69 | ||
70 | operator bool() const { return m_is_valid; } | |
71 | ||
72 | bool is_regular_file() const { return m_is_regular_file; } | |
73 | bool is_directory() const { return m_is_directory; } | |
9b21df9d RP |
74 | bool is_character_device() const { return m_is_character_device; } |
75 | bool is_block_device() const { return m_is_block_device; } | |
76 | bool is_fifo() const { return m_is_fifo; } | |
77 | bool is_symbolic_link() const { return m_is_symbolic_link; } | |
78 | bool is_link() const { return m_is_symbolic_link; } | |
79 | bool is_socket() const { return m_is_socket; } | |
85108f09 RP |
80 | |
81 | private: | |
82 | std::string m_path; | |
9b21df9d | 83 | bool m_follow_symlinks; |
85108f09 RP |
84 | |
85 | bool m_is_valid; | |
86 | ||
87 | bool m_is_regular_file; | |
88 | bool m_is_directory; | |
9b21df9d RP |
89 | bool m_is_character_device; |
90 | bool m_is_block_device; | |
91 | bool m_is_fifo; | |
92 | bool m_is_symbolic_link; | |
93 | bool m_is_socket; | |
85108f09 RP |
94 | |
95 | }; // end of FileStat | |
96 | ||
ef51ea7e RP |
97 | |
98 | } // end of namespace Utils | |
9b21df9d | 99 | } // end of namespace AsyncIo |
ef51ea7e RP |
100 | |
101 | ||
102 | #endif |