From 80543b681b82cb48e8f8379555fc739bf5b5d3a4 Mon Sep 17 00:00:00 2001 From: Steffen Schuemann Date: Sun, 30 Aug 2020 09:47:27 +0200 Subject: [PATCH] refs #66, removed shared_ptr guards in copy_file --- include/ghc/filesystem.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index 620f322..4cfa90c 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -3524,16 +3524,15 @@ GHC_INLINE bool copy_file(const path& from, const path& to, copy_options options ec = detail::make_system_error(); return false; } - std::shared_ptr guard_in(nullptr, [in](void*) { ::close(in); }); int mode = O_CREAT | O_WRONLY | O_TRUNC; if (!overwrite) { mode |= O_EXCL; } if ((out = ::open(to.c_str(), mode, static_cast(sf.permissions() & perms::all))) < 0) { ec = detail::make_system_error(); + ::close(in); return false; } - std::shared_ptr guard_out(nullptr, [out](void*) { ::close(out); }); ssize_t br, bw; while ((br = ::read(in, buffer.data(), buffer.size())) > 0) { ssize_t offset = 0; @@ -3544,10 +3543,14 @@ GHC_INLINE bool copy_file(const path& from, const path& to, copy_options options } else if (bw < 0) { ec = detail::make_system_error(); + ::close(in); + ::close(out); return false; } } while (br); } + ::close(in); + ::close(out); return true; #endif }