diff options
author | Karen Arutyunov <karen@codesynthesis.com> | 2020-03-11 22:50:15 +0300 |
---|---|---|
committer | Karen Arutyunov <karen@codesynthesis.com> | 2020-03-17 13:15:42 +0300 |
commit | 56e49a09b4f1d268bfee83324bbcd44eb925815b (patch) | |
tree | 9a8a8395560296fe52ad7b2fef487eef6ee7b4e6 /tests/path-entry/driver.cxx | |
parent | aabd974df745b8f9c061ab162d9babfc9545c108 (diff) |
Add readsymlink(), followsymlink(), and try_followsymlink()
Diffstat (limited to 'tests/path-entry/driver.cxx')
-rw-r--r-- | tests/path-entry/driver.cxx | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/tests/path-entry/driver.cxx b/tests/path-entry/driver.cxx index 51ac04d..30aae92 100644 --- a/tests/path-entry/driver.cxx +++ b/tests/path-entry/driver.cxx @@ -18,12 +18,14 @@ import std.core; import std.io; #endif import butl.path; +import butl.path-io; import butl.utility; // operator<<(ostream, exception) import butl.optional; import butl.timestamp; import butl.filesystem; #else #include <libbutl/path.mxx> +#include <libbutl/path-io.mxx> #include <libbutl/utility.mxx> #include <libbutl/optional.mxx> #include <libbutl/timestamp.mxx> @@ -36,11 +38,12 @@ using namespace butl; // Usage: argv[0] [-l] [-t] [-p <permissions>] [-m <time>] [-a <time>] <path> // // If path entry exists then optionally modify its meta-information and print -// its type, size (meaningful for the regular file only), permissions, -// modification and access times to STDOUT, one value per line, and exit with +// its type, size (meaningful for the regular file only), target path if the +// specified entry is a symlink and its path otherwise, permissions, +// modification and access times to stdout, one value per line, and exit with // the zero code. Otherwise exit with the one code. Don't follow symlink by -// default. On failure print the error description to STDERR and exit with -// the two code. +// default. On failure print the error description to stderr and exit with the +// two code. // // -l // Follow symlinks. @@ -136,6 +139,10 @@ main (int argc, const char* argv[]) if (!es.first) return 1; + stage = "lstat entry"; + pair<bool, entry_stat> ls (path_entry (p)); + assert (ls.first); + // The entry is a directory with a symlink followed. // bool tdir; @@ -188,7 +195,6 @@ main (int argc, const char* argv[]) } cout << "type: "; - switch (es.second.type) { case entry_type::unknown: cout << "unknown"; break; @@ -197,13 +203,18 @@ main (int argc, const char* argv[]) case entry_type::symlink: cout << "symlink"; break; case entry_type::other: cout << "other"; break; } + cout << endl; + + cout << "size: " << es.second.size << endl + << "target: " + << (ls.second.type == entry_type::symlink + ? readsymlink (p) + : p) << endl; stage = "get permissions"; - cout << endl - << "size: " << es.second.size << endl - << "permissions: " << oct - << static_cast<size_t> (path_permissions (p)) << endl; + cout << "permissions: " + << oct << static_cast<size_t> (path_permissions (p)) << endl; stage = tdir ? "get directory times" : "get file times"; |