Skip to content

Commit

Permalink
refs #146, added EINTR handling to directory iteration and file copying
Browse files Browse the repository at this point in the history
  • Loading branch information
gulrak committed Mar 3, 2023
1 parent 4041174 commit f3033c2
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions include/ghc/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3965,14 +3965,24 @@ GHC_INLINE bool copy_file(const path& from, const path& to, copy_options options
return false;
}
ssize_t br, bw;
while ((br = ::read(in, buffer.data(), buffer.size())) > 0) {
while (true) {
do { br = ::read(in, buffer.data(), buffer.size()); } while(errno == EINTR);
if(!br) {
break;
}
if(br < 0) {
ec = detail::make_system_error();
::close(in);
::close(out);
return false;
}
ssize_t offset = 0;
do {
if ((bw = ::write(out, buffer.data() + offset, static_cast<size_t>(br))) > 0) {
br -= bw;
offset += bw;
}
else if (bw < 0) {
else if (bw < 0 && errno != EINTR) {
ec = detail::make_system_error();
::close(in);
::close(out);
Expand Down Expand Up @@ -5673,7 +5683,7 @@ class directory_iterator::impl
, _entry(nullptr)
{
if (!path.empty()) {
_dir = ::opendir(path.native().c_str());
do { _dir = ::opendir(path.native().c_str()); } while(errno == EINTR);
if (!_dir) {
auto error = errno;
_base = filesystem::path();
Expand All @@ -5700,7 +5710,7 @@ class directory_iterator::impl
do {
skip = false;
errno = 0;
_entry = ::readdir(_dir);
do { _entry = ::readdir(_dir); } while(errno == EINTR);
if (_entry) {
_dir_entry._path = _base;
_dir_entry._path.append_name(_entry->d_name);
Expand All @@ -5714,7 +5724,7 @@ class directory_iterator::impl
::closedir(_dir);
_dir = nullptr;
_dir_entry._path.clear();
if (errno) {
if (errno && errno != EINTR) {
ec = detail::make_system_error();
}
break;
Expand Down

0 comments on commit f3033c2

Please sign in to comment.