Dobby 3.0
Dobby “Docker based Thingy” is a tool for managing and running OCI containers using crun
Loading...
Searching...
No Matches
FileUtilities.h
1/*
2* If not stated otherwise in this file or this component's LICENSE file the
3* following copyright and licenses apply:
4*
5* Copyright 2014 Sky UK
6*
7* Licensed under the Apache License, Version 2.0 (the "License");
8* you may not use this file except in compliance with the License.
9* You may obtain a copy of the License at
10*
11* http://www.apache.org/licenses/LICENSE-2.0
12*
13* Unless required by applicable law or agreed to in writing, software
14* distributed under the License is distributed on an "AS IS" BASIS,
15* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16* See the License for the specific language governing permissions and
17* limitations under the License.
18*/
19/*
20 * File: FileUtilities.h
21 * Author: jarek.dziedzic@bskyb.com
22 *
23 * Created on 11 July 2014
24 *
25 */
26
27#ifndef FILEUTILITIES_H
28#define FILEUTILITIES_H
29
30#include <string>
31#include <vector>
32#include <dirent.h>
33#include <sys/stat.h>
34#include <stdio.h>
35#include <limits.h>
36
37#include <boost/optional.hpp>
38
39
40#if !defined(SIZE_T_MAX)
41# define SIZE_T_MAX SIZE_MAX
42#endif
43
44
45namespace AICommon
46{
47
48const mode_t S_IRXALL = S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH;
49const mode_t S_IRALL = S_IRUSR | S_IRGRP | S_IROTH;
50
55std::vector<std::string> splitPath(const std::string& path);
56
64bool mkdirRecursive(const std::string& path, mode_t mode = S_IRWXU);
65
73bool mkdirRecursiveAt(const std::string& fullPath, int parentDirectoryFd, mode_t mode = S_IRWXU);
74
78bool exists(const std::string& path);
79
86int copyFile(const std::string & to, const std::string & from);
87int copyFile(const char *to, const char *from);
88
89
95void deleteDirectory(const std::string& directoryName);
96
103void deleteDirectoryAt(int parentDirectoryFd, const std::string& directoryName);
104
112 bool deleteFilesInDirectory(const std::string& directoryName);
113
119bool deleteFile(const std::string & filePath);
120
126std::vector<std::string> getFilesInDirectory(int dirFd);
127std::vector<std::string> getFilesInDirectory(const std::string & dirName, bool fullPaths = false);
128
134std::string resolvePath(const std::string& in);
135
140std::vector<uint8_t> fileContents(const std::string& filepath);
141
147std::vector<uint8_t> fileContents(int fd, size_t maxSize = SIZE_T_MAX);
148std::vector<uint8_t> fileContents(int dirFd, const std::string& filepath, size_t maxSize = SIZE_T_MAX);
149
154bool compareFilesExactly(const std::string & filePathApples, const std::string & filePathOranges);
155
163bool createTextFile(const std::string& filePath, const std::string& contents, mode_t mode = S_IRWXU);
164bool createTextFileAt(int dirFd, const std::string& filePath, const std::string& contents, mode_t mode = S_IRWXU);
165
169std::string readTextStream(FILE *fp);
170
190boost::optional<std::string> getXAttrib(int fileFd, const std::string& key);
191
197boost::optional<std::string> getXAttrib(const std::string& filePath, const std::string& key);
198
223bool setXAttrib(int fd, const std::string& key, const std::string& value, int flags = 0);
224bool setXAttrib(const std::string& filePath, const std::string& key, const std::string& value, int flags = 0);
225
231std::string fileMD5(const std::string & filePath);
232std::string fileMD5(int fd);
233
242int getDeviceFreeMegabytes(const std::string & path);
243
249size_t getDirectorySizeInKb( const std::string &path );
250
251}
252
253#endif /* FILEUTILITIES_H */
254