proxygen
folly::fs Namespace Reference

Functions

bool starts_with (const path &pth, const path &prefix)
 
path remove_prefix (const path &pth, const path &prefix)
 
path canonical_parent (const path &pth, const path &base)
 
path executable_path ()
 

Function Documentation

path folly::fs::canonical_parent ( const path &  p,
const path &  basePath = current_path() 
)

Canonicalize the parent path, leaving the filename (last component) unchanged. You may use this before creating a file instead of boost::filesystem::canonical, which requires that the entire path exists.

Definition at line 68 of file FsUtil.cpp.

Referenced by TEST().

68  {
69  return canonical(pth.parent_path(), base) / pth.filename();
70 }
path folly::fs::executable_path ( )

Get the path to the current executable.

Note that this is not reliable and not recommended in general; it may not be implemented on your platform (in which case it will throw), the executable might have been moved or replaced while running, and applications comprising of multiple executables should use some form of configuration system to find the other executables rather than relying on relative paths from one to another.

So this should only be used for tests, logging, or other innocuous purposes.

Definition at line 72 of file FsUtil.cpp.

Referenced by TEST().

72  {
73  return read_symlink("/proc/self/exe");
74 }
path folly::fs::remove_prefix ( const path &  p,
const path &  prefix 
)

If "path" starts with "prefix", return "path" with "prefix" removed. Otherwise, throw filesystem_error.

Definition at line 50 of file FsUtil.cpp.

Referenced by TEST().

50  {
51  path::const_iterator it;
52  if (!skipPrefix(pth, prefix, it)) {
53  throw filesystem_error(
54  "Path does not start with prefix",
55  pth,
56  prefix,
57  bsys::errc::make_error_code(bsys::errc::invalid_argument));
58  }
59 
60  path p;
61  for (; it != pth.end(); ++it) {
62  p /= *it;
63  }
64 
65  return p;
66 }
bool prefix(Cursor &c, uint32_t expected)
bool folly::fs::starts_with ( const path &  p,
const path &  prefix 
)

Check whether "path" starts with "prefix". That is, if prefix has n path elements, then the first n elements of path must be the same as prefix.

There is a special case if prefix ends with a slash: /foo/bar/ is not a prefix of /foo/bar, but both /foo/bar and /foo/bar/ are prefixes of /foo/bar/baz.

Definition at line 45 of file FsUtil.cpp.

Referenced by TEST().

45  {
46  path::const_iterator it;
47  return skipPrefix(pth, prefix, it);
48 }
bool prefix(Cursor &c, uint32_t expected)