]> git.tdb.fi Git - libs/core.git/blob - source/fs/utils.h
Add common_ancestor function
[libs/core.git] / source / fs / utils.h
1 #ifndef MSP_FS_UTILS_H_
2 #define MSP_FS_UTILS_H_
3
4 #include "path.h"
5
6 namespace Msp {
7 namespace FS {
8
9 /// Extracts the last component of the path.
10 std::string basename(const Path &);
11
12 /// Removes the last component from the path.
13 Path dirname(const Path &);
14
15 /** Returns the base part of a filename.  This includes everything up to the
16 last dot, but not the dot itself. */
17 std::string basepart(const std::string &);
18
19 /** Returns the extension part of a filename.  This includes the last dot and
20 everything after it. */
21 std::string extpart(const std::string &);
22
23 /// Fixes the case of a path to match files / directories on the filesystem.
24 Path fix_case(const Path &path);
25
26 /// Reads the contents of a symbolic link
27 Path readlink(const Path &path);
28
29 /// Resolves all symlinks from a path.  Will always return an absolute path.
30 Path realpath(const Path &path);
31
32 /// Removes a file
33 void unlink(const Path &path);
34
35 /// Renames a file.  Existing file, if any, is overwritten.
36 void rename(const Path &from, const Path &to);
37
38 /// Makes a path relative to some base path.  That is, base/result==path.
39 Path relative(const Path &path, const Path &base);
40
41 /// Returns the longest prefix shared by both paths.
42 Path common_ancestor(const Path &, const Path &);
43
44 /** Determines how many levels a path is below another.  Returns -1 if path is
45 not a descendant of parent. */
46 int descendant_depth(const Path &path, const Path &parent);
47
48 } // namespace FS
49 } // namespace Msp
50
51 #endif