From 8a82f67e2cb3366ab6988bcb56eb06c1d56fdc5d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sat, 28 Apr 2018 18:04:08 +0200 Subject: Use rmsymlink() to portably remove symlinks --- build2/algorithm.cxx | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'build2/algorithm.cxx') diff --git a/build2/algorithm.cxx b/build2/algorithm.cxx index 6f756e4..924935c 100644 --- a/build2/algorithm.cxx +++ b/build2/algorithm.cxx @@ -973,7 +973,12 @@ namespace build2 try { - try_rmfile (l); // Normally will be there. + // Normally will be there. + // + if (l.to_directory ()) + try_rmsymlink (l, true /* directory */); + else + try_rmfile (l); // Skip (ad hoc) targets that don't exist. // @@ -1014,10 +1019,10 @@ namespace build2 void clean_backlink (const path& l, uint16_t verbosity) { - // Assuming this works for directories (which can only be symlinked). See - // also try_rmfile() calls in ~backlink() and update_backlink(). - // - rmfile (l, verbosity); + if (l.to_directory ()) + rmsymlink (l, true /* directory */, verbosity); + else + rmfile (l, verbosity); // Should work for symbolic and hard file links. } // If target/link path are syntactically to a directory, then the backlink @@ -1039,9 +1044,11 @@ namespace build2 { if (active) { - // Assuming this works for both file and directory (sym)links. - // - try_rmfile (path, true /* ignore_errors */); + if (path.to_directory ()) + try_rmsymlink (path, true /* directory */, true /* ignore_errors */); + else + try_rmfile (path, true /* ignore_errors */); + active = false; } } -- cgit v1.1