Fork Vasum on GitHub Official Vasum Wiki on Tizen.org
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
fs.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Contact: Lukasz Pawelczyk <l.pawelczyk@partner.samsung.com>
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License
17  */
18 
25 #ifndef COMMON_UTILS_FS_HPP
26 #define COMMON_UTILS_FS_HPP
27 
28 #include <string>
29 #include <sys/types.h>
30 #include <vector>
31 #include <boost/filesystem.hpp>
32 
33 
34 namespace utils {
35 
39 std::string readFileStream(const std::string& path);
40 
44 bool readFileStream(const std::string& path, std::string& result);
45 
49 std::string readFileContent(const std::string& path);
50 
54 bool readFileContent(const std::string& path, std::string& content);
55 
59 bool saveFileContent(const std::string& path, const std::string& content);
60 
65 bool readFirstLineOfFile(const std::string& path, std::string& ret);
66 
70 bool removeFile(const std::string& path);
71 
75 bool isCharDevice(const std::string& path);
76 
80 void assertIsDir(const std::string& path);
81 
85 void assertIsAbsolute(const std::string& path);
86 
90 bool listDir(const std::string& path, std::vector<std::string>& files);
91 
95 bool mountRun(const std::string& path);
96 
100 bool mount(const std::string& source,
101  const std::string& target,
102  const std::string& filesystemtype,
103  unsigned long mountflags,
104  const std::string& data);
105 
109 bool umount(const std::string& path);
110 
114 bool isMountPoint(const std::string& path, bool& result);
115 
119 bool hasSameMountPoint(const std::string& path1, const std::string& path2, bool& result);
120 
126 bool moveFile(const std::string& src, const std::string& dst);
127 
131 bool copyDirContents(const std::string& src, const std::string& dst);
132 
136 bool createDir(const std::string& path, uid_t uid, uid_t gid, boost::filesystem::perms mode);
137 
141 bool createDirs(const std::string& path, mode_t mode);
142 
148 bool createEmptyDir(const std::string& path);
149 
153 bool createFile(const std::string& path, int flags, mode_t mode);
154 
158 bool createFifo(const std::string& path, mode_t mode);
159 
163 bool copyFile(const std::string& src, const std::string& dest);
164 
168 bool createLink(const std::string& src, const std::string& dest);
169 
170 } // namespace utils
171 
172 
173 #endif // COMMON_UTILS_FS_HPP
bool createFifo(const std::string &path, mode_t mode)
Creates an FIFO special file.
Definition: fs.cpp:520
std::string readFileStream(const std::string &path)
Reads the content of file stream (no seek); Throws exception on error.
Definition: fs.cpp:50
bool hasSameMountPoint(const std::string &path1, const std::string &path2, bool &result)
Checks whether the given paths are under the same mount point.
Definition: fs.cpp:277
bool createDir(const std::string &path, uid_t uid, uid_t gid, boost::filesystem::perms mode)
Creates a directory with specific UID, GID and permissions set.
Definition: fs.cpp:408
void assertIsAbsolute(const std::string &path)
Checks if path is absolute.
Definition: fs.cpp:192
bool saveFileContent(const std::string &path, const std::string &content)
Save the content to the file.
Definition: fs.cpp:114
std::string readFileContent(const std::string &path)
Reads the content of a file (performs seek); Throws exception on error.
Definition: fs.cpp:76
bool createDirs(const std::string &path, mode_t mode)
Recursively creates a directory with specific permissions set.
Definition: fs.cpp:447
bool removeFile(const std::string &path)
Remove file.
Definition: fs.cpp:145
bool umount(const std::string &path)
Umounts a filesystem.
Definition: fs.cpp:255
char data[368]
Definition: initctl.cpp:41
bool createFile(const std::string &path, int flags, mode_t mode)
Creates an empty file.
Definition: fs.cpp:505
bool readFirstLineOfFile(const std::string &path, std::string &ret)
Read a line from file Its goal is to read a kernel config files (eg.
Definition: fs.cpp:129
bool isCharDevice(const std::string &path)
Checks if a char device exists.
Definition: fs.cpp:158
bool mount(const std::string &source, const std::string &target, const std::string &filesystemtype, unsigned long mountflags, const std::string &data)
Creates mount point.
Definition: fs.cpp:225
bool isMountPoint(const std::string &path, bool &result)
Check if given path is a mount point.
Definition: fs.cpp:264
bool listDir(const std::string &path, std::vector< std::string > &files)
List all (including '.
void assertIsDir(const std::string &path)
Checks if a path exists and points to a directory.
Definition: fs.cpp:164
bool mountRun(const std::string &path)
Mounts run as a tmpfs on a given path.
Definition: fs.cpp:219
bool copyDirContents(const std::string &src, const std::string &dst)
Recursively copy contents of src dir to dst dir.
Definition: fs.cpp:403
bool copyFile(const std::string &src, const std::string &dest)
Copy an file.
Definition: fs.cpp:530
bool createLink(const std::string &src, const std::string &dest)
Create hard link.
Definition: fs.cpp:562
bool moveFile(const std::string &src, const std::string &dst)
Moves the file either by rename if under the same mount point or by copy&delete if under a different ...
Definition: fs.cpp:295
bool createEmptyDir(const std::string &path)
Creates an empty directory, ready to serve as mount point.
Definition: fs.cpp:477