aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbutl/filesystem.cxx105
-rw-r--r--tests/link/driver.cxx43
-rw-r--r--tests/mventry/testscript5
-rw-r--r--tests/path-entry/driver.cxx22
-rw-r--r--tests/path-entry/testscript9
5 files changed, 22 insertions, 162 deletions
diff --git a/libbutl/filesystem.cxx b/libbutl/filesystem.cxx
index 70c8530..1fec18b 100644
--- a/libbutl/filesystem.cxx
+++ b/libbutl/filesystem.cxx
@@ -33,8 +33,6 @@
# endif
#endif
-#include <iostream> // @@ TMP
-
#include <cassert>
#ifndef __cpp_lib_modules_ts
@@ -193,67 +191,6 @@ namespace butl
return junction_target_exists (p.string ().c_str (), ignore_error);
}
- static inline bool
- symlink (DWORD a) noexcept
- {
- return a != INVALID_FILE_ATTRIBUTES &&
- (a & FILE_ATTRIBUTE_REPARSE_POINT) != 0;
- }
-
- static inline bool
- symlink (const path& p) noexcept
- {
- return symlink (GetFileAttributesA (p.string ().c_str ()));
- }
-
- // @@ TODO
- //
- static pair<bool, entry_stat>
- symlink_target_entry (const char* p, bool ignore_error)
- {
- HANDLE h (CreateFile (p,
- FILE_READ_ATTRIBUTES,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- NULL,
- OPEN_EXISTING,
- FILE_FLAG_BACKUP_SEMANTICS,
- NULL));
-
- if (h == INVALID_HANDLE_VALUE)
- {
- DWORD ec;
-
- if (ignore_error || error_file_not_found (ec = GetLastError ()))
- return make_pair (false, entry_stat {entry_type::unknown, 0});
-
- throw_system_error (ec);
- }
-
- DWORD ec (0);
- BY_HANDLE_FILE_INFORMATION fi;
-
- if (!GetFileInformationByHandle (h, &fi))
- ec = GetLastError ();
-
- CloseHandle (h);
-
- if (ec != 0)
- {
- if (ignore_error)
- return make_pair (false, entry_stat {entry_type::unknown, 0});
-
- throw_system_error (ec);
- }
-
- if ((fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0)
- return make_pair (true,
- entry_stat {entry_type::regular,
- (uint64_t (fi.nFileSizeHigh) << 32) |
- fi.nFileSizeLow});
- else
- return make_pair (true, entry_stat {entry_type::directory, 0});
- }
-
pair<bool, entry_stat>
path_entry (const char* p, bool fl, bool ie)
{
@@ -271,15 +208,15 @@ namespace butl
p = d.c_str ();
}
- // Note that VC's implementations of _stat64() follows reparse points and
- // fails for dangling ones. MinGW GCC's implementation returns the
- // information about the reparse itself. That's why we handle junctions
- // and symlinks specially, not relying on _stat64().
+ // Note that VC's implementations of _stat64() follows junctions and fails
+ // for dangling ones. MinGW GCC's implementation returns the information
+ // about the junction itself. That's why we handle junctions specially,
+ // not relying on _stat64().
//
DWORD a (GetFileAttributesA (p));
if (a == INVALID_FILE_ATTRIBUTES) // Presumably not exists.
return make_pair (false, entry_stat {entry_type::unknown, 0});
-/*
+
if (junction (a))
{
if (!fl)
@@ -289,14 +226,6 @@ namespace butl
? make_pair (true, entry_stat {entry_type::directory, 0})
: make_pair (false, entry_stat {entry_type::unknown, 0});
}
-*/
- if (symlink (a))
- {
- if (!fl)
- return make_pair (true, entry_stat {entry_type::symlink, 0});
-
- return symlink_target_entry (p, ie);
- }
entry_type et (entry_type::unknown);
struct __stat64 s; // For 64-bit size.
@@ -565,31 +494,7 @@ namespace butl
mksymlink (const path& target, const path& link, bool dir)
{
if (!dir)
- {
- // Try to create a symbolic link and assume symlinks are not supported
- // on error, unless target or link paths is invalid.
- //
- //
- if (CreateSymbolicLinkA (link.string ().c_str (),
- target.string ().c_str (),
- SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE))
- return;
-
- if (GetLastError () == ERROR_INVALID_PARAMETER)
- {
- auto invalid = [] (const path& p)
- {
- return GetFileAttributesA (p.string ().c_str ()) ==
- INVALID_FILE_ATTRIBUTES &&
- GetLastError () == ERROR_INVALID_PARAMETER;
- };
-
- if (invalid (target) || invalid (link))
- throw_generic_error (EINVAL);
- }
-
throw_generic_error (ENOSYS, "file symlinks not supported");
- }
dir_path ld (path_cast<dir_path> (link));
diff --git a/tests/link/driver.cxx b/tests/link/driver.cxx
index 79f381d..96ac880 100644
--- a/tests/link/driver.cxx
+++ b/tests/link/driver.cxx
@@ -35,33 +35,18 @@ using namespace butl;
static const char text[] = "ABCDEF";
-enum class mklink
-{
- sym,
- hard,
- any
-};
-
static bool
-link_file (const path& target, const path& link, mklink ml, bool check_content)
+link_file (const path& target, const path& link, bool hard, bool check_content)
{
try
{
- switch (ml)
- {
- case mklink::sym: mksymlink (target, link); break;
- case mklink::hard: mkhardlink (target, link); break;
- case mklink::any: mkanylink (target, link, true /* copy */); break;
- }
- }
- catch (const system_error& e)
- {
- cerr << e << endl;
- return false;
+ if (hard)
+ mkhardlink (target, link);
+ else
+ mksymlink (target, link);
}
- catch (const pair<entry_type, system_error>& e)
+ catch (const system_error&)
{
- cerr << e.second << endl;
return false;
}
@@ -154,26 +139,22 @@ main ()
// Create the file hard link.
//
- assert (link_file (fp, td / path ("hlink"), mklink::hard, true));
+ assert (link_file (fp, td / path ("hlink"), true, true));
#ifndef _WIN32
// Create the file symlink using an absolute path.
//
- assert (link_file (fp, td / path ("slink"), mklink::sym, true));
+ assert (link_file (fp, td / path ("slink"), false, true));
// Create the file symlink using a relative path.
//
- assert (link_file (fn, td / path ("rslink"), mklink::sym, true));
+ assert (link_file (fn, td / path ("rslink"), false, true));
// Create the file symlink using an unexistent file path.
//
- assert (link_file (fp + "-a", td / path ("sa"), mklink::sym, false));
+ assert (link_file (fp + "-a", td / path ("sa"), false, false));
#endif
- // Create the file any link.
- //
- assert (link_file (fp, td / path ("alink"), mklink::any, true));
-
// Prepare the target directory.
//
dir_path dn ("dir");
@@ -188,8 +169,8 @@ main ()
}
#ifndef _WIN32
- assert (link_file (fp, dp / path ("hlink"), mklink::hard, true));
- assert (link_file (fp, dp / path ("slink"), mklink::sym, true));
+ assert (link_file (fp, dp / path ("hlink"), true, true));
+ assert (link_file (fp, dp / path ("slink"), false, true));
#endif
// Create the directory symlink using an absolute path.
diff --git a/tests/mventry/testscript b/tests/mventry/testscript
index 8c41eb4..ecd617a 100644
--- a/tests/mventry/testscript
+++ b/tests/mventry/testscript
@@ -130,7 +130,7 @@ if ($test.target == $build.host)
: target stays intact.
:
echo 'foo' >=a;
- $lns &b;
+ $lns;
echo 'bar' >=c &!c;
$* c b;
cat a >'foo';
@@ -149,7 +149,6 @@ if ($test.target == $build.host)
: dir
:
{
-#\
: from
:
: Make sure that if source is a symlink it refers the same target after
@@ -161,7 +160,7 @@ if ($test.target == $build.host)
touch a/b;
test -f c/b;
test -d b == 1
-#\
+
: to
:
: Make sure that if destination is a symlink it is get overwritten and
diff --git a/tests/path-entry/driver.cxx b/tests/path-entry/driver.cxx
index e4dddf3..d48bf49 100644
--- a/tests/path-entry/driver.cxx
+++ b/tests/path-entry/driver.cxx
@@ -25,36 +25,20 @@ import butl.filesystem;
using namespace std;
using namespace butl;
-// Usage: argv[0] [-l] <path>
+// Usage: argv[0] <path>
//
// If path entry exists then print it's type and size (meaningful for the
// regular file only) to STDOUT, and exit with the zero code. Otherwise exit
// with the one code. Don't follow symlink. On failure print the error
// description to STDERR and exit with the two code.
//
-// -l
-// Follow symlinks.
-//
int
main (int argc, const char* argv[])
try
{
- bool follow_symlinks (false);
-
- int i (1);
- for (; i != argc; ++i)
- {
- string v (argv[i]);
-
- if (v == "-l")
- follow_symlinks = true;
- else
- break;
- }
-
- assert (i == argc - 1);
+ assert (argc == 2);
- auto es (path_entry (argv[i], follow_symlinks));
+ auto es (path_entry (argv[1]));
if (!es.first)
return 1;
diff --git a/tests/path-entry/testscript b/tests/path-entry/testscript
index 35b6f6f..456f96f 100644
--- a/tests/path-entry/testscript
+++ b/tests/path-entry/testscript
@@ -25,15 +25,6 @@
directory
/.
EOO
-
- : followed-symlink
- :
- cat <:'abc' >=f;
- ln -s f l;
- $* -l l >>EOO
- regular
- 3
- EOO
}
: non-existent