xref: /haiku/src/apps/haikudepot/util/StorageUtils.h (revision 02354704729d38c3b078c696adc1bbbd33cbcf72)
1 /*
2  * Copyright 2017-2021, Andrew Lindesay <apl@lindesay.co.nz>.
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 #ifndef PATH_UTILS_H
6 #define PATH_UTILS_H
7 
8 #include <Path.h>
9 
10 class StorageUtils {
11 
12 public:
13 	static bool				AreWorkingFilesAvailable();
14 	static void				SetWorkingFilesUnavailable();
15 
16 	static status_t			LocalWorkingFilesPath(const BString leaf,
17 								BPath& path,
18 								bool failOnCreateDirectory = true);
19 	static status_t			LocalWorkingDirectoryPath(const BString leaf,
20 								BPath& path,
21 								bool failOnCreateDirectory = true);
22 
23 	static status_t			CheckCanWriteTo(const BPath& path);
24 
25 	static status_t			AppendToString(const BPath& path, BString& result);
26 	static status_t			AppendToFile(const BString& input,
27 								const BPath& path);
28 
29 	static status_t			RemoveWorkingDirectoryContents();
30 	static status_t			RemoveDirectoryContents(BPath& path);
31 	static status_t			ExistsObject(const BPath& path,
32 								bool* exists,
33 								bool* isDirectory,
34 								off_t* size);
35 
36 	static	status_t		SwapExtensionOnPath(BPath& path,
37 								const char* extension);
38 	static	BString			SwapExtensionOnPathComponent(
39 								const char* pathComponent,
40 								const char* extension);
41 };
42 
43 #endif // PATH_UTILS_H
44